Assembly code snippets

Back to the snippets overview

Details

TitleCentering a Window on the Screen
AuthorIczelion
Submitted by:JimmyClif
Date added:2002-02-17 19:56:01
Date modified:2002-02-17 19:56:28

Comments

It centers the usually MainWindow on the Screen.

Snippet

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