CWindow::CenterWindow

Centers the window against a given window.

BOOL CenterWindow(
   HWND hWndCenter = NULL 
) throw();

Parameters

  • hWndCenter
    [in] The handle to the window against which to center. If this parameter is NULL (the default value), the method will set hWndCenter to the window's parent window if it is a child window. Otherwise, it will set hWndCenter to the window's owner window.

Return Value

TRUE if the window is successfully centered; otherwise, FALSE.

Example

//The following example attaches various HWNDs to the CWindow objects 
//and calls CWindow::CenterWindow() for each of them

CWindow childWindow, popupWindow, overlappedWindow;

childWindow.Attach(hWndChild); //a window created with WS_CHILD style
childWindow.CenterWindow();    //This will center the child 
                               //window against its Parent window

popupWindow.Attach(hWndPopup); //a window created with WS_POPUP style
popupWindow.CenterWindow();    //This will center the popup window 
                               //against its Owner window

overlappedWindow.Attach(hWndOverlapped); //a window created with 
                                         //WS_OVERLAPPED style
overlappedWindow.CenterWindow(::GetDesktopWindow()); //This will center 
                       //the overlapped window against the DeskTop window

Requirements

Header: atlwin.h

See Also

Reference

CWindow Class

CWindow::MoveWindow

CWindow::SetWindowPos

Other Resources

CWindow Members