?
Solved

How to find cursor or input position from screen?

Posted on 1998-08-10
5
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
psdavis earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

764 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