?
Solved

Disabling copy in Edit ctrl

Posted on 2002-03-12
6
Medium Priority
?
327 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Technology Partners: 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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

755 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