CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Posts
    18

    Accessing my main window control...

    Hello to all !!!

    I'm fairly new to MFC programming and I was wondering how can I reference my main window controls when i'm within a modal dialog box ???

    Any help would be greatly appreciated

    Happy coding =:-)


  2. #2
    Join Date
    May 1999
    Location
    Toronto, Ontario, Canada
    Posts
    155

    Re: Accessing my main window control...

    You can try using AfxGetMainWnd, this should return your mainframe window.

    -Safai

  3. #3
    Join Date
    May 1999
    Posts
    18

    Re: Accessing my main window control...

    Hummm thanx for the answer but it didn't help very much... After getting the CWnd pointer to the main window how can refer to the controls in it ??? i.e I have a CListBox name lst...

    thanx in advance


  4. #4
    Join Date
    May 1999
    Location
    Toronto, Ontario, Canada
    Posts
    155

    Re: Accessing my main window control...

    Well, you can cast your "CMainFrame" to the CWnd you got from AfxGetMainWnd. Then you can access the controls inside it, assuming you have member variables of those controls.

    CMainFrame *pMainFrame = (CMainFrame*)AfxGetMainWnd();
    pMainFrame->m_listbox.AddString("item1");



    You can do this cast because you know for sure that the main window returned from AfxGetMainWnd is always of the type CMainFrame. (or whatever you set in CWinApp::InitInstance throught CWinApp::m_pMainWnd variable)

    -Safai

  5. #5
    Join Date
    May 1999
    Posts
    18

    Re: Accessing my main window control...

    Thank you very much... It works wonderfully


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