Solved

Access CDialog members?

Posted on 2001-07-26
7
435 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel Use VBA to get user's Mac Address for their computer 5 107
haveThree challenge 22 112
twoTwo  challenge 35 92
FizzBuzz challenge 9 76
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

17 Experts available now in Live!

Get 1:1 Help Now