How does CRichEditCtrl know the insert operation?

It has methods, such as CRichEditCtrl::Copy(), CRichEditCtrl::Paste()that you can call, but I can’t detect any messages that the dispatcher sends to Windows to perform the insert operation. Does anyone know if such a thing exists? Or CRichEditCtrldoes it perform something lower, for example, monitoring WM_CHAR events? If so, can I reuse any internal methods or would I just have to roll on my own to override the standard insert functions?

I really want my custom subclass ( CMyRichEditCtrl : CRichEditCtrl) to ignore any formatting of the text inserted into the control. Either getting the clipboard data in a different clipboard format, or pasting it as usual, and immediately removing the formatting from the pasted text.

What I have tried so far:

  • Checking messages for WM_PASTE in CMyRichEditCtrl::PreTranslateMessage()
  • Method creation virtual void CMyRichEditCtrl::Paste()
  • Setting a breakpoint on CRichEditCtrl::Paste()afxcmn.inl
  • Discard each message passing through CMyRichEditCtrl::PreTranslateMessage()

Results:

1: WM_PASTE message is not visible
2: It was never called 3: It never hit ... how?
4: The control never receives WM_COMMAND, WM_PASTE, or focus messages. Basically, only mouse-moving and keystroke messages .

, . , MFC - .

+3
5

EN_PROTECTED.

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
}
+1

Windows //. . WM_CUT.

, , WM_CHAR, , .

0

, , , WM_COMMAND ID_EDIT_PASTE . MFC CRichEditCtrl:: OnEditPaste(), Paste() .

, , - CRichEditCtrl, OnEditPaste

ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)

. , PreTranslateMessage WM_COMMAND wParam ID_EDIT_PASTE.

, ( ), OnEditPaste

void MyRichEdit::OnEditPaste()
{
  SendMessage(EM_PASTESPECIAL,CF_UNICODETEXT);
}

, , , .

, , , , . , WM_PASTE . . , , COM IRichEditOleCallback:: QueryAcceptData. : -)

0

ON_MESSAGE .

ON_MESSAGE (WM_PASTE, OnPaste)

LRESULT CMyRichEditCtrl:: OnPaste (WPARAM, LPARAM)

If you open the RichEdit.h file, you will notice that some of the messages are in the WM_USER range. Perhaps this is how MFC handles events for Rich Edit Control.

0
source

I need to execute as below

void MyRichEcit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{


if( ( GetKeyState(VK_CONTROL)<0 && nChar==88 ) || (nChar==VK_DELETE && GetKeyState(VK_SHIFT) < 0) ) //cut
    {

    }

if( ( GetKeyState(VK_CONTROL)<0 && nChar==86 ) || (nChar==VK_INSERT && GetKeyState(VK_SHIFT) < 0) ) //paste
    {

    }


    CWnd::OnKeyDown(nChar, nRepCnt, nFlags);    
}
0
source

Source: https://habr.com/ru/post/1732500/


All Articles