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.
HELP
electrickAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
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

0
 
abdijCommented:
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
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,
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)
this->GetParent()->GetDlgItem(ID_EDIT1)->SetWindowText("Hi");

Thats it.
Try it out.
VinExpert
0
The 14th Annual Expert Award Winners

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

 
abdijCommented:
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.
abdij
0
 
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
0
 
abdijCommented:
I have emailed the zipped project .
0
All Courses

From novice to tech pro — start learning today.