?
Solved

Disabling copy in Edit ctrl

Posted on 2002-03-12
6
Medium Priority
?
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

649 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