Jump to content

WinMessageBox2

From EDM2
Revision as of 14:28, 9 April 2025 by Martini (talk | contribs) (Created page with "This function creates a message-box window that can be used to display error messages and ask questions. ==Syntax==  WinMessageBox2(hwndParent, hwndOwner, pszText, pszTitle, ulWindow, pmb2info) ==Parameters== ;hwndParent (HWND) - Input : Parent-window handle of the message-box window to be created. :;HWND-DESKTOP ::The message box is to be a main window. :;Other ::Parent-window handle. ;hwndOwner (HWND) - Input : Requested owner-window handle of the message-bo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function creates a message-box window that can be used to display error messages and ask questions.

Syntax

 WinMessageBox2(hwndParent, hwndOwner, pszText, pszTitle, ulWindow, pmb2info)

Parameters

hwndParent (HWND) - Input
Parent-window handle of the message-box window to be created.
HWND-DESKTOP
The message box is to be a main window.
Other
Parent-window handle.
hwndOwner (HWND) - Input
Requested owner-window handle of the message-box window to be created.
The actual owner window is calculated using the algorithm specified in the description of the WinLoadDlg function.
pszText (PSZ) - Input
Message-box window message.
The text of the message to be displayed within the message-box window. If multiple lines are required, carriage-return characters must be inserted into the text at appropriate points.
pszTitle (PSZ) - Input
Message-box window title.
The text for the title should not be longer than 40 characters. If text longer than this is supplied, text centering is still performed, even though the beginning and end of the string are not visible.
A value of NULL indicates that the text "Error" is to be displayed as the title of the message-box window.
ulWindow (ULONG) - Input
Message-box window identity.
This value is passed to the HK_HELP hook if the WM_HELP message is received by the message-box window.
pmb2info (PMB2INFO) - Input
Input structure for message-box window.

Returns

ulButtonId (ULONG) - returns
Id of the button that was clicked, or MBID_ERROR.

Remarks

The function is a more powerful version of WinMessageBox. It supports custom icons and custom text within buttons, and can be transformed into a non-modal message box. It can also be displayed with a title bar and a system menu containing Move, Size, Close and Window items.

Errors

Possible returns from WinGetLastError:

  • PMERR_INVALID_FLAG (0x1019) An invalid bit was set for a parameter. Use constants defined by PM for options, and do not set any reserved bits.
  • PMERR_INVALID_HWND (0x1001) An invalid window handle was specified.

Example Code

#define  INCL_WINDIALOGS                 /* Window Dialog Mgr functions*/
#define  INCL_WINPOINTERS                /* Window Pointer functions   */
#define  NUM_BUT 4
#include <os2.h>

ULONG   ulResult;                        /* Indicates which button to  */
                                         /* push on the message box    */
ULONG   i;                               /* A loop index               */
MB2INFO *pmbInfo;                        /* Pointer to the message box */
                                         /* structure                  */

PSZ      pszBoxTitle     = "A title with up to 40 characters in it";

MB2D mb2dBut[NUM_BUT] =
{
  /* Static copy of button definitions */
  { "AAAA",              ID_BUTTON1, BS_PUSHBUTTON},  /* Or use 0 */
  { "BBBBBBBBBBBBBBBBB", ID_BUTTON2, BS_DEFAULT},
  { "CCCCCCCC",          ID_BUTTON3, 0},
  { "D",                 ID_BUTTON4, 0}
};

/* Size of the message box structure needed.         */
/* Need space for MB2INFO plus 3 additional buttons  */
/* (one button is defined in the MB2INFO structure). */
ULONG   ulInfoSize = (sizeof(MB2INFO) + (sizeof(MB2D) * (NUM_BUT-1)));

/* Allocate space for the MB2INFO structure */
pmbInfo = malloc (ulInfoSize);

pmbInfo->cb         = ulInfoSize;        /* Size of block              */
pmbInfo->hIcon      = WinLoadPointer(HWND_DESKTOP, 0, ID_ICON1);
pmbInfo->cButtons   = NUM_BUT;           /* Number of buttons for box  */
pmbInfo->flStyle    = MB_CUSTOMICON |
                      MB_MOVEABLE;
pmbInfo->hwndNotify = NULLHANDLE;

/* Copy information for each button to the MB2INFO structure */
for (i = 0; i < NUM_BUT; i++)
{
  memcpy( pmbInfo->mb2d+i , mb2dBut+i , sizeof(MB2D));
};

ulResult = WinMessageBox2(HWND_DESKTOP,  /* Parent window              */
                          HWND_DESKTOP,  /* Owner window               */
                          "Line 1 of your message\nLine 2 of message",
                          pszBoxTitle,   /* Message box title          */
                          1234L,         /* Identifier for message box */
                          pmbInfo);      /* Button definitions for     */
                                         /* message box                */

free(pmbInfo);

Related Functions