Solved

Getting window X

Posted on 2003-11-10
6
365 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

775 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