Advertisement

Accessing other files/classes in MFC

Started by June 03, 2001 08:13 PM
2 comments, last by SikCiv 23 years, 8 months ago
Im new to MFC so im not sure how do deal with seperate classes in a DevStudio MFC app. I have created a new MFC app in Devstudio version 5, and it has created two cpp files, they are called NewProjApp and NewProjAppDlg, then I added another Dialog (a seperate file/class) by pressing Ctrl+1. But my problem is I need to access a function in the NewProjAppDlg class/file from the new dialog class I created. The NewProjAppDlg class has a public member function called "UpdateStats", and calling it within the same file is easy enough, just call UpdateStats(), but how do I call it from another class? I tried NewProjAppDlg::UpdateStats but it doesnt recognise the class, how do I do this? Demo Download: www.angelfire.com/realm/zeroone

  Downloads:  ZeroOne Realm

Add
#include "NewProjAppDlg.h"
to the top of the new dialog''s .h file

In the constructor of the dialog a pointer to the parent window is passed in. Downcast him from CWnd to CNewProjAppDlg and keep a copy of him around. Then call pNewProjAppDlg->UpdateStatus(...)

When you create the child dialog, make sure to pass this in as the parent.

Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
Im not sure what you mean about downcasting, and how do you get pNewProjAppDlg?

Ive added the header file, and in the function...
''CNewDlg::CNewDlg(CWnd *pParent, ....)''

and added the line...
''CWndParent = pParent;''

and added a global variable...
''CWnd CWndParent'' at the top of the file.

What now? Do I need to call something like
''pNewProjAppDlg = (CNewProjAppDlg)CWndParent;''

Or am I totally wrong ?

By the way, the MFC app is all dialog based.

  Downloads:  ZeroOne Realm

Im still trying to figure it out so if someone could help?
Maybe I should try an MFC forum, does anyone know a good site?

Demo Download: www.angelfire.com/realm/zeroone

  Downloads:  ZeroOne Realm

This topic is closed to new replies.

Advertisement