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. How to implement a WM_COPY handler for a CEdit derived control

How to implement a WM_COPY handler for a CEdit derived control

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
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
    madmax0001
    wrote on last edited by
    #1

    Hi, I have written a CEdit derived control for displaying formatted float values. Now I want to implement a handler for WM_COPY and WM_PASTE. The WM_COPY handler for e.g. must copy the unformatted(!) float value to the clipboard. I have tried something like BEGIN_MESSAGE_MAP(CMyNumberEdit, CEdit) ON_MESSAGE(WM_COPY, OnCopy) END_MESSAGE_MAP() ... but OnCopy is never called. Can anyone help me? THX

    D 1 Reply Last reply
    0
    • M madmax0001

      Hi, I have written a CEdit derived control for displaying formatted float values. Now I want to implement a handler for WM_COPY and WM_PASTE. The WM_COPY handler for e.g. must copy the unformatted(!) float value to the clipboard. I have tried something like BEGIN_MESSAGE_MAP(CMyNumberEdit, CEdit) ON_MESSAGE(WM_COPY, OnCopy) END_MESSAGE_MAP() ... but OnCopy is never called. Can anyone help me? THX

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      madmax0001 wrote:

      ON_MESSAGE(WM_COPY, OnCopy)

      Try:

      ON_COMMAND(WM_COPY, OnCopy)


      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

      "We will be known forever by the tracks we leave." - Native American Proverb

      M 1 Reply Last reply
      0
      • D David Crow

        madmax0001 wrote:

        ON_MESSAGE(WM_COPY, OnCopy)

        Try:

        ON_COMMAND(WM_COPY, OnCopy)


        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

        "We will be known forever by the tracks we leave." - Native American Proverb

        M Offline
        M Offline
        madmax0001
        wrote on last edited by
        #3

        Hi, I've tried but it is also never called.

        D 1 Reply Last reply
        0
        • M madmax0001

          Hi, I've tried but it is also never called.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Something else must be up. I used the following and both methods get called:

          BEGIN_MESSAGE_MAP(CEditEx, CEdit)
          //{{AFX_MSG_MAP(CEditEx)
          ON_MESSAGE(WM_COPY, OnCopy)
          //}}AFX_MSG_MAP
          END_MESSAGE_MAP()
          ...
          LRESULT CEditEx::OnCopy( WPARAM wParam, LPARAM lParam )
          {
          // handle it here
          return 0;
          }
          ...
          LRESULT CEditEx::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
          {
          if (WM_COPY == message)
          ; // or here

          return CEdit::WindowProc(message, wParam, lParam);
          

          }


          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

          "We will be known forever by the tracks we leave." - Native American Proverb

          M 1 Reply Last reply
          0
          • D David Crow

            Something else must be up. I used the following and both methods get called:

            BEGIN_MESSAGE_MAP(CEditEx, CEdit)
            //{{AFX_MSG_MAP(CEditEx)
            ON_MESSAGE(WM_COPY, OnCopy)
            //}}AFX_MSG_MAP
            END_MESSAGE_MAP()
            ...
            LRESULT CEditEx::OnCopy( WPARAM wParam, LPARAM lParam )
            {
            // handle it here
            return 0;
            }
            ...
            LRESULT CEditEx::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
            {
            if (WM_COPY == message)
            ; // or here

            return CEdit::WindowProc(message, wParam, lParam);
            

            }


            "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

            "We will be known forever by the tracks we leave." - Native American Proverb

            M Offline
            M Offline
            madmax0001
            wrote on last edited by
            #5

            Hi, thank you very much. You're right. I have found my problem. I had implemented a handler for WM_CHAR where my editbox content is formatted. To process WM_COPY commands I must call the base class procedure for WM_CHAR for nonprintable characters like this: void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if(isprint(nChar)==0){ CEdit::OnChar(nChar, nRepCnt, nFlags); return; } // Further processing here } Now the OnCopy implementation is called ! :-)

            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