Solved

How to find cursor or input position from screen?

Posted on 1998-08-10
5
230 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
ID: 1320505
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
ID: 1320506
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
ID: 1320507
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
ID: 1320508
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
ID: 1320509
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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