Hi,
Can somebody show me how to center a window onto the screen? I would like to know how to get the correct x and y if given the window height and width to place that window onto the center of the screen.
Thanks,
Barry
Posted on 2002-11-18 16:26:40 by bgong68
Do you know the meaning of "search"?
Search for "center window":
http://www.asmcommunity.net/board/index.php?topic=5437&highlight=center+window
Posted on 2002-11-18 17:02:28 by bazik
Taken from www.madwizard.org


CenterScreen proc hwnd:HWND
LOCAL DlgHeight:DWORD
LOCAL DlgWidth:DWORD
LOCAL DlgRect:RECT
LOCAL DesktopRect:RECT

invoke GetWindowRect,hwnd,ADDR DlgRect
invoke GetDesktopWindow
mov ecx,eax
invoke GetWindowRect,ecx,addr DesktopRect
push 0
mov eax,DlgRect.bottom
sub eax,DlgRect.top
mov DlgHeight,eax
push eax
mov eax,DlgRect.right
sub eax,DlgRect.left
mov DlgWidth,eax
push eax
mov eax,DesktopRect.bottom
sub eax,DlgHeight
shr eax,1
push eax
mov eax,DesktopRect.right
sub eax,DlgWidth
shr eax,1
push eax
push hwnd
call MoveWindow
ret
CenterScreen endp


My code
	invoke 	GetSystemMetrics, SM_CXSCREEN

sub eax,800
shr eax,1
xchg eax,ebx
invoke GetSystemMetrics, SM_CYSCREEN
sub eax,600
shr eax,1
invoke CreateWindowEx, NULL,ADDR ClassName, ADDR AppName, WS_BORDER or WS_VISIBLE or WS_OVERLAPPEDWINDOW,\
ebx,eax,800,600, 0, 0, hinst, 0
Posted on 2002-11-19 06:33:45 by roticv
Hi roticv,
Thanks for the code and showing me where you got it from. I will check out that website as well.
Barry ^_^
Posted on 2002-11-19 06:46:53 by bgong68
If you look in the MASM32 subfolders, your will discover many useful functions, the onr roticv posted, for example. :)
Posted on 2002-11-19 08:50:56 by JCP