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?

[Webinar] Streamline your web hosting managementRegister Today

abdijConnect With a Mentor Commented:
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

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.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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 .
All Courses

From novice to tech pro — start learning today.