In vc2005, when setwindowtext is called, an error occurs when char [] is used for the second parameter. We recommend that you use tchar because vc2005 uses Unicode by default.
For Unicode programming, we recommend that you use tchar (16-bit w_char) instead of char. In fact, it is good for Unicode programming. It is a good habit to use tchar. If you want to convert to Unicode, you can use the multibytetowidechar function.
Note the following when writing code: 1: Add _ T or _ text before the string. for example: _ T ("dadad"); 2: replace char with tchar (unsigned char must be removed from unsigned) 3: replace STR function with _ TCS function 4: the printf function family must be changed to wprintf. However, do not use the wprintf function to parse the char type. 5: For string and integer conversions, use _ itot and _ ttoi to convert each other. Do not use atoi or ITOA. In Unicode mode, cstring and wchar_t are common. That is to say, in vs2005, wchar STR = l "string"; cstring str1 = STR; can be compiled, but not in vc6.: String declaration type. Generally, you can use the generic function to enable the program to automatically set according to the configured encoding.
Common MFC Data Types |
Maps to ASCII |
Map to Unicode |
Note |
_ Tchar |
Char |
Wchar_t |
_ Tchar is a ing macro. When Unicode is defined, the data type is mapped to wchar_t. If Unicode is not defined, it is mapped to Char. |
_ T or _ text |
Char constant string |
Wchar_t constant string |
Features are the same as macros. in ASCII mode, they are ignored, that is, they are deleted by the pre-processor. However, if Unicode is defined, they convert constant strings to the equivalent Unicode. |
Lptstr |
Char *, lpstr (win32) |
Wchar_t * |
A portable 32-Bit String pointer. It maps the character type to the type set by the project. |
Lpctstr |
Const char *, lpcstr (win32) |
Const wchar_t * |
Portable 32-bit constant string pointer. It maps character type constants to the type set by the project. |
2. unicode wchar * To char * cstring STR (wchar *); //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /// lpcstr 32-bit Pointer to a constant string Lpstr 32-bit Pointer to a string Lpctstr 32-bit Pointer to a constant string. This string can be transplanted to Unicode And DBCS Lptstr 32-bit Pointer to a string. This string can be transplanted to Unicode And DBCS lpwstr 32-bit Pointer to a unicode string Lpcwstr 32-bit Pointer to a unicode String constant L stands for long, P stands for pointer, C stands for constant, W stands for wide, and STR stands for string.