• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1273
  • Last Modified:

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.
0
MrNed
Asked:
MrNed
  • 5
  • 4
  • 2
1 Solution
 
nonubikCommented:
Try to intercept the WM_PASTE mesasge for your rich edit control wndproc.
0
 
MrNedAuthor Commented:
Ive tried both of these without success:

ON_CONTROL_REFLECT(WM_PASTE, OnPaste)

ON_MESSAGE(WM_PASTE, OnPaste)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
nonubikCommented:
>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.
0
 
gecko_au2003Commented:
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
0
 
MrNedAuthor Commented:
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?
0
 
nonubikCommented:
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);
}
0
 
MrNedAuthor Commented:
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?
0
 
nonubikCommented:
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.
0
 
MrNedAuthor Commented:
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)?
0
 
nonubikCommented:
>So to answer my original question are you saying that I can't capture the mythical paste message
So it seems.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now