Results 1 to 3 of 3

Thread: cursor position with respect to window client area

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Sterling Heights, MI, USA
    Posts
    11

    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?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Megatron
    Guest
    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
  •  



Click Here to Expand Forum to Full Width