CRichEditCtrl如何知道已执行粘贴操作? [英] How does a CRichEditCtrl know a paste operation has been performed?

查看:315
本文介绍了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 )忽略控制中粘贴到的文本上的任何格式。通过获取不同剪贴板格式的剪贴板数据,或通过正常粘贴,并立即删除插入文本的格式。

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.

我试过的:

What I tried so far:


  1. 中检查WM_PASTE的邮件CMyRichEditCtrl :: PreTranslateMessage()

  2. 建立方法 virtual void CMyRichEditCtrl :: Paste()

  3. 上的断点在afxcmn.inl中的CRichEditCtrl :: Paste()

  4. 通过 CMyRichEditCtrl :: PreTranslateMessage()

  1. Checking the message for WM_PASTE in CMyRichEditCtrl::PreTranslateMessage()
  2. Creating a method virtual void CMyRichEditCtrl::Paste()
  3. Putting a breakpoint on CRichEditCtrl::Paste() in afxcmn.inl
  4. 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消息。 / p>

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
}

这篇关于CRichEditCtrl如何知道已执行粘贴操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆