The best way to learn something is by example, so, I’ve decided to include an example.
if MessageBox(0, ‘Choose an option from below’, ‘Options’, +mb_YesNo +mb_ICONWARNING) = 6 then
ShowMessage (‘You clicked yes’)
ShowMessage (‘You clicked no’);
You’ll notice that the first line asks if the MessageBox = 6. That 6 means that the user clicked yes.
Here, I will provide all 7 possibilities.
0: Not enough memory to show the message box.
1: The user clicked the OK Button.
2: The user clicked the Cancel Button.
3: The user clicked the Abort Button.
4: The user clicked the Retry Button.
5: The user clicked the Ignore Button.
6: The user clicked the Yes Button.
7: The user clicked the No Button.
Of course, as I showed you above, there’s other buttons you could choose. You could easilly have the following:
MessageBox(0, ‘More Options’, ‘More Options’, +mb_ABORTRETRYIGNORE +mb_ICONWARNING);
That MessageBox will show the abort retry and ignore buttons. You can even combine different buttons to get different messageboxes like this:
MessageBox(0, ‘Save the document before starting a new one?’, ‘Save Warning’, +mb_YesNo +MB_ABORTRETRYIGNORE +mb_ICONWARNING);
The results start to get strange though, you’ll see what I mean if you try that one out for yourself. Go ahead, you won’t hurt anything. One last thing about messageboxes is the icons that you can get. You can get that yellow triangle with the exclamation mark as I pointed out, or you could get the information icon like this:
MessageBox(0, ‘Save the document before starting a new one?’, ‘Save Warning’, +mb_YesNo +mb_ICONINFORMATION);
Getting the icon with the X in it is done in a simmilar fassion. Just replace +mb_ICONINFORMATION with +mb_ICONSTOP. If you want the one with the questionmark in it, then just replace that with +mb_ICONQUESTION. If you don’t want an icon, then just don’t tell it what icon to put and you won’t get an icon. One last quick tip, if you want a plain messagebox that just says OK in it without showing an icon, then you can just put this:
ShowMessage(‘This is the message you want to be shown’);
Notice: To handle message box to stay on top, you should change ‘0’ value to ‘handle’ string.