Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

External Class accessing Main Dialog Class

Status
Not open for further replies.
Jan 20, 2005
180
US

I have 3 classes, the App, the App Dialog and an external class. I need this external class to be able to access the Dialog Class, to set and get text from a edit box.

 
Make an overloaded constructor for the external class then when creating a new instance of it (from the dialog class), send in 'this' to the external class's constructor. Make sure the argument is of type 'CYourDialogClassNameHere'. Include the header file for the dialog. now you should be able to access any public members of your dialog class.

BlackDice

 
I think I understand, but Im getting errors trying to do this...

So, what I want to do instead is combine them more or less... This will be a temp solution..
I want to put my external class into my dialog class.

CMyCls:public CDialog {
...
CexternalCls xc;
CInternalCls ic;
}

How can I get the ic class to access the xc class functions that Im going to need in this case? Go about doing it the same way I assume more or less? Or is there an easier way to access a parents member info?


 
Any class can access another classes public functions. If you need to access any private or protected functions, you need to add a 'friend' declaration into the class you want access to. Example:
Code:
class CexternalCls
{
   friend class CInternalCls;  // Let CInternalCls access anything in this class.
...
};
 
>I need this external class to be able to access the Dialog Class, to set and get text from a edit box.

Consider if it's not the other way around. Ie the Dialog sets / gets data to the other class.

Reason: Acting upon events in the dialog is trivial since there is already message handling support in it (if you want to trigger the data shuffling by such events that is).

If the "other class" is running in a separate thread doing stuff for other reasons you might want to look into "Threads in a GUI (MFC) app the easy way" : faq116-5162

/Per
[sub]
www.perfnurt.se[/sub]
 
I hope I never have to do a threaded process at my current job. If I need to do that someone will have to come shoot me. As if we ever get that big, there will be people under me writing the code. 8)

And Thanks all of you for your help.. I have learned a few things, relearned a couple and totally screwed up what I was doing, arent backups wonderful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top