Getting window X

I have a button on a window, I wan't to get the buttons position based on the client-area.

For example, if I move my button to 16,16 using the MoveWindow command, how could I get that same position back?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

From Windows Help File
This function retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.

BOOL GetWindowRect( HWND hWnd, LPRECT lpRect );

hWnd - Handle to the window.
lpRect - Long pointer to a RECT structure that receives the screen coordinates of the upper-left and lower-right corners of the window.

Return Values
Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.

This is the function I used to get the positions of all the controls in my Dialog box. I used the information the scroll the controls around the dialog box.

Hope this helps. :)
nullmindAuthor Commented:
I've used GetWindowRect and GetClientRect, the problem is that it doesn't allow me to convert the positions.

GetWindowRect on a child control (eg; button), will return it's screen coords. The rect returned is the position of the parent window, and whatever else (Title bar, window borders.)

I wanted to know if there is an easy way to convert the screen coordinates to local client area of a window.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

nullmindAuthor Commented:
I'm not using MFC, is there a way I can convert that to normal API calls?
There is a Win32 equiviliant function:
The ScreenToClient function converts the screen coordinates of a specified point on the screen to client-area coordinates.

BOOL ScreenToClient(
  HWND hWnd,        // handle to window
  LPPOINT lpPoint   // screen coordinates

Have Fun!
nullmindAuthor Commented:
Ok, it was an API call, I did not know this.

Thanks a million KurtVon!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.