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:28-Feb-03 09:50:38 pm
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 16: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[106236]
2D Rotated Rectangles Collision Detection[79394]
Keyboard Hook[68784]
UDP[52867]
HTTP Proxy[36098]

::Top 5 Samples::
2D ColDet Rotated Rectangles[10613]
PS2 Mouse Driver[6098]
Wave Format Player[4984]
Reading FAT12[4870]
CodeGuru[4561]


All rights reserved to RageStorm © 2009