Reputation: 23
Is there a notification code sent when the cursor position changes in an Edit Control MFC? I want to display the cursor (character) position for the user
Upvotes: 2
Views: 481
Reputation: 597051
There is no EN_...
notification sent by the Edit control itself when the caret position changes.
However, you can use SetWinEventHook()
to register for EVENT_OBJECT_LOCATIONCHANGE
notifications for your app's process ID and UI thread ID.
EVENT_OBJECT_LOCATIONCHANGE
0x800BAn object has changed location, shape, or size. The system sends this event for the following user interface elements: caret and window objects. Server applications send this event for their accessible objects.
You can then have your callback function filter the notifications by checking if the provided hwnd
is your Edit control and the provided idObject
is OBJID_CARET
.
OBJID_CARET
The text insertion bar (caret) in the window.
When detected, you can get the actual caret position by sending an EM_GETSEL
message to the Edit control.
Gets the starting and ending character positions (in TCHARs) of the current selection in an edit control.
Or, if you are using the CEdit
class, use its GetSel()
method.
Call this function to get the starting and ending character positions of the current selection (if any) in an edit control, using either the return value or the parameters.
Upvotes: 5