Unicode This article mainly introduces the generation, and development of ASII and Unicode, and some relevant standards, mainly ASII is to use one byte 8, Unicode is used in two bytes 16, ASII has 128 Character, and Unicode can represent 2 of the 16th of the non-afternoon, there is a few more than the previous: 1, ASII is only the standard of the United States, so it is only enough for the American character set, so Among them, there is no renminbi symbol (for entertainment only) 2. Unicode is inverted when storing, such as 0x 003f storage is 0x3f 0x003. If you fail in the program language, if you are unclear A or u coding will The norm is wrong, such as the number of characters of Hello, H coding is 0x0041, stored as 0x41 0x00, if it is asii, hello is a character, because 0x00 is ending characters, so it must distinguish these two Format, in Asni C, use a wide character concept, we can use the wide character set as a Unicode character set (in fact, it should be the latter), for the character processing function There are two versions, wide and non-wide, which seems to have greatly increased the difficulty of programming, in fact, these no longer need to consider, because they have been overwritten in VSC take a mechanism A series of macros is defined in some header files, through the reference to the header file, so that this dispute will become invisible, such as tchar.h, by reference to TCHAR.H, compiling different versions in different compilation environments . A few examples: There is a definition of the following effect in tchar.h: if the _unicode identifier #define _tcslen wcslen typefedef wchar_t tchar; otherwise: #define _tcslen strlen typef char tchar;
In windows.h has a similar process: #ifdef UNICODE typedef WCHAR TCHAR, * PTCHAR; typedef LPWSTR LPTCH, PTCH, PTSTR, LPTSTR; typedef LPCWSTR LPCTSTR; #elsetypedef char TCHAR, * PTCHAR; typedef LPSTR LPTCH, PTCH, PTSTR, LPTSTR ; typedef LPCSTR LPCTSTR; generally added to the end of a and W to be distinguished #endif API call: WINUSERAPI int WINAPI MessageBoxA (HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType); WINUSERAPI int WINAPI MessageBoxW (HWND hWnd, LPCWSTR lpText, LPCWSTR LPCAPTION, UINT UTYPE); but this also adds programmers' workload, they must be determined using a or WinUser.h to do TCHAR.H to help programmers solve trouble , As follows: #ifdef unicode #define messagebox messageBoxw #else #define messageBox MessageBoxa #ENDIF
Finally, give a program: * ---------------------------------------- -------------------------------- Scrnsize.c - Displays Screen Size In A Message Box (c) Charles Petzold 1998 ------------------------------------------------ ---------------------------- * / #include
va_start (parglist, szformat);
// the last argument to wvsprintf Points to the arguments
_VSNTPrintf (Szbuffer, Sizeof (Szbuffer) / Sizeof (Tchar), SZFORMAT, PARGLIST);
// The va_end macro just zeroes out pArgList for no good reason va_end (pArgList); return MessageBox (NULL, szBuffer, szCaption, 0);} int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {int cxScreen Cyscreen; cxscreen = getSystemMeen; cyscreen = getSystemMetrics (SM_CYSCREEN);
MessageBoxPrintf (Text ("Scrnsize"), Text ("The Screen IS% I Pixels Wide By% I Pixels High."), CXScreen, Cyscreen; Return 0;} where getSystemMetrics is a different object that can be used to get Windows Size information The function of Winuser.h has been included in Windows.h, and you can see #include