Recently doing a project requires the control to change with the size of the dialog box, so you need to get the dialog window, the control's size, and the position exactly.
After a good search, testing, finally saw the hope. Here are some functions to get the window position and size, as in the following example:
1. Get screen resolution
//The bottom two functions get the size of the display screen, but do not include areas such as the taskbarintCX =GetSystemMetrics (sm_cxfullscreen);intcy =GetSystemMetrics (sm_cyfullscreen);//The bottom two functions get the actual size of the screen: screen resolutionintNwidth=getsystemmetrics (Sm_cxscreen);//Screen WidthintNheight=getsystemmetrics (Sm_cyscreen);//Screen HeightCString Strscreen;strscreen.format (L"%d,%d", Nwidth,nheight); MessageBox (strscreen);
2. Get dialog box form size and its screen coordinates
//dialog box form size and its screen coordinatesCRect Rectdlg;//Act 1:GetClientRect (RECTDLG);//get the size of the form//Act 2://GetWindowRect (RECTDLG);//get the position of the form on the screen//screentoclient (RECTDLG);CString Strdlg;strdlg.format (L"%d,%d,%d,%d", Rectdlg.left,rectdlg.top,rectdlg.width (), Rectdlg.height ()); MessageBox (STRDLG);
3. Get control size and position
//control size and positionCRect Rectctrl; CStatic*p= (cstatic*) GetDlgItem (idc_static_test);p->movewindow ( -, -, -, -);//change the size of the control and move it to the specified positionP->GetWindowRect (Rectctrl); This-screentoclient (Rectctrl);//GetDlgItem (idc_static_test)->getclientrect (Rectctrl);CString str;str. Format (L"%d,%d,%d,%d", Rectctrl.left,rectctrl.top,rectctrl.width (), Rectctrl.height ()); MessageBox (str);
Summarize:
1. GetSystemMetrics () --to obtain the defined system data or system configuration information;
2, GetClientRect () to get the location and size of the customer area, generally used to get the window size;
3, GetWindowRect ()-Gets the screen coordinates of the window (dialog box or control), typically used to get the screen coordinates of the dialog box or to use the client area coordinates of the get control with the ScreenToClient ();
4, ScreenToClient ()--screen coordinates convert to client area coordinates, general and GetWindowRect () use to get the client area coordinates of the control;
Access to MFC window position and size