Access CDialog members?

I've got a Dialog-based Application.
By default VC created an App and a Dlg class.
In the App's InitInstance, to show the dialog box, there is a declaration CMyDlg dlg, then a dlg.DoModal().

My question is, how do I access dlg members from my other classes?  For instance, I will have a status on the dialog box, and I want other classes to have access to that status to write to it.

Help much appreciated

Who is Participating?
pkreddyConnect With a Mentor Commented:
 The 'C' was an extra thing Remove that and use. But before that ensure that
       m_pMainWnd = &dlg;       //Has been done

You can use..


  Please be more specfic about the problem.

 You can access this way or


-- PK
FreddieMAuthor Commented:
Thanks for your help pkreddy.

I tried your first suggestion

before posting my question here.

But dlg isn't a public member of the App.  It's declared in InitInstance.
When I tried declaring it as a public member I got VC exceptions on startup - it didn't seem to like me declaring a dialog as a public member - it only accepted it in InitInstance.

For CAfxGetMainWnd - that didn't compile -
"error C2065: 'CAfxGetMainWnd' : undeclared identifier"

Anything else I can try?

Many thanks

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Meir RivkinFull stack Software EngineerCommented:
FreddieM: its quite simple, in order to give other classes an access to its data members u need to have some function which retrieves the data member.

class CMainDialog :: public CDialog
CStatusbar& GetStatusar(){return m_wndStatusbar;}

CStatusbar m_wndStatusbar;

Meir RivkinFull stack Software EngineerCommented:
now, u can write to it:
GetStatusar().SetWindowText("write text here....");
FreddieMAuthor Commented:
Thanks for your comment sedgwick.

But it was the AfxGetMainWnd part that I didn't know.
(I've not done that much MFC).
I figured that I if I could get to a public member variable as a quick test, then I could design it better with access functions as you suggested, later.

Thanks again, but pkreddy answered the bit I really didn't know.
FreddieMAuthor Commented:
Excellent (after fixing the 'C' typo!!!)

Thanks very much pkreddy.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.