Access to control on parent dialog
I have been trying to add a new string to a combobox control on a parent dialog from one of it's children. I use the following to get a pointer to the parent dialog;
CParent* pParent; // in the header file
pParent = (CParent*) this->GetOwner(); // In the cpp file
I can read the parents variables in the child like this;
int nNumVar = pParent->m_NumVar;
I can only update the parents variables from the child with the following code;
((CParent*)pParent->m_NumVar = nNumVar;
Now I need to add a new string in a combobox from the child. The following two examples seem to be correct but don't work. Intellisense shows everything to me and lets me select the methods and the variables and compiles ok.
pParent->GetDlgItem(IDC_COMBOBOX)->AddString(strSomething);
or
((CParent*)pParent)->GetDlgItem(IDC_COMBOBOX)->AddString(strSomething);
Unfortunetly when I run the program I get an assertion error that says the controls m_pWnd value is NULL.
What can I do. Any help or comments will be greatly appreciated.
Murray Bilker [email protected]
Philadelphia Locking Systems Corp
Re: It works at my program.
Hi.
It works on my progarm.
That is, ComboBox is on the dialog. If I generate another dialog
from the first one, the program added the string to ComboBox on
the first one from the second dialog.
So, check the other stuff.
The relation bet the first dialog and the second one may not
be parent and child(actually pop-up)?
GetParent() is not pointed to the first dialog correctly?
Hope for help.
-Masaaki Onishi-
Re: It works at my program.
You are correct. I was calling the child dialog as a popup. Unfortunetly that is what the program calls for in this case. I changed the way I was getting the pointer to the parent class and that resolved the problem.
Before;
CParent* pParent;
pParent = (CParent*) this->GetOwner(); // Pointed to the frame!
Now;
CView* pParent;
pParent = ((CFrameWnd*)GetOwner())->GetActiveFrame()->GetActiveView();
Thanks for your help.
Murray Bilker [email protected]
Philadelphia Locking Systems Corp