CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: AfxMessageBox

  1. #1
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    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

    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

  2. #2
    Join Date
    May 1999
    Posts
    216

    Re: AfxMessageBox

    You can use MessageBox() intead. i had that problem , but when i used MessageBox() it worked.


  3. #3
    Join Date
    May 1999
    Location
    Wisconsin, USA
    Posts
    953

    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.



  4. #4
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    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

    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

  5. #5
    Join Date
    May 1999
    Location
    Wisconsin, USA
    Posts
    953

    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.



  6. #6
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    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

    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

  7. #7
    Join Date
    May 1999
    Location
    Wisconsin, USA
    Posts
    953

    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!



  8. #8
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    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

    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured