-
AfxMessageBox
Can anyone explain to me why m_pMainWnd = &uDlg; under the CClassMainApp::InitInstance() function causes the AfxMessageBox() function to stop working. If it is // commented out AfxMessageBox() works fine? Oh and this is in a Dialog based app!
Thanks! Charlie
-
Re: AfxMessageBox
You can use MessageBox() intead. i had that problem , but when i used MessageBox() it worked.
-
Re: AfxMessageBox
I'll take a shot.
Are you trying to use AfxMessageBox in myApp.InitInstance()? If so you are probably trying to do so AFTER the main dialog has been destroyed already, so you can't attach AfxMessageBox to it because it is no longer there.
-
Re: AfxMessageBox
Actually the m_pMainWnd = &uDlg; is something that is setup by the Application Wizard when the project was created, but it is definately before the dialog is ever used. So I still don't understand why it would affect AfxMessageBox? But thanks for giving it a shot!
Charlie
-
Re: AfxMessageBox
I actually meant, it only effects AfxMessageBox in you InitInstance method.
Here is an example of some InitInstance code:
CMyDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
// if you attempt to use AfxMessageBox after DoModal returns the m_pMainWnd may be invalid // because the destructor may have been called already.
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
If you are having problems with AfxMessageBox in some other method that's a different story.
-
Re: AfxMessageBox
I see what you are saying and maybe I should have re-worded the question and asked what is the m_pMainWnd &dlg; for. Is it the Address of the Main Dalog Window? If yes what would be an example for its use? I am fairly new to Visual C++ so please forgive me if I seem a little dense!
Thanks for responding I need to understand how these thing work!
Charlie
-
Re: AfxMessageBox
I tried sending you a private message but I kept getting errors.
Your instance of CDialog will become the main window when you set
m_pMainWnd = &dlg
I'm sure there are many uses for a pointer to the main window (m_pMainWnd) but I do not pretend to know them all.
One use is to position additional windows according to your Main Window, for instance a "please wait.." window or a progress bar window or even MessageBoxes can all be centered on the main window.
You'll find you'll learn something every day and that should be a good thing!
-
Re: AfxMessageBox
Thanks for the info and I am learning every day and it is a Good thing! Appreciate your time and effort. You gave me some new insight about m_pMainWnd and at least now I understand some uses for it!
Thanks Again!
Charlie