• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 997
  • Last Modified:

Center Dialog - Win32

I want a function in my InitDialog:

case WM_INITDIALOG:
 
     CenterDialog(hWndDlg);
     .
     .
     .

thing is... I don't know how.

I have played with system metric stuff, but no success.

Thanks!
0
edvinson
Asked:
edvinson
  • 3
  • 3
1 Solution
 
jkrCommented:
You can do that like

void CenterWindow (HWND hwnd) {

      RECT rc;

      GetWindowRect(&rc);

      int nWidth = rc.right - rc.left;
      int nHeight = rc.bottom - rc.top;

      int X = ((int) GetSystemMetrics(SM_CXFULLSCREEN) - nWidth) /2;       // center window horizontally
    int Y = ((int) GetSystemMetrics(SM_CYFULLSCREEN) - nHeight) /2;      // and vertically


      MoveWindow(hwnd,X,Y,nWidth,nHeight,TRUE);
}
0
 
edvinsonAuthor Commented:
Hey JKR, how come you didn't call C++ , JKR when you invented it? ;)
0
 
edvinsonAuthor Commented:
In case others are reading this, jkr's above comment works great! He made a type though:

change:

GetWindowRect(&rc);

to

 GetWindowRect(hwnd, &rc);

and you got a winner!

Thanks.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jkrCommented:
Argh, my fault, I should have compile it ;o)
0
 
edvinsonAuthor Commented:
I can't believe I made a typo on the word "typo" in my last comment.
0
 
jkrCommented:
*g*
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now