Edit Control MFC中光标位置变化时有通知码吗?
Is there a notification code when cursor position changes in Edit Control MFC?
Edit Control MFC中光标位置改变时是否发送通知码?我想为用户显示光标(字符)位置
当插入符号位置改变时,Edit 控件本身没有发送 EN_...
通知。
但是,您可以对应用的进程 ID 和 UI 线程 ID 使用 SetWinEventHook()
to register for EVENT_OBJECT_LOCATIONCHANGE
通知。
EVENT_OBJECT_LOCATIONCHANGE
0x800B
An 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.
然后您可以让回调函数通过检查提供的 hwnd
是否是您的编辑控件以及提供的 idObject
是否是 OBJID_CARET
来过滤通知。
OBJID_CARET
The text insertion bar (caret) in the window.
检测到后,您可以通过向编辑控件发送 EM_GETSEL
消息来获取实际插入符位置。
Gets the starting and ending character positions (in TCHARs) of the current selection in an edit control.
或者,如果您使用的是 CEdit
class, use its GetSel()
方法。
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.
Edit Control MFC中光标位置改变时是否发送通知码?我想为用户显示光标(字符)位置
当插入符号位置改变时,Edit 控件本身没有发送 EN_...
通知。
但是,您可以对应用的进程 ID 和 UI 线程 ID 使用 SetWinEventHook()
to register for EVENT_OBJECT_LOCATIONCHANGE
通知。
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.
然后您可以让回调函数通过检查提供的 hwnd
是否是您的编辑控件以及提供的 idObject
是否是 OBJID_CARET
来过滤通知。
OBJID_CARET
The text insertion bar (caret) in the window.
检测到后,您可以通过向编辑控件发送 EM_GETSEL
消息来获取实际插入符位置。
Gets the starting and ending character positions (in TCHARs) of the current selection in an edit control.
或者,如果您使用的是 CEdit
class, use its GetSel()
方法。
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.