[英]Is there a notification code when cursor position changes in Edit Control MFC?
Is there a notification code sent when the cursor position changes in an Edit Control MFC?编辑控件 MFC 中的 cursor position 更改时是否发送通知代码? I want to display the cursor (character) position for the user
我想为用户显示 cursor(字符)position
There is no EN_...
notification sent by the Edit control itself when the caret position changes.当插入符号 position 更改时,Edit 控件本身不会发送
EN_...
通知。
However, you can use SetWinEventHook()
to register for EVENT_OBJECT_LOCATIONCHANGE
notifications for your app's process ID and UI thread ID.但是,您可以使用
SetWinEventHook()
为您的应用的进程 ID 和 UI 线程 ID 注册EVENT_OBJECT_LOCATIONCHANGE
通知。
EVENT_OBJECT_LOCATIONCHANGE
EVENT_OBJECT_LOCATIONCHANGE
0x800B0x800B
An object has changed location, shape, or size.
object 已更改位置、形状或大小。 The system sends this event for the following user interface elements: caret and window objects.
系统为以下用户界面元素发送此事件:插入符号和 window 对象。 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
.然后,您可以让您的回调 function 通过检查提供的
hwnd
是您的 Edit 控件并且提供的idObject
是OBJID_CARET
来过滤通知。
OBJID_CARET
OBJID_CARET
The text insertion bar (caret) in the window.
window 中的文本插入栏(插入符号)。
When detected, you can get the actual caret position by sending an EM_GETSEL
message to the Edit control.检测到后,您可以通过向 Edit 控件发送
EM_GETSEL
消息来获取实际的插入符号 position。
Gets the starting and ending character positions (in TCHARs) of the current selection in an edit control.
获取编辑控件中当前选择的开始和结束字符位置(以 TCHAR 为单位)。
Or, if you are using the CEdit
class, use its GetSel()
method.或者,如果您使用的是
CEdit
class,请使用其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.
调用此 function 以使用返回值或参数获取编辑控件中当前选择(如果有)的开始和结束字符位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.