DLGTemplate MapDialogRect() problem
-
Hello, I have a dialog without resources which works fine.In a class derived from CDialog I have a variable of type DLGTemplate.This variable has default x,y,cx,cy values set in the constructor. But I want to increase the height and width of the dialog box in accordance with the number of windows controls added to the dialog box.I am adding windows controls in the OnCreate() function of Dialog class like this. CRect Rect(10,10,100,100); CComboBox* Combo = new CComboBox; Combo->Create(WS_VISIBLE | WS_CHILD |CBS_SORT, Rect, this, ID); How do I find the relation between the above Rect's coordinates and the coordinates of the dialog box? I tried MapDialogRect but I don't understand what exactly is done there? Please help. Thanks Prithaa
-
Hello, I have a dialog without resources which works fine.In a class derived from CDialog I have a variable of type DLGTemplate.This variable has default x,y,cx,cy values set in the constructor. But I want to increase the height and width of the dialog box in accordance with the number of windows controls added to the dialog box.I am adding windows controls in the OnCreate() function of Dialog class like this. CRect Rect(10,10,100,100); CComboBox* Combo = new CComboBox; Combo->Create(WS_VISIBLE | WS_CHILD |CBS_SORT, Rect, this, ID); How do I find the relation between the above Rect's coordinates and the coordinates of the dialog box? I tried MapDialogRect but I don't understand what exactly is done there? Please help. Thanks Prithaa
The co-ordinates specified in the control's Create() call are specified in the parent's (your dialogue's) CLIENT co-ordinates. 'Client' co-ords have their (0, 0) at the top-left of the space *within* any border and title bar the dialogue has. If it has no border and no title bar, then this is the same as the top-left of the full dialogue. If you want to know how far the control is from the top-left of yoour dialogue and you have a title bar and / or border, then you need to get the dialogues 'window' rect, and the control's 'window' rect, and then you can calculate the offset. Note, though, that if you ask a control for its client rect, it gives you co-ordinates relative to *its*own* client area, not its parent. If you ask a control or window for its 'window' rect, it gicves you co-ords relative to *the*screen's* top-left. So, to get the offset from a dialogue's client arrea to a control's top-left, do this: CRect rctControl ; MyControl.GetWindowRect(&rctControl); // It's relative to top-left of screen. MyDlg.ScreenToClient(&rctControl); // Now, relative to top-left of dlg's client area. To get it relative to the full dlg's top-left (ignoring title bar and border): CRect rctControl ; MyControl.GetWindowRect(&rctControl); // It's relative to top-left of screen. CRect rctDlg ; MyDlg.GetWindowRect(&rctDlg); rctControl.OffsetRect(rctDlg.left - rctControl.left, rctDlg.top - rctControl.top); // Now, relative to top-left of dlg's full area.
-
Hello, I have a dialog without resources which works fine.In a class derived from CDialog I have a variable of type DLGTemplate.This variable has default x,y,cx,cy values set in the constructor. But I want to increase the height and width of the dialog box in accordance with the number of windows controls added to the dialog box.I am adding windows controls in the OnCreate() function of Dialog class like this. CRect Rect(10,10,100,100); CComboBox* Combo = new CComboBox; Combo->Create(WS_VISIBLE | WS_CHILD |CBS_SORT, Rect, this, ID); How do I find the relation between the above Rect's coordinates and the coordinates of the dialog box? I tried MapDialogRect but I don't understand what exactly is done there? Please help. Thanks Prithaa
If you know your client area size, and you want to calculate the window size that will give you that client area size, you can use: CWnd::CalcWindowRect() (MFC) or AdjustWindowRect()/AdjustWindowRectEx() (Win32) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: