Dialog box prohibits subsequent MessageBox
-
I'm a Windows programming beginner, been programming DOS for some time, starting to make the switch and I'm having a niggly bit of trouble trying to display a messagebox immediately after a dialog.DoModal() . Has anyone out there seen this type of behaviour where any messagebox call after a dialog box fails to be displayed? Did I miss something obvious? The application was created as an simple MFC GUI app. Your help is much appreciated. //********************************************************************* dlg.m_strWarningtext.Format(strMsgBuf); nResponse = dlg.DoModal(); // >>>>> At this point, any messagebox call returns IDOK without even being displayed. if (nResponse == IDOK) { // Do stuff sprintf(strMsgBuf,"Messagebox text "); nRetVal = MessageBox( NULL, (LPCTSTR)strMsgBuf, "Error", MB_OK | MB_ICONERROR ); // >>>>> nRetVal is always == IDOK and the messagebox won't display } else if (nResponse == IDCANCEL) { // Do stuff } //*********************************************************************
-
I'm a Windows programming beginner, been programming DOS for some time, starting to make the switch and I'm having a niggly bit of trouble trying to display a messagebox immediately after a dialog.DoModal() . Has anyone out there seen this type of behaviour where any messagebox call after a dialog box fails to be displayed? Did I miss something obvious? The application was created as an simple MFC GUI app. Your help is much appreciated. //********************************************************************* dlg.m_strWarningtext.Format(strMsgBuf); nResponse = dlg.DoModal(); // >>>>> At this point, any messagebox call returns IDOK without even being displayed. if (nResponse == IDOK) { // Do stuff sprintf(strMsgBuf,"Messagebox text "); nRetVal = MessageBox( NULL, (LPCTSTR)strMsgBuf, "Error", MB_OK | MB_ICONERROR ); // >>>>> nRetVal is always == IDOK and the messagebox won't display } else if (nResponse == IDCANCEL) { // Do stuff } //*********************************************************************
I don't know the answer, but if you're using MFC, replace the last two lines with nRetVal = AfxMessageBox("MessageBox Test"); Christian The content of this post is not necessarily the opinion of my yadda yadda yadda. To understand recursion, we must first understand recursion.
-
I'm a Windows programming beginner, been programming DOS for some time, starting to make the switch and I'm having a niggly bit of trouble trying to display a messagebox immediately after a dialog.DoModal() . Has anyone out there seen this type of behaviour where any messagebox call after a dialog box fails to be displayed? Did I miss something obvious? The application was created as an simple MFC GUI app. Your help is much appreciated. //********************************************************************* dlg.m_strWarningtext.Format(strMsgBuf); nResponse = dlg.DoModal(); // >>>>> At this point, any messagebox call returns IDOK without even being displayed. if (nResponse == IDOK) { // Do stuff sprintf(strMsgBuf,"Messagebox text "); nRetVal = MessageBox( NULL, (LPCTSTR)strMsgBuf, "Error", MB_OK | MB_ICONERROR ); // >>>>> nRetVal is always == IDOK and the messagebox won't display } else if (nResponse == IDCANCEL) { // Do stuff } //*********************************************************************
Hello, the codegurus around the world.;) If you use the debugger, you may find the reason. I think that ::MessageBox() should be called in if (response == IDOK) The other way is that we put MessageBox() in CMyDialog::OnOK(). We often tend to use MessageBox() to check something. But, TRACE, TRACE1, and so on works also in the debug mode.
void CMyDialog::OnOK()
{
MessageBox("OK button works", "Test");
TRACE ("OK button works")
// In Debug mode, "OK button works" shows in Output windows;CDialog::OnOK();
}
Have a nice day! -Masaaki Onishi-