Home > Software engineering >  Why use TextOut, behind will have a special character
Why use TextOut, behind will have a special character

Time:09-27

Specific problems as follows:
 SelectObject (ADC, (HBRUSH) GetStockObject (GRAY_BRUSH));//select a device brush 
The Ellipse (ADC, 0,0,100,100);//draw a circle
SetBkColor (ADC, RGB (0, 255, 0));//the background color of the button text
SetTextColor (ADC, RGB (255, 0, 0));//text color on button
TextOut (ADC, 25, 50, L "12345", sizeof (" 12345 "));//the text on the button

After running effect is as follows:

There will be some strange characters behind, how does this broken? Have prawn to save me this small shrimp, grateful...

CodePudding user response:

Spend a little bit of time problem solved, modify the code to the
 SelectObject (ADC, (HBRUSH) GetStockObject (GRAY_BRUSH));//DCBAK 
The Ellipse (ADC, 0,0,100,100);
SetBkColor (ADC, RGB (0, 255, 0));//the background color of the button text
SetTextColor (ADC, RGB (255, 0, 0));//text color on button
WCHAR STR [50].
Swprintf_s (STR, L "12345", 20).
TextOut (ADC, 25, 50, STR, wcslen (STR));//the text on the button

Successfully solve the problem, the problem of seems to be the font decoding, sizeof lead to can't normal before end of the decoding process, and then to adjacent seams of storage space inside to decode,

CodePudding user response:

With a function of t, can adapt to Unicode and multibyte compile environment
 _stprintf_s, _tcslen _tcscpy_s, _tcscat_s _tcscmp etc. 

LPCTSTR STR=_T (" 12345 ");
TextOut (hDC, x, y, STR, _tcslen (STR));

CodePudding user response:

L "12345", sizeof (" 12345 ")
L and no L do not match

CodePudding user response:

建议楼主亲自打开tchar.h一眼,

CodePudding user response:

Sizeof (" 12345 ") sizeof _tcsclen instead

CodePudding user response:

_T (" ") to try the problem can be solved

CodePudding user response:

CodePudding user response:

Use sizeof (" 12345 ") must be wrong, the result is 6, for L "12345", only five characters,

CodePudding user response:

Sizeof returns the space of memory, so you end string has a null, or the end of the wchar, or compiler Settings the string at the end of the
"
wcslen

CodePudding user response:

Learning how to learn,,,

CodePudding user response:

Estimate is Unicode version, do you use to TextOut function should be the number of characters, is not a sizeof get the number of bytes
  • Related