MrNed
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.
Try to intercept the WM_PASTE mesasge for your rich edit control wndproc.
ASKER
Ive tried both of these without success:
ON_CONTROL_REFLECT(WM_PAST E, OnPaste)
ON_MESSAGE(WM_PASTE, OnPaste)
ON_CONTROL_REFLECT(WM_PAST
ON_MESSAGE(WM_PASTE, OnPaste)
https://secure.codeproject.com/editctrl/FilterEdit.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cricheditctrl.3a3a.paste.asp
https://www.experts-exchange.com/questions/10217404/Turning-off-text-selection-in-CRichEditCtrl.html
http://www.codeguru.com/forum/showthread.php?t=283543
The above is items related to what you are looking for as far as I am aware !
I hope it helps !
Kind regards
gecko
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cricheditctrl.3a3a.paste.asp
https://www.experts-exchange.com/questions/10217404/Turning-off-text-selection-in-CRichEditCtrl.html
http://www.codeguru.com/forum/showthread.php?t=283543
The above is items related to what you are looking for as far as I am aware !
I hope it helps !
Kind regards
gecko
>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.
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
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
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?
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::PreTranslateMe ssage(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::PreTranslateMessa ge(pMsg);
}
BOOL CfolderDlg::PreTranslateMe
{
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::PreTranslateMessa
}
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.
> 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.
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)?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.