简体   繁体   中英

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

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

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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM