1

我知道它可以用 Windows 做这样的事情:

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

但是我如何对用户按下的内容做出反应(比如如果他们点击“是”则关闭窗口)?

4

2 回答 2

10

MessageBox将返回一个表示按下按钮的整数。从上一个链接:

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.

所以像:

int result = MessageBox(hWnd, "Save work?", MB_YESNOCANCEL);
if (result == IDOK)
{
    // ...
}
else if (result == IDNO)
{
    // ...
}
else // cancel
{
    // ...
}
于 2009-10-19T19:45:59.223 回答
1
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);
}
于 2014-05-06T11:47:16.843 回答