can't disable ctrl-V on a rich edit control

This is a discussion on can't disable ctrl-V on a rich edit control within the Windows Programming forums, part of the Platform Specific Boards category; Hi there, I am trying to disble the Ctrl-V key function for a rich edit control. I set the ENM_KEYEVENTS ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    49

    can't disable ctrl-V on a rich edit control

    Hi there,

    I am trying to disble the Ctrl-V key function for a rich edit control. I set the ENM_KEYEVENTS event mask filter and I handle my WM_NOTIFY message as follows...

    Code:
    case WM_NOTIFY:
             switch( ((LPNMHDR)lParam)->code ){
    							
    		      case EN_MSGFILTER:
    				if( ((MSGFILTER*)lParam)->wParam == 0x0016 ){
                                        MessageBox( hwnd, "Ctrl-V", NULL, MB_OK );
    				    return 1; //disables the key
    			        } 
                           break;
              }
    break;

    This code fails to prevent the Ctrl-V button from pasting into the rich edit control. I know that the if statement is being executed because I get a message but I still get the text pasted into the rich edit control. What am I doing wrong?

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,534
    Try adding this code to your script.
    Code:
    WNDPROC DefEditProc;
    
    LRESULT EditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
       if(uMsg == WM_KEYDOWN)
       {
          if(wParam == 'V' && GetAsyncKeyState(VK_CONTROL))
             return 0;
       }
       return CallWindowProc(DefEditProc, hwnd, uMsg, wParam, lParam);
    }
    And use this right after creating the rich-edit.
    Code:
    DefEditProc = (WNDPROC)SetWindowLong(hRichEdit, GWL_WNDPROC, (long)SpreadEditProc);
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing from a Rich Edit control
    By JustMax in forum Windows Programming
    Replies: 10
    Last Post: 02-14-2009, 06:12 PM
  2. Change cursor on single edit control
    By Niara in forum Windows Programming
    Replies: 3
    Last Post: 01-11-2009, 08:52 AM
  3. Dialog Edit Control and Enter Key
    By Quantrizi in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2004, 07:59 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Rich edit control example Win API
    By Echidna in forum Windows Programming
    Replies: 1
    Last Post: 09-17-2001, 02:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21