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