The MASM Forum

General => The Campus => Topic started by: gelatine1 on June 29, 2014, 03:46:08 AM

Title: window width
Post by: gelatine1 on June 29, 2014, 03:46:08 AM
How to get the window width (or height) ? Is GetWindowRect my only option ? Or are there other functions ?

Thanks in advance,
Jannes
Title: Re: window width
Post by: Vortex on June 29, 2014, 04:20:05 AM
You can try GetWindowInfo :

http://msdn.microsoft.com/en-us/library/ms633516%28VS.85%29.aspx
Title: Re: window width
Post by: gelatine1 on June 29, 2014, 04:30:04 AM
Thanks! I assume I would need the rcClient member of that WINDOWINFO structure ?
Title: Re: window width
Post by: Vortex on June 29, 2014, 04:37:09 AM
Yes. You can also the check the members of the same structure :

QuotecxWindowBorders

    Type: UINT

    The width of the window border, in pixels.

cyWindowBorders

    Type: UINT

    The height of the window border, in pixels.
Title: Re: window width
Post by: gelatine1 on June 29, 2014, 04:41:31 AM
Quote from: Vortex on June 29, 2014, 04:37:09 AM
Yes. You can also the check the members of the same structure :

QuotecxWindowBorders

    Type: UINT

    The width of the window border, in pixels.

cyWindowBorders

    Type: UINT

    The height of the window border, in pixels.

Oh I thought those were the width and height of the actual borders ? (I guess something like 10px)
Title: Re: window width
Post by: dedndave on June 29, 2014, 05:39:04 AM
GetClientRect gets you the client area   :t
the left and top members are always 0
so, right = width and bottom = height
Title: Re: window width
Post by: gelatine1 on June 29, 2014, 07:09:22 AM
Aha! Exactly what I was looking for  :t
Title: Re: window width
Post by: Tedd on June 29, 2014, 10:51:46 PM
You will receive a WM_SIZE message each time the window size changes and when the window is created -- the width and height provided are the new client area size.
Save these values, and use them whenever you need the client area size.
Title: Re: window width
Post by: dedndave on June 30, 2014, 03:06:04 AM
i often do it the way Tedd suggests
it takes a little filtering, though - so you don't get the minimized numbers, etc

however, GetClientRect is one of the faster API functions   :P
Title: Re: window width
Post by: dedndave on June 30, 2014, 03:27:54 AM
    .DATA?

rcClient RECT <>


then, in WndProc...

    .elseif eax==WM_SIZE
        .if !(wParam&(NOT SIZE_MAXIMIZED))
            movzx   edx,word ptr lParam+2   ;EDX = client height
            movzx   ecx,word ptr lParam     ;ECX = client width
            mov     rcClient.bottom,edx
            mov     rcClient.right,ecx
        .endif
        xor     eax,eax


for WM_SIZE, wParam can be one of 5 values:

SIZE_RESTORED  EQU 0
SIZE_MINIMIZED EQU 1
SIZE_MAXIMIZED EQU 2
SIZE_MAXSHOW   EQU 3
SIZE_MAXHIDE   EQU 4


(NOT SIZE_MAXIMIZED) = 0FFFFFFFDh
so, the code above updates the RECT if wParam = SIZE_RESTORED or if wParam = SIZE_MAXIMIZED

        .if !(wParam&(NOT SIZE_MAXIMIZED))
notice the "!" - that means .if not(.....) (logical NOT)
the "&" ampersand is bitwise AND
Title: Re: window width
Post by: dedndave on June 30, 2014, 03:40:14 AM
you could write that code so it also updates when minimized
but, your paint code should to be smart enough to know that a negative height value means minimized
i suppose that windows won't send any WM_PAINT messages when the window is minimized
but, it would be a crash if it did because a negative height value looks like a very large unsigned value

EDIT: come to think of it, it must be ok
we use GetClientRect in WM_PAINT - it returns a negative height when the window is minimiized

must be a guarantee that no WM_PAINT messages are sent when minimized
haven't seen that documented, but it makes sense
Title: Re: window width
Post by: jj2007 on June 30, 2014, 03:50:12 AM
Quote from: dedndave on June 30, 2014, 03:40:14 AM
but, your paint code should to be smart enough to know that a negative height value means minimized

IsIconic is another way to check, but negative height would be shorter.
Title: Re: window width
Post by: Tedd on July 02, 2014, 02:10:08 AM
WM_PAINT isn't sent periodically, you will only receive it when there are invalidated regions that need repainting AND your message queue is empty (if there is any other message, you will receive that instead.)
If your window is not visible, you will not receive WM_PAINT (there's nothing to paint!) Equally, if your window is minimized, it's no longer visible.
So there's no need to check for the window's status, just take the width and height from WM_SIZE as-is.
Unless you happen to be doing something else periodically that relies on the window size; but then you should take the status into account and consider not doing it when the window isn't visible, since you'll only have to redo it with the 'new' size once it becomes visible again.
Title: Re: window width
Post by: jj2007 on July 02, 2014, 03:44:38 AM
Quote from: Tedd on July 02, 2014, 02:10:08 AM
If your window is not visible, you will not receive WM_PAINT (there's nothing to paint!) Equally, if your window is minimized, it's no longer visible.

You can get some messages in minimised state, mainly (when right-clicking)
WM_MENUSELECT
WM_CAPTURECHANGED
WM_UNINITMENUPOPUP
WM_MENUSELECT
WM_EXITMENULOOP
WM_NCACTIVATE
WM_GETTEXT
WM_ACTIVATE

but indeed, WM_PAINT is not among them. So I wonder where this notion of negative height came from??
Title: Re: window width
Post by: dedndave on July 02, 2014, 03:53:53 AM
what i was saying is, i haven't seen it documented that way
of course, it makes sense that you would not receive WM_PAINT when minimized

as for the negative height,
try GetWindowRect when minimized   :biggrin:
and, subtract bottom-top

EDIT: hmmm - never tried to see what happens when you InvalidateRect when minimized
i wonder if the update region is null ?   :redface:
Title: Re: window width
Post by: Tedd on July 02, 2014, 08:27:43 AM
Quote from: dedndave on July 02, 2014, 03:53:53 AM
EDIT: hmmm - never tried to see what happens when you InvalidateRect when minimized
i wonder if the update region is null ?   :redface:
Either the invalidated rectangle will be added to the update region, or it won't.
But it makes no actual difference -- the entire window has to be updated once the window is restored, completely replacing any previous update region; and you won't receive WM_PAINT to redraw it until it's restored.