Click here to Skip to main content
12,622,568 members (30,869 online)
Click here to Skip to main content
Add your own
alternative version

Stats

5.1K views
2 bookmarked
Posted

CenterWindow in WIN32

, 23 Sep 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
void CenterWnd(HWND wnd){ RECT r,r1; GetWindowRect(wnd,&r); GetWindowRect(GetDesktopWindow(),&r1); MoveWindow(wnd,((r1.right-r1.left)-(r.right-r.left))/2, ((r1.bottom-r1.top)-(r.bottom-r.top))/2, (r.right-r.left), (r.bottom-r.top),0);}
void CenterWnd(HWND wnd)
{
   RECT r,r1;
   GetWindowRect(wnd,&r);
   GetWindowRect(GetDesktopWindow(),&r1);
   MoveWindow(wnd,((r1.right-r1.left)-(r.right-r.left))/2,
      ((r1.bottom-r1.top)-(r.bottom-r.top))/2,
      (r.right-r.left), (r.bottom-r.top),0);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Charles Kludge
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 3 Pin
ominion18-Nov-15 7:33
memberominion18-Nov-15 7:33 
GeneralThis is not an alternative as it only centers relative to th... Pin
Krosus4-Oct-11 23:22
memberKrosus4-Oct-11 23:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 23 Sep 2011
Article Copyright 2011 by Charles Kludge
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid