Solved

Access CDialog members?

Posted on 2001-07-26
7
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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