Skip to content

Instantly share code, notes, and snippets.

@davidglezz
Last active December 27, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidglezz/7305324 to your computer and use it in GitHub Desktop.
Save davidglezz/7305324 to your computer and use it in GitHub Desktop.
Center window
void CenterWindow(HWND hWnd)
{
RECT rcWin;
GetWindowRect(hWnd, &rcWin);
SetWindowPos(hWnd, NULL, (GetSystemMetrics(SM_CXFULLSCREEN) - (rcWin.right - rcWin.left + 1)) / 2,
(GetSystemMetrics(SM_CYFULLSCREEN) - (rcWin.bottom - rcWin.top + 1)) / 2,
0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment