?
Solved

Access CDialog members?

Posted on 2001-07-26
7
Medium Priority
?
468 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

741 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