?
Solved

Disabling copy in Edit ctrl

Posted on 2002-03-12
6
Medium Priority
?
318 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 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