开发者

How to receive feedback from a Windows MessageBox?

I know its possible to do something like this with Windows:

MessageBox(hWnd, "Yes, No, or Cancel?", "YNCB_YESNOCANCEL);

But how do I react to what the user pressed (like closing the win开发者_如何学编程dow if they clicked "yes")?


MessageBox will return a integer referring to the button pressed. From the previous link:

Return Value
    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.

So something like:

int result = MessageBox(hWnd, "Save work?", MB_YESNOCANCEL);
if (result == IDOK)
{
    // ...
}
else if (result == IDNO)
{
    // ...
}
else // cancel
{
    // ...
}


int result = MessageBox(hWnd,_T(""),_T("Save work?"), MB_YESNOCANCEL);
if (result == 6){
    MessageBox(NULL, _T("YES"),_T("Press"),MB_OK);
}
else if (result == 7){
    MessageBox(NULL, _T("NO"),_T("Press"),MB_OK);
}
else{
    MessageBox(NULL, _T("CANCEL"),_T("Press"),MB_OK);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜