Such as "
call , "May break between them, such as
"
went up into the mountain shoot tigers ,
to sweet potatoes, "
Use gdi + drawing, the effect is not very good, you have what advice
CodePudding user response:
CRichEditCtrl SetSelectionCharFormat
CodePudding user response:
Thank you for your reply, this is a way,
If by HDC handle, can have a direct way of drawing
CodePudding user response:
Every word with color, the output word by word,
CodePudding user response:
Output can be word by word, calculate the information such as the position of each character
CodePudding user response:
Don't have to calculate the rate of the position of each character ", "
But to change the Pen
CodePudding user response:
If the simple display, use normal window, through the DC output, output before use SetTextColor sets the text color (must use DC_PEN)
If you want to display complex and can edit, use CRichCtrl, content contains display format the text of the control parameters
CodePudding user response:
reference 5 floor schlafenhamster reply: don't have to "have to calculate the position of each character" But to change the Pen Change the pen is no problem, how to do, such as the " went up into the mountain shoot tigers , to dig the sweet potato" CodePudding user response:
When two words such as "down", an inter-bank, draw the RECT etc. How to deal with CodePudding user response:
If it is Chinese characters, width and height is the same, as long as once CodePudding user response:
If the string is " went up into the mountain shoot tigers , and dig sweet potato " Window width is 7 characters 1. According to window width delimited string The string into a 1: string " went up into the mountain shoot tigers , "2: the string " to dig the sweet potato " 2. According to the color segmentation again string String into: 1-1: string " up "1-2: string "shoot tigers," 1-3: string " "2-1: string " to "String 2-2: "dig a sweet potato" 3. In order painted string CodePudding user response:
Well, understand upstairs. Thank you CodePudding user response:
Try single-line: Void StepText (HDC HDC, the RECT * rc, char * STR)//text literally { Int len=strlen (STR);//calculate the length of the string Int posx.//the current character position Int posy=rc - & gt; Top; The SIZE the SIZE;//store each character of wide high SetTextAlign (HDC, TA_UPDATECP | TA_LEFT | TA_TOP);//set automatically update text position While (len> 0) { Posx=rc - & gt; left; MoveToEx (HDC, rc - & gt; Left, posy, NULL);//move to the beginning of a line While (len>=0) { Int t; If ((STR [0]) & lt; T=0) 2;//character of Chinese and western to distinguish The else t=1; GetTextExtentPoint32 (HDC, STR, t, & amp; The size);//get characters wide high If (posx + size. Cx> Rc - & gt; Right) break;//if beyond the border Cx; posx +=the size.//update the current position TextOut (HDC, 0, 0, STR, t);//output characters STR +=t;//update the characters Len -=t;//update the character length If (len<=0) break;//if the finished output character } Posy +=size. Cy;//migration processing If (posy + size. Cy + size. (cy) & gt;=rc - & gt; Bottom)//the next line cannot write, for scrolling { The RECT the RECT=* rc; The rect. Top +=size. Cy;//scrolling position ScrollDC (HDC, 0, - size. Cy, & amp; The rect, NULL, NULL, NULL); Posy -=size. Cy;//restore migration processing } } } CodePudding user response:
Note that SetTextAlign (HDC, TA_UPDATECP | TA_LEFT | TA_TOP);//set automatically update text position And the TextOut (HDC 0, 0, , STR, t);//output characters CodePudding user response:
Multi-line with color //StepText (HDC, & amp; The rect, "haha how are you! \ r \ nhaha you! \ r \ n \ r \ nhaha he good! \ r \ nhaha she all right!" ); Void StepText (HDC HDC, the RECT * rc, char * STR)//text literally { Int len=strlen (STR);//calculate the length of the string Int posx.//the current character position Int posy=rc - & gt; Top; The SIZE the SIZE;//store each character of wide high SetTextAlign (HDC, TA_UPDATECP | TA_LEFT | TA_TOP);//set automatically update text position While (len> 0) { Posx=rc - & gt; left; MoveToEx (HDC, rc - & gt; Left, posy, NULL);//move to the beginning of a line While (len>=0) { Int t; If ((STR [0]) & lt; 0) {t=2; SetTextColor (HDC, 255); }//characters of Chinese and western to distinguish The else {t=1; SetTextColor (HDC, 0); } GetTextExtentPoint32 (HDC, STR, t, & amp; The size);//get characters wide high If (posx + size. Cx> Rc - & gt; Right) break;//if beyond the border Cx; posx +=the size.//update the current position If (* STR==0 x0d) {STR +=1; continue; } If (* STR==0 x0a) {STR +=1; Len=strlen (STR); break; } TextOut (HDC, 0, 0, STR, t);//output characters STR +=t;//update the characters Len -=t;//update the character length If (len<=0) break;//if the finished output character }//end while (len>=0) //newline: Posy +=size. Cy;//migration processing If (posy + size. Cy + size. (cy) & gt;=rc - & gt; Bottom)//the next line cannot write, for scrolling { The RECT the RECT=* rc; The rect. Top +=size. Cy;//scrolling position ScrollDC (HDC, 0, - size. Cy, & amp; The rect, NULL, NULL, NULL); Posy -=size. Cy;//restore migration processing } } } CodePudding user response:
DrawText nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull