The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: BlackVortex on August 29, 2008, 12:43:48 AM

Title: How to create a centered window
Post by: BlackVortex on August 29, 2008, 12:43:48 AM
I thought this would be trivial, but after a lot of searching around MSDN,google,this forum's search etc I utterly failed !

Here is the situation, I create a dialog with these resource properties :

whatever DIALOGEX 300,150,196,165
FONT 8,"Tahoma",400,0,0
STYLE WS_POPUP+WS_VISIBLE
BEGIN
END


And I use this command to create it :
invoke DialogBoxParam, hInstance, ADDR DlgName,NULL,addr DlgProc,NULL

How can I set it to be created centered to the desktop/screen or as a last resort what's the best way to center it to the screen on init ?
Title: Re: How to create a centered window
Post by: hoverlees on August 29, 2008, 01:08:39 AM
You must calculate the postion yourself when processing WM_INITDIALOG message.

1.Get the screen size using GetSystemMetrics
2.Get the size of your window
3.Calculate the center position
4.Set the window position using SetWindowPos
Title: Re: How to create a centered window
Post by: drizz on August 29, 2008, 01:23:16 AM
+DS_CENTER
Title: Re: How to create a centered window
Post by: BlackVortex on August 29, 2008, 01:40:02 AM
Quote from: drizz on August 29, 2008, 01:23:16 AM
+DS_CENTER

YES ! Thank you !

     (http://www.freesmileys.org/smileys/bounce006.gif)


P.S.: Thanks hover for the info, I'll keep those APIs in mind.