Assembly code snippets

Back to the snippets overview

Details

TitleNew CenterControl
AuthorJoshua
Submitted by:Joshua
Date added:2003-12-13 02:53:01
Date modified:2003-12-13 03:49:09

Comments

New version of CenterControl originally by QvasiModo
Centers a child window (control) relative to it's parent window.

Size 77 bytes (QvasiModo's: 106 bytes)

Snippet

; CenterControl
;   original by QvasiModo
;   new version by Joshua

; Centers a child window (control) relative to it's parent window.

CenterControl proto :dword

.code
option prologue:none
option epilogue:none
CenterControl proc hwnd:dword
    push ebx
    push esi
    mov esi,[esp+12]
    push 1
    sub esp,16
    push esp
    push esi
    call GetWindowRect
    pop eax
    pop ecx
    sub [esp],eax
    sub [esp+4],ecx
    push esi
    call GetParent
    sub esp,16
    push esp
    push eax
    call GetClientRect
    pop ebx
    pop edx
    pop eax
    pop ecx
    add eax,ebx
    add ecx,edx
    sub eax,[esp]
    sub ecx,[esp+4]
    sar eax,1
    sar ecx,1
    push ecx
    push eax
    push esi
    call MoveWindow
    pop esi
    pop ebx
    ret
CenterControl endp
option prologue:PrologueDef
option epilogue:EpilogueDef