[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

How to find cursor or input position from screen?

Hello,

I have a CForm view and  a bunch of CEdits.  I want to do some specific functions with the scrolling.  What my problem is that I can't get the location of the cursor.  I'm not talking about the cursor for the mouse but the cursor of the input (the little blinking vertical bar).  Can anyone help?

thanks
0
draw
Asked:
draw
  • 3
  • 2
1 Solution
 
psdavisCommented:
CWnd::GetCaretPos
static CPoint PASCAL GetCaretPos( );

Return Value

CPoint object containing the coordinates of the caret's position.

Remarks

Retrieves the client coordinates of the caret's current position and returns them as a CPoint.

The caret position is given in the client coordinates of the CWnd window.

Phillip

0
 
drawAuthor Commented:
Hello,

I think I addressed the problem wrong.  I apologize, but what I meant to say is that I want the coordinates of the keyborad cursor relative to the parent window.  Lets say if you wanted to find the coordinates for the mouse cursor you would use the CPoint values from OnMouseMove(...)  But now I want the cursor for the keyboard.  Any help would be appreciated.

thanks
draw
0
 
psdavisCommented:
There's a problem with the nomenclature that you're using.  The cursor is the arrow, the caret is the "little blinking vertical bar" that you referred to.  GetCaretPos will give you that vertical bar's position.

The caret position is given in the client coordinates of the CWnd window.  You can then convert the client coordinates using ClientToScreen.

ClientToScreen converts the client coordinates of a given point or rectangle on the display to screen coordinates. The ClientToScreen member function uses the client coordinates in the POINT or RECT structure or the CPoint or CRect object pointed to by lpPoint or lpRect to compute new screen coordinates; it then replaces the coordinates in the structure with the new coordinates. The new screen coordinates are relative to the upper-left corner of the system display.

Hope this clarifies.

Phillip


Now if you want to convert the points relative to the parent window, then you can convert them using
0
 
drawAuthor Commented:
Hello,

What happens is that GetCaretPos only finds the position of the caret within the "selection" (CEdit control).  Is there any way to figure out the (x,y) position of the selection on the client screen?

thanks
draw
0
 
psdavisCommented:
Get the CWnd of the CEdit control

CEdit* pEdit = (CEdit*) GetDlgItem( IDC_WHATEVER );

// Get the caret position

CPoint ptCaret;
pEdit->GetCaretPos( &ptCaret );

// Now convert the point from the client position to the window position..

pEdit->ClientToScreen( &ptCaret );

// That's all.  You may have to play with the ClientToScreen, ScreenToClient, or the MapWindowPoints to get it into the specific coordinates that you're looking for.

Phillip
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now