Export (0) Print
Expand All
MFC
Expand Minimize

CWnd::CenterWindow 

Centers a window relative to its parent.


void CenterWindow(
   CWnd* pAlternateOwner = NULL 
);

Parameters

pAlternateOwner

Pointer to an alternate window relative to which it will be centered (other than the parent window).

Usually called from CDialog::OnInitDialog to center dialog boxes relative to the main window of the application. By default, the function centers child windows relative to their parent window, and pop-up windows relative to their owner. If the pop-up window is not owned, it is centered relative to the screen. To center a window relative to a specific window which is not the owner or parent, the pAlternateOwner parameter may be set to a valid window. To force centering relative to the screen, pass the value returned by CWnd::GetDesktopWindow as pAlternateOwner.

// The following example will center an About dialog in response to a 
// button click. It is assumed that the About dialog contains an 
// additional button named IDC_CENTERWINDOW, which is also registered 
// in the CAboutDlg message map, as follows:
//   BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//      ON_BN_CLICKED(IDC_CENTERWINDOW, OnCenterWindow)
//   END_MESSAGE_MAP()

void CAboutDlg::OnCenterWindow()
{
   CenterWindow();
}

Community Additions

ADD
Show:
© 2014 Microsoft