Windows function MessageBox

Source: Internet
Author: User

From windows 1.0 to Windows 3.1, the MessageBox function is located in the dynamic link library user. EXE. In Windows. h of Windows 3.1 software development kit, the MessageBox function is defined as follows:

int WINAPI MessageBox (HWND, LPCSTR, LPCSTR, UINT) ;        

Note that the second and third parameters of a function are pointers to constant strings. When compiling a Win16 program, Windows does not process MessageBox calls. The table in the program. EXE file allows Windows to dynamically link the call of the program with the MessageBox function in the user.

32-bit windows (that is, all versions of Windows NT, and Windows 95 and Windows 98) except for a 16-bit compatible user. EXE also contains a dynamic link library called user32.dll, which contains the entry point of the 32-bit user interface function, including the 32-bit MessageBox.

This is the key to Windows Unicode support: in user32.dll, there is no 32-bit entry point for the MessageBox function. In fact, there are two entry points: messageboxa (ASCII version) and messageboxw (wide character version ). Each Win32 function that uses a string as a parameter has two entry points in the operating system! Fortunately, you generally don't have to worry about this issue. You only need to use MessageBox in the program. Like the tchar header file, every Windows header file has the skills we need.

The following is the method defined by messageboxa in winuser. h. This is similar to the earlier definition of MessageBox:

WINUSERAPI int WINAPI MessageBoxA (HWND hWnd, LPCSTR lpText,                            LPCSTR lpCaption, UINT uType) ;        

Below is messageboxw:

WINUSERAPI int WINAPI MessageBoxW (HWND hWnd, LPCWSTR lpText,                                   LPCWSTR lpCaption, UINT uType) ;        

Note that the second and third parameters of the messageboxw function are pointers to wide characters.

If you need to use both ASCII and wide character function calls, you can use messageboxa and messageboxw functions explicitly in Windows programs. However, most programmers will continue to use MessageBox. Based on whether Unicode is defined, MessageBox will be the same as messageboxa or messageboxw. When this technique is completed in winuser. H, the program is quite trivial:

#ifdef UNICODE        #define MessageBox  MessageBoxW        #else        #define MessageBox  MessageBoxA        #endif        

In this way, if the Unicode identifier is defined, all the MessageBox function calls in the program are actually the messageboxw function; otherwise, it is the messageboxa function.

When the program is executed, Windows connects different function calls in the program to the entry points of different Windows dynamic link libraries. Although there are only a few exceptions, Windows functions of Unicode edition cannot be executed in Windows 98. Although these functions have entry points, the error code is usually returned. The application pays attention to the returned errors and takes some reasonable actions.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.