News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

window width

Started by gelatine1, June 29, 2014, 03:46:08 AM

Previous topic - Next topic

gelatine1

How to get the window width (or height) ? Is GetWindowRect my only option ? Or are there other functions ?

Thanks in advance,
Jannes

Vortex

You can try GetWindowInfo :

http://msdn.microsoft.com/en-us/library/ms633516%28VS.85%29.aspx

gelatine1

Thanks! I assume I would need the rcClient member of that WINDOWINFO structure ?

Vortex

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.

gelatine1

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)

dedndave

GetClientRect gets you the client area   :t
the left and top members are always 0
so, right = width and bottom = height

gelatine1

Aha! Exactly what I was looking for  :t

Tedd

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.
Potato2

dedndave

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

dedndave

    .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

dedndave

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

jj2007

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.

Tedd

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.
Potato2

jj2007

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??

dedndave

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: