How to get the window width (or height) ? Is GetWindowRect my only option ? Or are there other functions ?
Thanks in advance,
Jannes
You can try GetWindowInfo :
http://msdn.microsoft.com/en-us/library/ms633516%28VS.85%29.aspx
Thanks! I assume I would need the rcClient member of that WINDOWINFO structure ?
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.
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)
GetClientRect gets you the client area :t
the left and top members are always 0
so, right = width and bottom = height
Aha! Exactly what I was looking for :t
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.
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
.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
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
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.
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.
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??
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:
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.