Solved

Getting window X

Posted on 2003-11-10
6
363 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modify static variables within a class in VC++ 3 95
Getting IP address 8 71
What is sub-make ? 2 39
object oriented programming comparison 5 55
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

920 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

17 Experts available now in Live!

Get 1:1 Help Now