Sign in to follow this  

messagebox button

This topic is 4354 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, i made a messagebox and i made a case that if the user press cancel the program quits, the problem is that i dont know how to check the if the button is pressed. this is what ive done:
case MB_OKCANCEL:
             if (MB_OKCANCEL==MB_CANCEL)
             {
             return 0;
             }
             break;

i though it just worked with MB_CANCEL, but it doesnt:P. So what do i have to do to check if the user has pressed cancel?

Share this post


Link to post
Share on other sites
It really does help to read the docs instead of just guessing...

Quote:

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.


IDABORT Abort button was selected.
IDCANCEL Cancel button was selected.
IDCONTINUE Continue button was selected.
IDIGNORE Ignore button was selected.
IDNO No button was selected.
IDOK OK button was selected.
IDRETRY Retry button was selected.
IDTRYAGAIN Try Again button was selected.
IDYES Yes button was selected.

Share this post


Link to post
Share on other sites
That really doesn't make any sense to me. This is what I think you're trying to do:
int ret = MessageBox(...);
if (ret == IDCANCEL)
return 0;



Could be wrong, though...

Share this post


Link to post
Share on other sites
Quote:

i cant work with msdn


Why not?

MB_OKCANCEL is a constant that is passed to MessageBox() to determine what buttons are displayed. The key word there is "constant," its value will never change and comparing it to IDCANCEL (the ID of the cancel button in the message box) is both semantically invalid and probably will never evaluate to true.

I imagine you want something like:


int ret = MessageBox(/* parameters */);

if(ret == IDOK)
{
// User hit OK.
}
else if (ret == IDCANCEL)
{
// User hit CANCEL.
}


As Anon Mike said, read the documentation.

Share this post


Link to post
Share on other sites
Hey,
I had problems with the same thing, the message box wouldn't respond correctly
to the buttons, what I did that works is:

if (MessageBox(...) == MB_OK) //
{
//take action for OK,
}

I haven't done a whole lot with message boxes, but I hope this helps.

Share this post


Link to post
Share on other sites

This topic is 4354 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this