Click to See Complete Forum and Search --> : AfxMessageBox


Charlie Curtis
May 1st, 1999, 12:50 PM
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

ravish
May 3rd, 1999, 03:48 PM
You can use MessageBox() intead. i had that problem , but when i used MessageBox() it worked.

PeterK
May 4th, 1999, 04:09 PM
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.

Charlie Curtis
May 5th, 1999, 07:08 AM
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

PeterK
May 5th, 1999, 02:28 PM
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.

Charlie Curtis
May 10th, 1999, 09:51 AM
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

PeterK
May 10th, 1999, 11:57 AM
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!

Charlie Curtis
May 10th, 1999, 12:17 PM
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