TomP89
TomP89

Reputation: 1460

C++ win32 API Message box button clicked

I have just started learning how to program Windows GUI's using the low level Win32 API and C++ so please bear with me.

I have a message box which is displayed at one point and as you can see below it is set to an OK/Cancel box

    MessageBox(hWnd, L"Hello", L"Caption", MB_OKCANCEL);

My question is, how do you check which of the two (or possibly more) buttons were pressed and act accordingly?

Thank you

Tom

Upvotes: 2

Views: 18012

Answers (4)

user1232296
user1232296

Reputation: 217

you can use

int msgboxID=MessageBox(NULL, "DOCTOR WHO","BBC", MB_OKCANCEL | MB_DEFBUTTON2);
switch(msgboxID){
    case IDCANCEL:// you check msdn for more cases
     {
     PostQuitMessage(0);
     return 0;
     }


               }

http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx

Upvotes: 6

Muhammad Anjum Kaiser
Muhammad Anjum Kaiser

Reputation: 4077

MessageBox() call returns an integer value providing the value of button clicked.

http://msdn.microsoft.com/en-us/library/ms645505(v=vs.85).aspx

Upvotes: 1

Diego Sevilla
Diego Sevilla

Reputation: 29021

Look at the MessageBox description. The return type is the value of the button clicked. For example, IDOK when the user pressed the "OK" button.

Upvotes: 6

Manuel
Manuel

Reputation: 6442

Uhm, a Google search for MessageBox yields a link to Microsoft's documentation. Have a look at the "Return Value" section. Does this help?

Upvotes: 0

Related Questions