Click to See Complete Forum and Search --> : Accessing my main window control...


Luc B.
May 31st, 1999, 02:41 PM
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 =:-)

Safai Ma
May 31st, 1999, 02:48 PM
You can try using AfxGetMainWnd, this should return your mainframe window.

-Safai

Luc B.
June 1st, 1999, 08:24 AM
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 :)

Safai Ma
June 1st, 1999, 08:33 AM
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

Luc B.
June 1st, 1999, 09:06 AM
Thank you very much... It works wonderfully :)