![]() ![]() Void LeoDavidsonUtils::CentreWindow(HWND hWndToMove, HWND hWndRelative) the window centres on the desktop instead. On systems before Windows 2000 and Windows 98 which don't support multiple monitors, Give hWndRelative NULL to centre on the monitor with the mouse pointer. (It will centre in the monitor with the mouse, by default, and should correctly handle negative screen coordinates.) Here's a version which works with multiple monitors on systems which support them. To the main dialog, which is the main window of the application: Then I added code to CSubDialog::OnInitDialog() to center it with respect Our brute-force CenterWindowOnOwner() function. SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE) Move the window to the correct coordinates with SetWindowPos() Int yTop = (rectToCenterOn.top + rectToCenterOn.bottom) / 2. Next, we apply the same centering // algorithm as does CenterWindow() // find the upper left of where we should center to int xLeft = (rectToCenterOn.left + rectToCenterOn.right) / 2. Now rectWndToCenterOn contains the screen rectangle of the window // pointed to by pWndToCenterOn. PWndToCenterOn->GetWindowRect(&rectToCenterOn) Get the client rectangle of the window on which we want to center // Make sure the pointer is not NULL first if (pWndToCenterOn = NULL) Void CSubDialog::CenterWindowOnOwner(CWnd* pWndToCenterOn)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |