News:

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

Finding Client Position

Started by msmith, July 25, 2006, 07:06:20 PM

Previous topic - Next topic

msmith

Since GetWindowRect returns the window's origin referenced to the screen and GetClientRect returns 0,0, I have been doing a GetWindowRect for both the parent and child(window of interest) and then subtracting the position coordinates to get the origin of the child window within the parent.

Surely, there must be a function to do this directly, but I can't find it.

hutch--

You can have a look to see if ScreenToClient() and ClientToScreen() APIs will help you.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

msmith

Thanks Hutch,

ScreenToClient comes pretty close to doing what I want. I looked at all of my compiler sources and I used it 1 time to convert mouse position for screen to client.

If you do a GetWindowRect, set the POINT structure with rectleft and recttop, and then do a ScreenToClient, that should do the job.

It's too bad that GetClientRect doesn't do exactly that.

It turns out that GetClientRect is really a GetWindowSize function as it returns 0,0 for x,y and returns width for rectright and height for rectbottom.

Regards,

Mike

msmith

Quote
If you do a GetWindowRect, set the POINT structure with rectleft and recttop, and then do a ScreenToClient, that should do the job.

Actually, it's better than that because the POINT structure is the same as the first two dwords of the RECT structure, so you can do a GetWindowRect followed by a ScreenToClient using the same RECT structure for both. This means there is no need to set a POINT structure at all.

Shantanu Gadgil

This is a function I have written and use frequently as I work with dialogs quite a bit! :)

Hope you find it useful too!

GetControlRect proc hWinParent:HWND, hWinControl:HWND, lprcRectangle:DWORD
LOCAL ptLocalControl:POINT
LOCAL rcLocalControl:RECT

push eax
push ebx

invoke GetWindowRect,hWinControl,addr rcLocalControl
mov eax,rcLocalControl.right
sub eax,rcLocalControl.left
mov ebx,lprcRectangle
mov (RECT ptr [ebx]).right, eax ;WIDTH

mov eax,rcLocalControl.bottom
sub eax,rcLocalControl.top
mov ebx,lprcRectangle
mov (RECT ptr [ebx]).bottom, eax ;HEIGHT

push rcLocalControl.left
pop ptLocalControl.x
push rcLocalControl.top
pop ptLocalControl.y

invoke ScreenToClient,hWinParent,addr ptLocalControl

mov ebx,lprcRectangle
mov eax,ptLocalControl.x
mov (RECT ptr [ebx]).left, eax

mov eax,ptLocalControl.y
mov ebx,lprcRectangle
mov (RECT ptr [ebx]).top, eax

pop ebx
pop eax
ret
GetControlRect endp


Cheers,
Shantanu
To ret is human, to jmp divine!

ToutEnMasm


Hello,
a word on the struct RECT,she is very badly defined.
RECT STRUCT
  left    dd      ?
  top     dd      ?
  right   dd      ?
  bottom  dd      ?
RECT ENDS
If you can extract  a lenght of this without the help of winhelp,you are very strong

I have re-defined it like that.
   FRECT   STRUCT
      min POINT <>
      max POINT <>
   FRECT ENDS
and now you can write,

           rect FRECT <>
           width = rect.max.x -rect.min.x
           height = rect.max.y -rect.min.y
no need of winhelp to understand a basic operation