Solved

Getting window X

Posted on 2003-11-10
6
367 Views
Last Modified: 2010-04-01
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?

Cheers!
0
Comment
Question by:nullmind
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:cindy_k
ID: 9717827
From Windows Help File
===========================================
GetWindowRect
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 );
Parameters

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.

Remarks
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. :)
Cynthia
0
 
LVL 1

Author Comment

by:nullmind
ID: 9718072
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.

Cheers!
0
 
LVL 11

Accepted Solution

by:
KurtVon earned 50 total points
ID: 9718302
CWnd::ScreenToClient()
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:nullmind
ID: 9718557
I'm not using MFC, is there a way I can convert that to normal API calls?
0
 
LVL 3

Expert Comment

by:cindy_k
ID: 9718582
There is a Win32 equiviliant function:
ScreenToClient
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
);

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/cordspac_5oxg.asp

Have Fun!
Cynthia
0
 
LVL 1

Author Comment

by:nullmind
ID: 9718592
Ok, it was an API call, I did not know this.

Thanks a million KurtVon!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question