Solved

Disabling copy in Edit ctrl

Posted on 2002-03-12
6
301 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:Grailman
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6856960
You should achieve the behaivour you want by filtering out "WM_COPY" messages...
0
 
LVL 1

Author Comment

by:Grailman
ID: 6857052
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);
   }

???
0
 
LVL 3

Accepted Solution

by:
Crius earned 100 total points
ID: 6857221
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:Grailman
ID: 6857236
Thanks for the help!
0
 
LVL 3

Expert Comment

by:Crius
ID: 6857294
Glad to be of service. :)

One other option you have by the way, is to just override the
ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)

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. :)
0
 
LVL 1

Author Comment

by:Grailman
ID: 6857314
Great idea!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 177
Unix / Linux grid computing 5 144
sum13 challenge 24 90
"Black Box" Testing of Control System Software 2 21
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now