Link to home
Start Free TrialLog in
Avatar of MrNed
MrNedFlag for Australia

asked on

CRichEditCtrl - Capturing paste

Im trying to provide syntax highlighting in a rich edit control. So far it works fine for any normal typing, but when the user pastes text from a different application in the control, it retains the formatting from that application. I want to be able to capture the paste message so I can format it my way before it gets into the control, but I cant find any way of doing it.
Avatar of nonubik
nonubik

Try to intercept the WM_PASTE mesasge for your rich edit control wndproc.
Avatar of MrNed

ASKER

Ive tried both of these without success:

ON_CONTROL_REFLECT(WM_PASTE, OnPaste)

ON_MESSAGE(WM_PASTE, OnPaste)
>Ive tried both of these without success:

Where did you write the handler? WM_PASTE need to be in the riche edit' class.
If you put them in the edit's parent (e.g. a dialog), you can overwrite the PreTranslateMessage method and catch there the WM_COPY message.
I didn't write any handler, I just found them URL's with regards to this Q and thought that they would prove useful in some shape or form to you :) and so hence I posted them. I am sorry that I can not be of more use to you !!

However If I find anything else with regards to this, then I will make further posts !

Other then that hopefully other experts reply to this thread to help you out !

Kind regards

Gecko
Avatar of MrNed

ASKER

None of those links have helped. I have derived my own class from CRichEditCtrl and overridden WindowProc but it never sees the WM_PASTE message. I also tried it in the parent dialog but it also never saw WM_PASTE. I also tried overriding PreTranslateMessage but it never sees WM_PASTE either.

Do I need to do something to enable it in the first place?
I tried Spy++ and found out that only CTRL and V keys are sent to the window

BOOL CfolderDlg::PreTranslateMessage(MSG* pMsg)
{
      if(pMsg->hwnd == m_Rich.m_hWnd)
      {
            if(pMsg->message == WM_KEYDOWN)
            {
                  switch(pMsg->wParam)
                  {
                  case VK_CONTROL:
                        m_bCtrlDown = TRUE;
                        break;
                  case 'V':
                        if(m_bCtrlDown)
                              ;//here we have ctrl+V
                        break;
                  }
            }
            if(pMsg->message == WM_KEYUP && pMsg->wParam == VK_CONTROL)
                  m_bCtrlDown = FALSE;
      }

      return CDialog::PreTranslateMessage(pMsg);
}
Avatar of MrNed

ASKER

I can capture keystrokes no problem, but isnt there a way to capture the actual PASTE message? What if the user pastes via other a menu or toolbar button?
As far as I can figure out, the WM_PASTE message is sent by application to copy the current content of the clipboard, so is up to the application if it sends WM_PASTE or not.

> What if the user pastes via other a menu or toolbar button?
If it's your application, then you know when user use them and can handle.
Avatar of MrNed

ASKER

I certainly dont send the WM_PASTE message myself, and neither does anything else cause I cant catch it anywhere. Yet, the control still pastes stuff.

So to answer my original question are you saying that I can't capture the mythical paste message, I have to handle all the different ways that text could get into the control (ie menu, toolbar, ctrl+v, etc)?
ASKER CERTIFIED SOLUTION
Avatar of nonubik
nonubik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial