News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

My First Procedure - CenterWindow

Started by peaslee, April 01, 2009, 09:23:33 PM

Previous topic - Next topic

peaslee

With some help from others on GetWindowInfo, here is my procedure for centering a window:


CenterWindow proc hwnd:HWND

LOCAL WinWidth
LOCAL WinHeight
LOCAL NewX
LOCAL NewY
LOCAL WinInfo:WINDOWINFO

invoke GetWindowInfo, hwnd, ADDR WinInfo
mov    eax, WinInfo.rcWindow.right
sub    eax, WinInfo.rcWindow.left
mov    WinWidth, eax
mov    eax, WinInfo.rcWindow.bottom
sub    eax, WinInfo.rcWindow.top
mov    WinHeight, eax

invoke GetSystemMetrics, SM_CXSCREEN
sub    eax, WinWidth
shr    eax, 1
mov    NewX, eax

invoke GetSystemMetrics, SM_CYSCREEN
sub    eax, WinHeight
shr    eax, 1
mov    NewY, eax

invoke SetWindowPos, hwnd, HWND_NOTOPMOST, NewX, NewY, WinWidth, WinHeight, NULL
ret

CenterWindow endp



This should be invoked before ShowWindow to avoid flicker.

Bruce
Bruce Peaslee
"Reality is a crutch for those who can't do drugs."

ecube

nice work! in GoASM 64bit that'd be something like


CenterWindow FRAME hwnd
LOCAL WinWidth:Q
LOCAL WinHeight:Q
LOCAL NewX:Q
LOCAL NewY:Q
LOCAL WinInfo:WINDOWINFO

invoke GetWindowInfo,[hwnd], ADDR WinInfo
mov    rax, [WinInfo.rcWindow.right]
sub     rax, [WinInfo.rcWindow.left]
mov    Q[WinWidth], rax
mov    rax, [WinInfo.rcWindow.bottom]
sub     rax, [WinInfo.rcWindow.top]
mov    Q[WinHeight], rax

invoke GetSystemMetrics, SM_CXSCREEN
sub    rax, [WinWidth]
shr     rax, 1
mov   Q[NewX], rax

invoke GetSystemMetrics, SM_CYSCREEN
sub    rax, [WinHeight]
shr     rax, 1
mov    Q[NewY], rax

invoke SetWindowPos, [hwnd], HWND_NOTOPMOST, [NewX], [NewY],[ WinWidth], [WinHeight], NULL
ret
endf

can I use the 32bit and 64bit version of your code in the SDK i'm releasing tonight for GoASM?

peaslee

Quote from: E^cube on April 01, 2009, 10:25:50 PM
can I use the 32bit and 64bit version of your code in the SDK i'm releasing tonight for GoASM?

Sure.
Bruce Peaslee
"Reality is a crutch for those who can't do drugs."

donkey

Hi E^cube,

mov    Q[WinWidth], rax

The Q is not necessary since the size of the register is known. Doesn't hurt anything to leave it in though.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

MichaelW

One thing that I don't see in the procedure is code to set the cbSize member of the WINDOWINFO structure. Per the PSDK this is required. It seems to work OK under Windows 2000 without it, but it might not under all versions.
eschew obfuscation

ecube

Thanks Donkey,
I hope when I upload the sdk in a few hours you'll take a look at the sources, i'm sure I wrote/converted many things wrong :) even though i've tested everything it seems to run ok. Having .IF,.ELSEIF etc woulda made life a lot easier with some things but it's ok...