Solved

Disabling copy in Edit ctrl

Posted on 2002-03-12
6
299 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
Comment Utility
You should achieve the behaivour you want by filtering out "WM_COPY" messages...
0
 
LVL 1

Author Comment

by:Grailman
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:Grailman
Comment Utility
Thanks for the help!
0
 
LVL 3

Expert Comment

by:Crius
Comment Utility
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
Comment Utility
Great idea!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumNumber challenge 16 98
haveThree challenge 22 100
mapBully challenge 6 88
Making an alias 7 51
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

6 Experts available now in Live!

Get 1:1 Help Now