Points to a null-terminated string used for the dialog box title. If
this parameter is NULL, the default title Error is used.
Specifies a set of bit flags that determine the contents and
behavior of the dialog box. This parameter can be a combination
of flags from the following groups of flags.
After this text a whole list of constants and flags (which are defined in windows.inc) follows. I haven't
displayed it here because it is quite long. Looking at the reference, you can see that the MessageBox
function takes 4 parameters: A parent window, a pointer to a message string, a pointer to a title
string and the type of messagebox.
hWnd can be NULL, because our program does not have a window.
lpText has to be a pointer to our text. This just means that the parameter is the offset of the memory
location where our text is.
lpCaption is the offset of the title string.
uType is a combination of the values explained in the reference like MB_OK, MB_OKCANCEL,
Let's first define two strings for the messagebox:
add this to first.asm:
MsgText db "Hello world!",0
MsgTitle db "This is a messagebox",0
indicates the start of the data section. With
bytes are directly inserted, and as a string is
just a collection of bytes, the data section will contain the strings above, 0-terminated by the
. MsgText holds the offset of the first string, MsgTitle the offset of the second string.
Now we can use the function:
invoke MessageBox, NULL, offset MsgText, offset MsgTitle, NULL
But because invoke is used, you can use the (more safe) ADDR in stead of offset:
invoke MessageBox, NULL, ADDR MsgText, ADDR MsgTitle, NULL
We haven't looked at the last parameter yet, but this will work fine because MB_OK (style for a
messagebox with an OK button) equals 0 (NULL). But you can use any other style. The uType (4th
parameter) definiton is:
Specifies a set of bit flags that determine the contents and behavior of the dialog box. This parameter
can be a combination of flags from the following groups of flags.
Now take for example that we want a simple messagebox with an OK button with the 'information'-
icon. MB_OK is the style for the OK button, MB_ICONINFORMATION is the style for an information
icon. Styles are combined with the 'or' operator. This is not the or-opcode. Masm will perform the or
operation before assembling. In stead of or, you can use the + sign (addition), but sometimes this
gives problems with overlapping styles (one style containg some other style). But in this case you
could also have used a +.
invoke MessageBox, NULL, ADDR MsgText, ADDR MsgTitle, MB_OK +
Converted by Atop CHM to PDF Converter free version!
37 / 53