Pointer to a class

I have a derived class CMyButton : CButton
I want to create a pointer from CMyButton to CMyDialogDlg so that I can write to member variable m_EditBox, which is a control of CMyDialogDlg

Here's what I've tried:
In MyButton.h declaring
CMyDialogDlg* pDlg;
Then in the initialization of CMyButton
pDlg = GetParent();
pDlg = FindWindow("CMyDialogDlg", "WindowName")
pDlg = GetOwner();

They all return a pointer to CWnd not CMyDialogDlg, so I get an error.

The only way it works is if I declare
CWnd* pDlg;
Then the statement
pDlg->m_EditBox doesn't work cuz it's not a member of CWnd.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here is how you can do it

Store the CWnd pointer using m_pWndPointer = GetParent();

m_pWndPointer->GetDlgItem(IDC_MYSTRING)->SetWindowText("On Cancel Button Control");

Here i have used the Staic control mainpulation of CButton class derived MyOwnButton class which is a button in the Dialog containing the IDC_STRING.
On the movement of cursor over the Button i change the Dialog Static string.

Hope this is what you wanted


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi man,

  Actually i had done a sample project for the query you last posted.
I can send it to you if you give me your mailid.
Mine is abdij_b@hotmail.com
Vinayak KumbarSr Program ManagerCommented:
Adding to abdij...
Is that button is the child window of that dialog?(I mean is that button is placed on that dialog?). If yes, then u can access the edit box using(in the button.cpp)

Thats it.
Try it out.
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Dear VinExpert,

In the context of the Child Window (Button) class the Dialog is the parent.
All i am doing is storing the Parent Dialog pointer earlier, for other reference. The this->getParent()is removed by m_pWndPointer. Thats all.

Bye for now.
electrickAuthor Commented:
OK, That makes sense. So then what I was trying to do isn't really possible? (Get a direct pointer to an object in another class)

Yes abdij, I would like to see your answer to my last question, my email is electrick@centurytel.net

Thanks to All
I have emailed the zipped project .
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.