Solved

Access CDialog members?

Posted on 2001-07-26
7
431 Views
Last Modified: 2013-11-20
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

Fred
0
Comment
Question by:FreddieM
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Expert Comment

by:pkreddy
ID: 6321241
hi,
  Please be more specfic about the problem.

 You can access this way or
  ((CDerivedApp*)AppAfxGetApp())->dlg.m_variable;

  ((CMyDlg*)(CAfxGetMainWnd())->dlg.m_variable;

-- PK
0
 

Author Comment

by:FreddieM
ID: 6321360
Thanks for your help pkreddy.

I tried your first suggestion
((CDerivedApp*)AppAfxGetApp())->dlg.m_variable;

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

Fred
0
 
LVL 1

Accepted Solution

by:
pkreddy earned 100 total points
ID: 6321379
Hi,
 The 'C' was an extra thing Remove that and use. But before that ensure that
       m_pMainWnd = &dlg;       //Has been done

You can use..

((CMyDlg*)(AfxGetMainWnd())->dlg.m_variable;

--PK
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 42

Expert Comment

by:sedgwick
ID: 6321435
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
{
public:
CStatusbar& GetStatusar(){return m_wndStatusbar;}

protected:
CStatusbar m_wndStatusbar;
};


cheers
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 6321441
now, u can write to it:
GetStatusar().SetWindowText("write text here....");
0
 

Author Comment

by:FreddieM
ID: 6321556
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.
0
 

Author Comment

by:FreddieM
ID: 6321559
Excellent (after fixing the 'C' typo!!!)

Thanks very much pkreddy.

Fred
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
windows 10 how make picture as desktop background 2 49
Doc'in system (example?) BA 7 79
either24  challenge 19 84
has77  challenge 9 68
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now