Home > C++, VC++, MFC > Blocking cut, copy, paste and context menu for an edit control!

Blocking cut, copy, paste and context menu for an edit control!

Sometimes you may have to prevent cut, copy, and paste, sometimes context menu too, on an edit control. So how to do this!

Well it’s easy to do this… Override WindowProc and provide empty case statements for these events, WM_COPY, WM_CUT, WM_PASTE, WM_CONTEXTMENU.

LRESULT CMyEdit::WindowProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
   switch( Message )
   {
     case WM_COPY: // No copy
     case WM_CUT:  // No cut
     case WM_PASTE:// No paste
     case WM_CONTEXTMENU:// No context menu
        return 0;// Yup! don't call base implementation
   }// End switch

   return CEdit::WindowProc( Message, wParam, lParam );
}//End WindowProc
Advertisements
  1. ronnieviegas
    April 14, 2009 at 7:11 pm

    hi nibu,
    I have a editbox which I create in view. It does not receive WM_PASTE, WM_COPY, WM_CUT. I tried the above code.

    What is the problem?

    Regards,
    Ronnie

  2. February 21, 2008 at 4:03 pm

    Hey bw,

    I’ve read an article on MSDN related to this topic. Probably the author is Paul Dilascia. Check out! 😉

  3. bw
    February 21, 2008 at 1:48 pm

    hey man, is it possible to extend edit control’s context menu (add new items to standard one like Copy Paste)?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: