windows_programming_notes.nbk: Home | Index | Next Page: MessageBoxEx | Previous Page: MessageBeep


 MessageBox

The MessageBox function creates, displays, and operates a message box. The message box contains an application-defined message and title, along with any combination of predefined icons and push buttons.

Syntax

    int MessageBox(
          HWND hWnd,
          LPCTSTR lpText,
          LPCTSTR lpCaption,
          UINT uType
        );

Parameters

Return Value

If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

If the function succeeds, the return value is one of the following menu-item values.

Remarks

Adding two right-to-left marks (RLMs), represented by Unicode formatting character U+200F, in the beginning of a MessageBox display string is interpreted by the Win32 MessageBox rendering engine so as to cause the reading order of the MessageBox to be rendered as right-to-left (RTL).

When you use a system-modal message box to indicate that the system is low on memory, the strings pointed to by the lpText and lpCaption parameters should not be taken from a resource file because an attempt to load the resource may fail.

If you create a message box while a dialog box is present, use a handle to the dialog box as the hWnd parameter. The hWnd parameter should not identify a child window, such as a control in a dialog box.

Windows 95/98/Me: The system can support a maximum of 16,364 window handles.

Windows NT/2000/XP: The value of MB_SERVICE_NOTIFICATION changed starting with Windows NT 4.0. Windows NT 4.0 provides backward compatibility for preexisting services by mapping the old value to the new value in the implementation of MessageBox. This mapping is done only for executables that have a version number earlier than 4.0, as set by the linker.

To build a service that uses MB_SERVICE_NOTIFICATION and can run on both Microsoft Windows NT 3.x and Windows NT 4.0, you can do one of the following.

At link-time, specify a version number less than 4.0. At link-time, specify version 4.0. At run-time, use the GetVersionEx function to check the system version. Then, when running on Windows NT 3.x, use MB_SERVICE_NOTIFICATION_NT3X; and on Windows NT 4.0, use MB_SERVICE_NOTIFICATION. Windows 95/98/Me: Even though MessageBoxW exists, it is supported by the Microsoft Layer for Unicode on Windows 95/98/Me Systems to give more consistent behavior across all Windows operating systems.

Function Information


windows_programming_notes.nbk: Home | Index | Next Page: MessageBoxEx | Previous Page: MessageBeep


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time