Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - CenterWindow
Author:Arkon
Category:Win32API
File Size:399 Bytes
Uploaded at:01-Mar-03 02:50:38 am
Description:
  Center the given (hWnd) window according to screen's resolution and window's size.
  
RECT dlgRect = {0};
GetWindowRect(hWnd, &dlgRect);
int widthResolution = GetSystemMetrics(SM_CXSCREEN);
int heightResolution = GetSystemMetrics(SM_CYSCREEN);
int newXPos = (widthResolution / 2) - (abs(dlgRect.right - dlgRect.left) / 2),
    newYPos = (heightResolution / 2) - (abs(dlgRect.bottom - dlgRect.top) / 2);
SetWindowPos(hWnd, NULL, newXPos, newYPos, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
User Contributed Comments(1)
 [1] arkon | 2006-07-12 20:14:40

if you create a dialog, just set the DS_CENTER flag in the style flags.
NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[116853]
2D Rotated Rectangles Collision Detection[88948]
Keyboard Hook[77243]
UDP[65799]
HTTP Proxy[41188]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11557]
PS2 Mouse Driver[6953]
Wave Format Player[5788]
Reading FAT12[5615]
CodeGuru[5355]


All rights reserved to RageStorm © 2009