In writing some software, we tend to prefer a more concise, fresh user interface, and in order to avoid other programs or desktops and other effects on the attention of users, we are usually accustomed to the software interface full screen, the entire display screen, at the same time, we will be the interface in the control of the location of the corresponding adjustment, Let them be centered by the size of the screen and its relative position in the dialog box.
The following is a description of the example (the full instance can be downloaded in my CSDN resource: http://download.csdn.net/detail/margin1988/8337049):
In the initialization function OnInitDialog () of the dialog box, the following actions are done in three steps:
(1) Get the screen resolution
int Nfullwidth=getsystemmetrics (sm_cxscreen); int nfullheight=getsystemmetrics (Sm_cyscreen);
(2) Control center display
CRect c1,c2; GetClientRect (C1); Gets the coordinates for the window client area for (int i=idc_button1;i<=idc_button5;i++) { GetDlgItem (i)->getwindowrect (C2); Gets the size of the bounding rectangle of the window screentoclient (C2);//The screen coordinates of the specified point on the screen are converted to user coordinates GetDlgItem (i)->setwindowpos (NULL, ( Nfullwidth-c1.right)/2+c2.left, (Nfullheight-c1.bottom)/2+c2.top,0,0,swp_nozorder| swp_nosize);}
(3) Full Screen display of dialog box (title bar removed)
CRect M_fullscreenrect; CRect Windowrect; GetWindowRect (&windowrect); CRect Clientrect; RepositionBars (0, 0xFFFF, Afx_idw_pane_first, Cwnd::reposquery, &clientrect); ClientToScreen (&clientrect); m_fullscreenrect.left=windowrect.left-clientrect.left;m_fullscreenrect.top= Windowrect.top-clientrect.top;m_fullscreenrect.right=windowrect.right-clientrect.right+nfullwidth;m_ Fullscreenrect.bottom=windowrect.bottom-clientrect.bottom+nfullheight; Windowplacement wndpl;wndpl.length=sizeof (windowplacement); wndpl.flags=0;wndpl.showcmd=sw_shownormal; Wndpl.rcnormalposition=m_fullscreenrect; SetWindowPlacement (&WNDPL);
VC + + dialog box (CDialog) Full screen display and control center display