Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Is there a "OnPaste(...)" - a CRichEdit question!

Is there a "OnPaste(...)" - a CRichEdit question!

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael Pauli
    wrote on last edited by
    #1

    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. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>

    R 2 Replies Last reply
    0
    • M Michael Pauli

      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. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      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 class CMyRichEditCtrl derived from CRichEditCtrl. Create your RichEditCtrl in the resource editor, and assign it a control member : m_MyRichEdt Go into the automatically generated code, and replace

      CRichEditCtrl 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 > 1000

      Now 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();

      1 Reply Last reply
      0
      • M Michael Pauli

        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. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>

        R Offline
        R Offline
        Rage
        wrote on last edited by
        #3

        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();

        M 2 Replies Last reply
        0
        • R 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();

          M Offline
          M Offline
          Michael Pauli
          wrote on last edited by
          #4

          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. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>

          1 Reply Last reply
          0
          • R 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();

            M Offline
            M Offline
            Michael Pauli
            wrote on last edited by
            #5

            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. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups