CRichEditCtrl 如何知道已执行粘贴操作?
它有诸如 CRichEditCtrl::Copy()
、CRichEditCtrl::Paste()
之类的方法,您可以调用它们,但我看不到控件的任何消息由 Windows 发送,告诉它执行粘贴操作.有谁知道这样的事情是否存在?还是 CRichEditCtrl
做一些较低级别的事情,比如监控 WM_CHAR 事件?如果是这样,我可以重复使用任何内部方法,还是只需要滚动自己的方法来覆盖标准粘贴功能?
It has methods like CRichEditCtrl::Copy()
, CRichEditCtrl::Paste()
which you can call, but I can't spot any messages the control is sent by Windows telling it to perform a paste operation. Does anyone know if such a thing exists? Or does CRichEditCtrl
do something lower-level like monitoring WM_CHAR events? If so can I reuse any internal methods or would I just have to roll my own in order to override the standard paste functionality?
我真正想要的是让我的自定义子类 (CMyRichEditCtrl : CRichEditCtrl
) 忽略粘贴 in 到控件的文本上的任何格式.要么以不同的剪贴板格式获取剪贴板数据,要么将其正常粘贴并立即删除插入文本的格式.
What I actually want is for my custom subclass (CMyRichEditCtrl : CRichEditCtrl
) to ignore any formatting on text pasted in to the control. Either by getting the clipboard data in a different clipboard format, or by pasting it in as normal and immediately removing formatting on inserted text.
到目前为止我尝试了什么:
- 在
CMyRichEditCtrl::PreTranslateMessage()
中检查 WM_PASTE 的消息 - 创建方法
virtual void CMyRichEditCtrl::Paste()
- 在 afxcmn.inl 中的
CRichEditCtrl::Paste()
上放置断点 - 转储每条通过
CMyRichEditCtrl::PreTranslateMessage()
的消息
- Checking the message for WM_PASTE in
CMyRichEditCtrl::PreTranslateMessage()
- Creating a method
virtual void CMyRichEditCtrl::Paste()
- Putting a breakpoint on
CRichEditCtrl::Paste()
in afxcmn.inl - Dumping every message passing through
CMyRichEditCtrl::PreTranslateMessage()
结果:
1:没有看到 WM_PASTE 消息
2:它从来没有被调用过
3:它从来没有被击中...怎么样?
4:控件从不接收任何 WM_COMMAND、WM_PASTE 或焦点相关的消息.基本上只有鼠标移动和按键消息.
1: No WM_PASTE message seen
2: It's never called
3: It's never hit... how?
4: The control never receives any WM_COMMAND, WM_PASTE or focus-related messages. Basically only mouse-move and key-press messages.
似乎其他人实际上已经成功地做到了这一点.我想知道我的 MFC 版本或其他东西是否会搞砸,此时.
It seems other people have actually done this successfully. I'm wondering if my MFC version or something could be screwing it up, at this point.
推荐答案
处理 EN_PROTECTED 消息.
Handle EN_PROTECTED message.
ON_NOTIFY_REFLECT(EN_PROTECTED, &YourClass::OnProtected)
// call this from the parent class
void YourClass::Initialize()
{
CHARFORMAT format = { sizeof(CHARFORMAT) };
format.dwEffects = CFE_PROTECTED;
format.dwMask = CFM_PROTECTED;
SetDefaultCharFormat(format);
SetEventMask(ENM_PROTECTED);
}
void YourClass::OnProtected(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
ENPROTECTED* pEP = (ENPROTECTED*)pNMHDR;
if (pEP->msg == WM_PASTE)
pResult = 1; // prevent paste
}
相关文章