modeless dialog and GetParent()
-
Sorry I dont' know what you mean. The dialog is created via clicking a button on a CFormView derived class and its pointer (this) is passed to the Modeless Dialog constructor.
a window's parent is set by the code that creates the window (in the case of a modeless dialog, that's generally your code). if you don't set a parent wnd (usually in the dlg ctor, or in Create) it will remain NULL. Cleek | Image Toolkits | Thumbnail maker
-
a window's parent is set by the code that creates the window (in the case of a modeless dialog, that's generally your code). if you don't set a parent wnd (usually in the dlg ctor, or in Create) it will remain NULL. Cleek | Image Toolkits | Thumbnail maker
-
Look at my first post. I am setting the parent window to the dialog. Please give me an example if I am off base.
ok. wasn't sure that was what that ctor was doing. are you calling Create anywhere ? Cleek | Image Toolkits | Thumbnail maker
-
ok. wasn't sure that was what that ctor was doing. are you calling Create anywhere ? Cleek | Image Toolkits | Thumbnail maker
Here is the code that creates the modeless dialog box void CFormsFormsFormsView::OnModelessheap() { if(m_pModeless){ m_pModeless->SetForegroundWindow(); m_pModeless->CenterWindow(); } else { m_pModeless = new CModelessDialogHeap(this); m_pModeless->Create(CModelessDialogHeap::IDD); m_pModeless->CenterWindow(); m_pModeless->ShowWindow(SW_SHOW); } } It all works fine. I just don't understand why GetParent() doesn't when called from the modeless dialog box. Thanks
-
Here is the code that creates the modeless dialog box void CFormsFormsFormsView::OnModelessheap() { if(m_pModeless){ m_pModeless->SetForegroundWindow(); m_pModeless->CenterWindow(); } else { m_pModeless = new CModelessDialogHeap(this); m_pModeless->Create(CModelessDialogHeap::IDD); m_pModeless->CenterWindow(); m_pModeless->ShowWindow(SW_SHOW); } } It all works fine. I just don't understand why GetParent() doesn't when called from the modeless dialog box. Thanks
can you step into that Create call ? i suspect some other bit of code somewhere is setting the dlg's m_pParentWnd to NULL. Create is another common place to set that variable. Cleek | Image Toolkits | Thumbnail maker
-
Here is the code that creates the modeless dialog box void CFormsFormsFormsView::OnModelessheap() { if(m_pModeless){ m_pModeless->SetForegroundWindow(); m_pModeless->CenterWindow(); } else { m_pModeless = new CModelessDialogHeap(this); m_pModeless->Create(CModelessDialogHeap::IDD); m_pModeless->CenterWindow(); m_pModeless->ShowWindow(SW_SHOW); } } It all works fine. I just don't understand why GetParent() doesn't when called from the modeless dialog box. Thanks
Yes I've stepped through the code. Like I said, the parent is passed into it just fine because I can assign that pointer to a member variable. But GetParent() should do the same thing...right? Appreciate your help. Here is the code CModelessDialogHeap::CModelessDialogHeap(CWnd* pParent /*=NULL*/) : CDialog(CModelessDialogHeap::IDD, pParent) { //{{AFX_DATA_INIT(CModelessDialogHeap) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_parent=pParent; }
-
I have created a modeless dialog. I am passing in the pointer to the parent window - which happens to be a CFormView derived class. m_pModeless = new CModelessDialogHeap(this); Now when I want to get the parent pointer (m_pModeless) from the modeless dialog I can do two things. A. Store the pointer passed into the constructor of the modeless dialog and use that -- which works. B. Or, according to one article on this site "http://thecodeproject.com/dialog/gettingmodeless.asp" I should be able to use GetParent(). When I do, it doesn't. It returns an empty pointer CWnd * tmpPtr = this->GetParent(); What am I missing? Thanks!
I've tried this several different ways and it works fine each time (i.e.,
GetParent()
returns the correct value). What does the constructor ofCModelessDialogHeap
look like? From where are you callingGetParent()
? IsCModelessDialogHeap
derived fromCDialog
?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
Here is the code that creates the modeless dialog box void CFormsFormsFormsView::OnModelessheap() { if(m_pModeless){ m_pModeless->SetForegroundWindow(); m_pModeless->CenterWindow(); } else { m_pModeless = new CModelessDialogHeap(this); m_pModeless->Create(CModelessDialogHeap::IDD); m_pModeless->CenterWindow(); m_pModeless->ShowWindow(SW_SHOW); } } It all works fine. I just don't understand why GetParent() doesn't when called from the modeless dialog box. Thanks
mx483 wrote: m_pModeless->Create(CModelessDialogHeap::IDD); The only thing I do different for my modeless dialogs is to call
Create(IDD)
from within the dialog's constructor. Does commenting out the call toCenterWindow()
have any effect?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
I've tried this several different ways and it works fine each time (i.e.,
GetParent()
returns the correct value). What does the constructor ofCModelessDialogHeap
look like? From where are you callingGetParent()
? IsCModelessDialogHeap
derived fromCDialog
?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
I sent the constructor of CModelessDialogHeap already. Here it is again. CModelessDialogHeap::CModelessDialogHeap(CWnd* pParent /*=NULL*/) : CDialog(CModelessDialogHeap::IDD, pParent) { //{{AFX_DATA_INIT(CModelessDialogHeap) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_parent=pParent; } CModelessDialogHeap is derived from CDialog. As long as the parent exists it shouldn't matter where GetParent is called. But I put a button on the dialog and attempted it while it was still active. void CModelessDialogHeap::OnButton1() { CWnd * tmpPtr = this->GetParent(); } Thanks for your help as well David.
-
I sent the constructor of CModelessDialogHeap already. Here it is again. CModelessDialogHeap::CModelessDialogHeap(CWnd* pParent /*=NULL*/) : CDialog(CModelessDialogHeap::IDD, pParent) { //{{AFX_DATA_INIT(CModelessDialogHeap) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_parent=pParent; } CModelessDialogHeap is derived from CDialog. As long as the parent exists it shouldn't matter where GetParent is called. But I put a button on the dialog and attempted it while it was still active. void CModelessDialogHeap::OnButton1() { CWnd * tmpPtr = this->GetParent(); } Thanks for your help as well David.
At this point my suggestion would be to create a little dialog-based test application that does nothing but create and show a modeless dialog in the
OnInitDialog()
method. Let me know how that works out.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
At this point my suggestion would be to create a little dialog-based test application that does nothing but create and show a modeless dialog in the
OnInitDialog()
method. Let me know how that works out.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
Okay I created a dialog based app and the GetParent function works as advertised. So now we know that the problem is more likely a conceptual one. The mainApp dialog is a popup and the CDialog derived modeless dialog is also a popup. Code is exactly the same as the problem project. In the problem project example I couldn't get to work I had an MDI application that had a CFormView derived class. It was a child. That child had a button when pressed would create the CDialog derived class modeless dialog. The CDialog derived class was set as PopUp. So can't a child spawn a modeless dialog (works) and can't that dialog in turn know it's spawning entity as Parent (GetParent). I won't mention anything about child as it was demonstrated to me by David that a modeless dialog shouldn't have a child style. I agree. I think this is important because these are pretty basic concepts. Thanks for your help.