Search code examples
visual-c++mfcwin32guimfc-feature-pack

Copy shortcut operation with CRichEditCtrl in MFC


I am very new to MFC. I am having following code for Copy and SelectAll shortcuts for CRichEditCtrl object.

ON_COMMAND(ID_EDIT_COPY, OnCopy)
ON_COMMAND(ID_EDIT_SELECT_ALL, OnSelectAll)

But I am not able to catch breakpoint for Copy (Ctrl+C) and SelectAll (Ctrl+A) in the functions which I wrote here as It is not getting executed.

Here CRichEditCtrl object is read only(Text is for read and not allowed to modified).

I also want to provide functionality of Text Selection with Mouse for CRichEditCtrl object.

Any idea on How to achieve this?


Solution

  • This actions are not executed with a WM_COMMAND value we know. Also the keystrokes are checked internally and handled internally.

    Internally there are special window messages named WM_COPY and WM_PASTE for some actions that interact with the clipboard.

    Afaik the selection (Select all) is done completely internal. you can try to subclass the RTF control and intercept the EM_SETSEL message.

    If you want to intercept the keystrokes you can use PreTranslateMessage or you can again subclass the RTF control.