Disabling copy in Edit ctrl

I have an app with a read-only CEdit ctrl. I want to prevent its contents from being copied to the clipboard either by Ctrl-C or the context menu, but I havent been able to find the correct message to trap on in PreTranslateMessage. Any clues?
Who is Participating?
CriusConnect With a Mentor Commented:
The edit control is the one that gets the WM_COPY, so you can't override WM_COPY in the dialog. Overriding ID_EDIT_COPY in the dialog will get rid of the ctrl-C copy, but it won't prevent them from right clicking the control and copying that way.

To prevent copying completely, you'll want to derive your own CEditCtrl from CEdit.

Once you do this, you can more easily just add a message handler for ID_EDIT_COPY and in it don't do anything.
You should achieve the behaivour you want by filtering out "WM_COPY" messages...
GrailmanAuthor Commented:
I tried to filter on WM_COPY but do not seem to get a message. I tried this using both Ctrl-C and Copy from the context menu:

   BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)
      if(WM_COPY == pMsg->message)
         I never get here...

      return CDialog::PreTranslateMessage(pMsg);

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

GrailmanAuthor Commented:
Thanks for the help!
Glad to be of service. :)

One other option you have by the way, is to just override the

and then:

void CEditCtrl::OnUpdateEditCopy(CCmdUI* pCmdUI)
    pCmdUI->Enable (false);

This will gray out the copy command from the menus when that edit control is selected. That way you won't get support calls saying they can't seem to copy text no matter how many times they select it. :)
GrailmanAuthor Commented:
Great idea!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.