WinMain, wWinMain, and win32 Character Set problems, winmainwwinmain
When I first got started with win32 development, I found that the entry function in the default code of creating a win32 project with vs is not WinMain but _ tWinMain or wWinMain. What are the differences between these two functions?
WinMain corresponds to the multi-byte character set (ANSI) and wWinMain corresponds to the Unicode Character Set. _ TWinMain is defined in the tchar. h file:
# Ifdef _ UNICODE # define _ tWinMain wWinMain # else # define _ tWinMain WinMain # endif
When the character set is ANSI, it is equivalent to WinMain. When the character set is Unicode, it is equivalent to wWinMain.
To change the character set, click Project> Project Properties in.
Many functions of windows APIs are divided into two versions. For example, CreateWindow is defined as follows:
# Ifdef UNICODE # define CreateWindow CreateWindowW # else # define CreateWindow createwindowwa # endif
So when should we use the Unicode Character Set and the multi-byte character set?
In fact, the Unicode Character Set is not required when the program contains Chinese characters. When the windows system language is Chinese, no matter which character set you choose, the Chinese character set can be displayed normally, however, garbled characters may occur when the system language is not Chinese. So if your software needs to adapt to a multi-language windows system, you must use the Unicode Character Set.
In addition, when the character set is Unicode, a string passed to the api function should be converted to Unicode encoding. L conversion is available:
CreateWindow (wndClass, L "this is the title of the window ",......);