Is there a "OnPaste(...)" - a CRichEdit question!
-
I have a rich-edit where I only want to support *one* font (Tahoma 10pt. etc.) set up at time of constructing of the edit. This works fine when writing in it. But how do I force a text into this specific font and look when *pasted* in - from some other size and font? Think it's something about monitoring the clipboard format but I'm not sure? It makes sense to have a OnPaste() not calling the base impl. and then do the paste-work myself adding my format to it before it goes in - but no such are found anywhere!? As far as I can see in CWnd I have: ChangeClipboardChain(...) SetClipboardViewer(...) OpenClipboard(...) GetClipboardOwner(...) GetOpenClipboardWindow(...) GetClipboardViewer(...) and in CRichEdit: Copy(...) Cut(...) Paste(...) PasteSpecial(...) CanPaste(...) I'm a little puzzled here? Regards, Michael Mogensen, mm it-consult dk. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
-
I have a rich-edit where I only want to support *one* font (Tahoma 10pt. etc.) set up at time of constructing of the edit. This works fine when writing in it. But how do I force a text into this specific font and look when *pasted* in - from some other size and font? Think it's something about monitoring the clipboard format but I'm not sure? It makes sense to have a OnPaste() not calling the base impl. and then do the paste-work myself adding my format to it before it goes in - but no such are found anywhere!? As far as I can see in CWnd I have: ChangeClipboardChain(...) SetClipboardViewer(...) OpenClipboard(...) GetClipboardOwner(...) GetOpenClipboardWindow(...) GetClipboardViewer(...) and in CRichEdit: Copy(...) Cut(...) Paste(...) PasteSpecial(...) CanPaste(...) I'm a little puzzled here? Regards, Michael Mogensen, mm it-consult dk. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
First, I am sorry, because I adviced yesterday to do so, and I did not answer your second post. :-OThere is actually no
OnPaste()
routine, do it that way : Create a classCMyRichEditCtrl
derived fromCRichEditCtrl
. Create your RichEditCtrl in the resource editor, and assign it a control member :m_MyRichEdt
Go into the automatically generated code, and replaceCRichEditCtrl m_MyRichEdt;
with
CMyRichEditCtrl m_MyRichEdt;
Do not forget to add an #include "MyRichEditCtrl.h" in that same file after
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000Now override PreTranslatemessage like that : B
OOL CMyRichEditCtrl::PreTranslateMessage(MSG* pMsg)
{if ((pMsg->message == WM\_PASTE)) { Change font ... } else return CRichEditCtrl::PreTranslateMessage(pMsg);
}
Hope this helps. ~RaGE();
-
I have a rich-edit where I only want to support *one* font (Tahoma 10pt. etc.) set up at time of constructing of the edit. This works fine when writing in it. But how do I force a text into this specific font and look when *pasted* in - from some other size and font? Think it's something about monitoring the clipboard format but I'm not sure? It makes sense to have a OnPaste() not calling the base impl. and then do the paste-work myself adding my format to it before it goes in - but no such are found anywhere!? As far as I can see in CWnd I have: ChangeClipboardChain(...) SetClipboardViewer(...) OpenClipboard(...) GetClipboardOwner(...) GetOpenClipboardWindow(...) GetClipboardViewer(...) and in CRichEdit: Copy(...) Cut(...) Paste(...) PasteSpecial(...) CanPaste(...) I'm a little puzzled here? Regards, Michael Mogensen, mm it-consult dk. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
After few testing (sorry, no time today :( ), my code snippet lacks one or two things : First, if (message == WM_PASTE) is not really good, since it can be that several messages are contained in one message. So prefer something like if ((message & WM_PASTE)==0) return ... else paste font; Secondly, I think you will have to remove the WM_PASTE from the message queue, otherwise, the clipboard contents will be paste (it passes ans passes over again in PreTranslateMessage(). ~RaGE();
-
After few testing (sorry, no time today :( ), my code snippet lacks one or two things : First, if (message == WM_PASTE) is not really good, since it can be that several messages are contained in one message. So prefer something like if ((message & WM_PASTE)==0) return ... else paste font; Secondly, I think you will have to remove the WM_PASTE from the message queue, otherwise, the clipboard contents will be paste (it passes ans passes over again in PreTranslateMessage(). ~RaGE();
OK thanx' - this is a new approch and I understand what you are saying. I'll check it out soon. Only my feeling now is that this solution seems kind of "emergency exit" and a little primitive as well - there *must* be a better way. Not complaining or anything - :~ Regards, Michael Mogensen, mm it-consult dk. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
-
After few testing (sorry, no time today :( ), my code snippet lacks one or two things : First, if (message == WM_PASTE) is not really good, since it can be that several messages are contained in one message. So prefer something like if ((message & WM_PASTE)==0) return ... else paste font; Secondly, I think you will have to remove the WM_PASTE from the message queue, otherwise, the clipboard contents will be paste (it passes ans passes over again in PreTranslateMessage(). ~RaGE();
Thanx' sharing the ideas! But I found another way around my CHARFORMAT-problem than using the PreTranslateMessage(...) - here it is. What I did was that I made the CHARFORMAT-change to the full selection in response to *not* an UPDATE event but a CHANGE ev. As it turned out an update-ev. came over and over again if I did the work on EN_UPDATE - ON_CHANGE was less sensitive. So this is how the final solution looks:
const void CCalFrameWnd::CCalendar::Note_EditChange() // Called from parent to signal that user are editing a note. { TRACE(_T("Note_EditChange()\n")); // Ensure usage of one charformat only. long lChar_Start = 0, lChar_End = 0; CHARFORMAT cf_def; cf_def.cbSize = sizeof(CHARFORMAT); m_pEdit_Note->GetDefaultCharFormat(cf_def); m_pEdit_Note->GetSel(lChar_Start, lChar_End); m_pEdit_Note->HideSelection(TRUE, FALSE); m_pEdit_Note->SetSel(0, -1); m_pEdit_Note->SetSelectionCharFormat(cf_def); m_pEdit_Note->SetSel(lChar_End, lChar_End); m_pEdit_Note->HideSelection(FALSE, FALSE); }
So I just force the def-CHARFORMAT on to the entire selection having always set the def-format first. Also I remember to be able to restore to the orig. caret pos. Btw. Can one make a "ON_EN_REFLECT_CHANGE" for a edit/rich edit - work like this should be held totally inside the class as far as I can se. Regards, Michael Mogensen, mm it-consult dk. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>