I've got the pointer to the control with function
CWnd* CWnd::GetDlgItem(int ITEM_ID)
so i've got CWnd*
pointer which points to the control,
but simply can't find any method within CWnd
class that will
retrieve the size and location of a given control.
Any help?
Solution 1. this->SetWindowPos(NULL,0,0,newWidth,newHeight,SWP_NOMOVE | SWP_NOZORDER); This will change the size of the dialog, but you will need to move and resize the control inside the dialog using the same function but with the CWnd of the control.
To create the column(s) of a list control, you can use the CListCtrl::InsertColumn() method. One of its syntaxes is: int InsertColumn(int nCol, const LVCOLUMN* pColumn); The nCol argument is the index of the column that this call will create.
How do I create and use a text box (Edit Control) in a dialog box? Visual Studio calls a text box an Edit control. In the dialog resource click the Toolbox tab and select Edit Control from the list. Use the mouse to click and drag the size and location of the text box.
MFC supports both kinds of dialog box with class CDialog . The controls are arranged and managed using a dialog-template resource, created with the dialog editor. Property sheets, also known as tab dialog boxes, are dialog boxes that contain "pages" of distinct dialog-box controls.
CRect rect;
CWnd *pWnd = pDlg->GetDlgItem(YOUR_CONTROL_ID);
pWnd->GetWindowRect(&rect);
pDlg->ScreenToClient(&rect); //optional step - see below
//position: rect.left, rect.top
//size: rect.Width(), rect.Height()
GetWindowRect
gives the screen coordinates of the control. pDlg->ScreenToClient
will then convert them be relative to the dialog's client area, which is usually what you need.
Note: pDlg
above is the dialog. If you're in a member function of the dialog class, just remove the pDlg->
.
In straight MFC/Win32: (Example of WM_INITDIALOG)
RECT r;
HWND h = GetDlgItem(hwndDlg, IDC_YOURCTLID);
GetWindowRect(h, &r); //get window rect of control relative to screen
POINT pt = { r.left, r.top }; //new point object using rect x, y
ScreenToClient(hwndDlg, &pt); //convert screen co-ords to client based points
//example if I wanted to move said control
MoveWindow(h, pt.x, pt.y + 15, r.right - r.left, r.bottom - r.top, TRUE); //r.right - r.left, r.bottom - r.top to keep control at its current size
Hope this helps! Happy coding :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With