Solved

How to find cursor or input position from screen?

Posted on 1998-08-10
5
224 Views
Last Modified: 2013-11-20
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
Comment
Question by:draw
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
psdavis earned 50 total points
Comment Utility
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
 

Author Comment

by:draw
Comment Utility
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
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
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
 

Author Comment

by:draw
Comment Utility
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
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

11 Experts available now in Live!

Get 1:1 Help Now