I created a window using 0 for the x and y and 2 constants for the width and height. But When I draw to the window it seams that the actual client area is smaller then the width and height values. I think windows dose this to account for different resolutions. How would I create a windows with a specific client area size?
Posted on 2002-05-04 16:45:49 by Kudos
If i follow you correctly,

    [*]Get Client Rect -> addr RCT
    [*]find width/heights ( delta x = right - left, delta y = bottom - top)
    [*]compare to desired width and height.
    [*]find the difference needed between the current and desired. (nx, ny)
    [*]GetWindowPos for cx, cy data
    [*]SetWindowPos with cx+nx, cy+nx

    This should resize the window such that the client area has a desired window area. (Kinda a work around approach, i admit, but its the best i can think of at the moment)

    Hope it helps.
Posted on 2002-05-04 16:53:00 by NaN
Thanx NaN that should do the trick
Posted on 2002-05-04 16:56:36 by Kudos

when you create a window using CreateWindowEx and constants for x,y you will get a *window* that is x units wide and y units high. This is slightly different than the client area. The client area is smaller because of the frame, menu bars, caption, etc.

If you want a Window with a certain client size look into AdjustWindowRect, which will calculate the window rectangle for a given client area.

What I usually do however is track the size of the client rectangle everytime the window is resized like so (I never call GetClientRect):

cmp eax,WM_SIZE

mov eax,lParam
mov edx,eax
and eax,0FFFFh
shr edx,16
mov ClientRectWidth,eax
mov ClientRectHeight,edx

Posted on 2002-05-04 17:04:15 by chorus

I like your approach, to reuse the info windows is handing you.

But have you concidered this?

movsx eax, WORD PTR lParam
mov ClientRectWidth,eax
movsx eax, WORD PTR (lParam + 4)
mov ClientRectHeight,eax

My general point is you need not do anything fancy to extract a work from a packed dword. I too generally store everything in a dword (just so I don't have to remember the size) (cause I'll forget!).

You can address the packed word directly where it is, and use movsx to extend the sign out to a dword.
Posted on 2002-05-04 19:16:27 by Ernie
Ernie, I like the lesson, cause im equally as bad ;)

But shouldnt it be (lParam + 2) (2 bytes == word )??

Posted on 2002-05-04 19:22:33 by NaN
I didn't think my method was fancy. Actually, it was the most straight-forward way of doing things :)

Furthermore, when I look at movsx vs mov/and I'm pretty sure my way is faster :) I'm sure it pairs better, and spares the extra uops on later processors of accessing the memory. Also, if you really wanted to be picky, you could replace movsx with movzx since the values aren't signed...

>>>Ernie, I like the lesson, cause im equally as bad

NaN, are you saying I'm a bad programmer? ;)

Posted on 2002-05-04 19:34:48 by chorus
Sorry poor choice of words...
Posted on 2002-05-04 20:05:17 by NaN
Ernies method is simpler & more straightforward (even though
I agree you should use movzx instead of movsx). I think it's
silly optimizing something like WM_SIZE for speed, and would
rather go for smaller & more straightforward code (your method
should be 24 bytes, ernies method should be 18 bytes).
Posted on 2002-05-05 06:51:23 by f0dder
f0dder, you're right. Ernie's method is the best choice in this instance. I hadn't compared the two for size, and as speed isn't an issue, it makes sense to use Ernie's way. To be honest, I hadn't coded it for speed - that's just how I move a packed dword whenever I see one. Pretty much any documentation I've seen has suggested to split up movzx, so I suppose I'm in the habit of doing it that way.

Thanks to both of you

Posted on 2002-05-05 12:43:29 by chorus