Solved

Getting window X

Posted on 2003-11-10
6
362 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
Comment Utility
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
Comment Utility
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
Comment Utility
CWnd::ScreenToClient()
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:nullmind
Comment Utility
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
Comment Utility
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
Comment Utility
Ok, it was an API call, I did not know this.

Thanks a million KurtVon!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now