GetParent when modeless
-
I have a modeless dialog that pops up a MODAL dialog. What I want to do is position that MODAL child relative to the "parent" modeless dialog - offset upper-left corner by +50. What I can't do is get a pointer to the modeless (parent) dialog. My code just references the governing MainFrame window. Here is what I'm trying: BOOL CPopUpDlg::OnInitDialog() { CDialog::OnInitDialog(); CRect pRect; CWnd *pParentWnd; pParentWnd = GetParent(); // tried GetParentOwner() too pParentWnd->GetWindowRect(&pRect); MoveWindow(pRect.left + 50, pRect.top + 50, 400, 400, NULL); return (TRUE); } Can you help/explain how I reference the correct modeless parent I want? Thanks. John
-
I have a modeless dialog that pops up a MODAL dialog. What I want to do is position that MODAL child relative to the "parent" modeless dialog - offset upper-left corner by +50. What I can't do is get a pointer to the modeless (parent) dialog. My code just references the governing MainFrame window. Here is what I'm trying: BOOL CPopUpDlg::OnInitDialog() { CDialog::OnInitDialog(); CRect pRect; CWnd *pParentWnd; pParentWnd = GetParent(); // tried GetParentOwner() too pParentWnd->GetWindowRect(&pRect); MoveWindow(pRect.left + 50, pRect.top + 50, 400, 400, NULL); return (TRUE); } Can you help/explain how I reference the correct modeless parent I want? Thanks. John
GetParent()
should return a pointer to the modeless dialog, if that is in fact who createdCPopUpDlg
. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com -
I have a modeless dialog that pops up a MODAL dialog. What I want to do is position that MODAL child relative to the "parent" modeless dialog - offset upper-left corner by +50. What I can't do is get a pointer to the modeless (parent) dialog. My code just references the governing MainFrame window. Here is what I'm trying: BOOL CPopUpDlg::OnInitDialog() { CDialog::OnInitDialog(); CRect pRect; CWnd *pParentWnd; pParentWnd = GetParent(); // tried GetParentOwner() too pParentWnd->GetWindowRect(&pRect); MoveWindow(pRect.left + 50, pRect.top + 50, 400, 400, NULL); return (TRUE); } Can you help/explain how I reference the correct modeless parent I want? Thanks. John
Try using
SetWindowPos()
ifMoveWindow()
doesn't work. (Cheesy answer, I know). /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com -
I have a modeless dialog that pops up a MODAL dialog. What I want to do is position that MODAL child relative to the "parent" modeless dialog - offset upper-left corner by +50. What I can't do is get a pointer to the modeless (parent) dialog. My code just references the governing MainFrame window. Here is what I'm trying: BOOL CPopUpDlg::OnInitDialog() { CDialog::OnInitDialog(); CRect pRect; CWnd *pParentWnd; pParentWnd = GetParent(); // tried GetParentOwner() too pParentWnd->GetWindowRect(&pRect); MoveWindow(pRect.left + 50, pRect.top + 50, 400, 400, NULL); return (TRUE); } Can you help/explain how I reference the correct modeless parent I want? Thanks. John
GetWindowRect() returns screen coordinates and MoveWindow() uses client coordinates for child windows. Try using ScreenToCLient(). Also how do you know GetParent() is returning the MainFrame. Have you verified this somehow. Neville Franks, Author of ED for Windows. www.getsoft.com
-
GetWindowRect() returns screen coordinates and MoveWindow() uses client coordinates for child windows. Try using ScreenToCLient(). Also how do you know GetParent() is returning the MainFrame. Have you verified this somehow. Neville Franks, Author of ED for Windows. www.getsoft.com
The displacement of the window works (one way or the other - sans ScreenToClient()), However, I see that the coordinates and thus my ParentWnd reference are with respect to the MainFrame. When I move the main frame (the window with the menu bar and tool bar for my app), the modal window is offset the same amount with respect to the main frame's window. This is the case every time I popup the modal window from my modeless property sheet. Any ideas???
-
The displacement of the window works (one way or the other - sans ScreenToClient()), However, I see that the coordinates and thus my ParentWnd reference are with respect to the MainFrame. When I move the main frame (the window with the menu bar and tool bar for my app), the modal window is offset the same amount with respect to the main frame's window. This is the case every time I popup the modal window from my modeless property sheet. Any ideas???
Does the code the creates the modal popup dialog specify the modeless dialog as its parent? Also if you look at the Window info for the Modal dialog in Spy++ or WinSpector is it correct? Neville Franks, Author of ED for Windows. www.getsoft.com
-
GetParent()
should return a pointer to the modeless dialog, if that is in fact who createdCPopUpDlg
. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.comOk, here is what I have: A modeless CPropertySheet derived dialog with a CButton that pops up a modal dialog. The modal dialog I use to collect a couple fields of data SPECIFIC to the parent modeless Sheet. What happens now is when I pop up the modal dialog, the positioning is relative to the Main Frame. I want the modal dialog to be placed right over the modeless Sheet (dialog). Also, I can see that my method of placing the modal dialog is relative to the Main Frame because when I move the Main Frame around, the modal dialog is offset +50 from the Main Frame. Thanks for help (in advance)
-
Does the code the creates the modal popup dialog specify the modeless dialog as its parent? Also if you look at the Window info for the Modal dialog in Spy++ or WinSpector is it correct? Neville Franks, Author of ED for Windows. www.getsoft.com
I don't do it explicitly. The modeless property sheet (or the property page on the sheet) calls DoModal(). So it happens like this: void CPage2Dlg::OnButton() { CPopUpDlg dlg; dlg.DoModal(); // position WRT the modeless parent } Using Spy++, I get some wacked results -- in the OnInitDialog() of the modal dialog, GetParent() returned and address different that what I found using Spy++ for: (Main Frame) - 0x002204EC Prop Sheet - 0x000D0534 modal dialog itself - 0x00030DC0 GetParent() -- 0x00355290 Oh the agony!!!!
-
I don't do it explicitly. The modeless property sheet (or the property page on the sheet) calls DoModal(). So it happens like this: void CPage2Dlg::OnButton() { CPopUpDlg dlg; dlg.DoModal(); // position WRT the modeless parent } Using Spy++, I get some wacked results -- in the OnInitDialog() of the modal dialog, GetParent() returned and address different that what I found using Spy++ for: (Main Frame) - 0x002204EC Prop Sheet - 0x000D0534 modal dialog itself - 0x00030DC0 GetParent() -- 0x00355290 Oh the agony!!!!
void CPage2Dlg::OnButton() { CPopUpDlg dlg(WHATEVER_TEMPLATE_ID_YOU_ARE_USING,**this**); dlg.DoModal(); // position WRT the modeless parent }
afaik, it should work eperales -
I don't do it explicitly. The modeless property sheet (or the property page on the sheet) calls DoModal(). So it happens like this: void CPage2Dlg::OnButton() { CPopUpDlg dlg; dlg.DoModal(); // position WRT the modeless parent } Using Spy++, I get some wacked results -- in the OnInitDialog() of the modal dialog, GetParent() returned and address different that what I found using Spy++ for: (Main Frame) - 0x002204EC Prop Sheet - 0x000D0534 modal dialog itself - 0x00030DC0 GetParent() -- 0x00355290 Oh the agony!!!!
Well I think you are getting a bit closer. Track down what window 0x00355290 is on Spy++. You either need to set the Modal dialog up so GetParent() returns the right thing, or find another way to get the Modeless dlg hWnd. Neville Franks, Author of ED for Windows. www.getsoft.com
-
I don't do it explicitly. The modeless property sheet (or the property page on the sheet) calls DoModal(). So it happens like this: void CPage2Dlg::OnButton() { CPopUpDlg dlg; dlg.DoModal(); // position WRT the modeless parent } Using Spy++, I get some wacked results -- in the OnInitDialog() of the modal dialog, GetParent() returned and address different that what I found using Spy++ for: (Main Frame) - 0x002204EC Prop Sheet - 0x000D0534 modal dialog itself - 0x00030DC0 GetParent() -- 0x00355290 Oh the agony!!!!
Save the property sheet's pointer in the property page, and pass it to
CPopUpDlg
inOnButton()
. That will guarantee that you have the right origin window. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com