gpt4 book ai didi

c++ - Edit Control MFC中光标位置变化时有通知码吗?

转载 作者:可可西里 更新时间:2023-11-01 09:50:24 24 4
gpt4 key购买 nike

当光标位置在Edit Control MFC中发生变化时是否发送通知代码?我想为用户显示光标(字符)位置

最佳答案

没有 EN_...当插入符位置发生变化时,Edit 控件本身发送的通知。

但是,您可以使用 SetWinEventHook()注册EVENT_OBJECT_LOCATIONCHANGE应用进程 ID 和 UI 线程 ID 的通知。

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类,使用它的 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.

关于c++ - Edit Control MFC中光标位置变化时有通知码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58017559/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com