我知道它可以用 Windows 做这样的事情:
MessageBox(hWnd, "Yes, No, or Cancel?", "YNCB_YESNOCANCEL);
但是我如何对用户按下的内容做出反应(比如如果他们点击“是”则关闭窗口)?
我知道它可以用 Windows 做这样的事情:
MessageBox(hWnd, "Yes, No, or Cancel?", "YNCB_YESNOCANCEL);
但是我如何对用户按下的内容做出反应(比如如果他们点击“是”则关闭窗口)?
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
{
// ...
}
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);
}