Message Box in Delphi

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’)
else
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.

11 Responses to Message Box in Delphi

  1. I just wanted to call out how great your writing skills are😉

  2. sasan mohammadi says:

    hey thank you for your subject i had a problem to use message box but with it i could improve that
    sasan from iran(zahedan)

  3. Cleber says:

    i wanna know how many mb_icons have?and which?

    thx

  4. T4mer says:

    Thanks great topic .

  5. tags says:

    this is great.huhu.thanks Lord.

  6. GenesisLt says:

    how I can made in Delphi MessageBox, or MessageDlg, where message will be ‘.. ‘ and 2 buttons captions are ‘Red’ and ‘blue’ ?

  7. Greer Lodge says:

    Greer Lodge…

    Message Box in Delphi « Frozenade’s Zone…

  8. new music hiphop…

    […]Message Box in Delphi « Frozenade’s Zone[…]…

  9. cheap hotel,sanur beach…

    […]Message Box in Delphi « Frozenade’s Zone[…]…

  10. frozenade says:

    @GenesisLt
    Can you explain more clearly?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: