CWindow::CenterWindow

BOOL CenterWindow( HWND hWndCenter = NULL );

Return Value

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

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.

Remarks

Centers the window against a given window.

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

CWindow OverviewClass Members

See Also   CWindow::MoveWindow, CWindow::SetWindowPos