|
-
Jul 16th, 2001, 07:44 AM
#1
Thread Starter
New Member
cursor position with respect to window client area
Hi,
I was wondering how I might get the mouse cursor position with respect to the upper left corner of the window client area (not the whole window). More specifically, I want the dimensions and position of the client area's device context. I was originally thinking of using GetWindowRect and GetCursorPosition, then subtracting the title bar height. Then I thought about those ridiculously large title bars, so that shoots a hole in my plan. Can anyone help me out?
-
Jul 17th, 2001, 05:14 AM
#2
Frenzied Member
You can use the GetClientRect API
GetClientRect
The GetClientRect function retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0).
BOOL GetClientRect(
HWND hWnd, // handle to window
LPRECT lpRect // address of structure for client coordinates
);
Parameters
hWnd
Handle to the window whose client coordinates are to be retrieved.
lpRect
Pointer to aRECT structure that receives the client coordinates. The left and top members are zero. The right and bottom members contain the width and height of the window.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, callGetLastError.
Last edited by Vlatko; Jul 17th, 2001 at 05:17 AM.
-
Jul 17th, 2001, 09:35 AM
#3
Use GetCursorPos() to get the mouse coordinates relative to the screen, and convert them to client coordinates via the ScreenToClient() function.
Code:
POINT pt;
GetCursorPos(&pt);
ScreenToClient(hWnd, &pt);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|