Solved

How to find cursor or input position from screen?

Posted on 1998-08-10
5
234 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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