CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2003
    Posts
    375

    How to override the Ctrl+V on CRichEditCtrl?

    I Want to rewrite the function of atcion of Ctrl+V on the richedit control,
    If it is impossible, I Want to disable the Ctrl+V, Who could give me some suggestions?Thanks!

  2. #2
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

    Re: How to override the Ctrl+V on CRichEditCtrl?

    That is a very good question forester!

    What I would have suggested was to simple derive your own class from CRichEditCtrl and then handle the WM_PASTE message. But for some bisarre reasons this does not work for CRichEditCtrl while it works perfectly for CEdit controls. The same happens when I try to intercept WM_COPY message (guess same with WM_CUT).

    Maybe someone can elaborate further on this strange behaviour?


    Laitinen
    Last edited by laitinen; August 2nd, 2007 at 09:08 AM.

  3. #3
    Join Date
    May 2005
    Posts
    4,954

    Re: How to override the Ctrl+V on CRichEditCtrl?

    Quote Originally Posted by forester
    I Want to rewrite the function of atcion of Ctrl+V on the richedit control,
    If it is impossible, I Want to disable the Ctrl+V, Who could give me some suggestions?Thanks!
    One way to disable it, look at the attached sample.

    Cheers
    Attached Files Attached Files
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  4. #4
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    Re: How to override the Ctrl+V on CRichEditCtrl?

    Hello,

    One easy method to avoid the default behaviour of any key combination is to define an acelerator for that key, create a handler for the accelerator key and to leave the handler function blank.

    Regards,
    Pravin.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

  5. #5
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

    Re: How to override the Ctrl+V on CRichEditCtrl?

    Thanks to Pravin and Golanshahar for providing possible solutions!

    Just to make it clear, I know this is not a big deal at all but it surprises me that I am not able to handle the WM_PASTE, WM_COPY. WM_CUT and so on in the CRichEditCtrl.

    Both solutions mentioned above work good for the CTRL+V key combination, but would not work if there was a menu item or contextmenu item that allowed the user to paste text into the control. Therefore it is a mystery to me why you can not solve the whole problem by just handling the WM_PASTE message. To me, this seems like a bug from MS.

    Regards,

    Laitinen

  6. #6
    Join Date
    May 2005
    Posts
    4,954

    Re: How to override the Ctrl+V on CRichEditCtrl?

    Quote Originally Posted by laitinen
    Thanks to Pravin and Golanshahar for providing possible solutions!

    Just to make it clear, I know this is not a big deal at all but it surprises me that I am not able to handle the WM_PASTE, WM_COPY. WM_CUT and so on in the CRichEditCtrl.

    Both solutions mentioned above work good for the CTRL+V key combination, but would not work if there was a menu item or contextmenu item that allowed the user to paste text into the control. Therefore it is a mystery to me why you can not solve the whole problem by just handling the WM_PASTE message. To me, this seems like a bug from MS.

    Regards,

    Laitinen

    I updated my sample code look at the attached project to see how to trap the WM_PASTE message.

    Cheers
    Attached Files Attached Files
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  7. #7
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

    Re: How to override the Ctrl+V on CRichEditCtrl?

    Hi Golan!

    You are actually experiencing the same problem as I did. If you comment out the code you added in PreTranslateMessage, then you would think that you OnPaste handler should be invoked, right? But it is not!! It is invoked when you do an implicit call to the paste member function, but not when you press ctrl+v. Or am I way of out of track here?

    Laitinen

  8. #8
    Join Date
    Jan 2003
    Posts
    375

    Re: How to override the Ctrl+V on CRichEditCtrl?

    I learn a lot, Thanks for your replies! I will test to see which one works better!

  9. #9
    Join Date
    May 2005
    Posts
    4,954

    Re: How to override the Ctrl+V on CRichEditCtrl?

    Quote Originally Posted by laitinen
    Hi Golan!

    You are actually experiencing the same problem as I did. If you comment out the code you added in PreTranslateMessage, then you would think that you OnPaste handler should be invoked, right? But it is not!! It is invoked when you do an implicit call to the paste member function, but not when you press ctrl+v. Or am I way of out of track here?

    Laitinen
    I think you are confusing with two things here, if you will open Spy++ and check the messages that is being send to the rich edit control you would see that when you press Ctrl+V WM_PASTE message is not being generated!!! Only WM_KEYDOWN/UP for Ctrl + V, and when you call Paste() member function it send the WM_PASTE message and it can be trapped so maybe this is confusing you.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  10. #10
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

    Re: How to override the Ctrl+V on CRichEditCtrl?

    Quote Originally Posted by golanshahar
    I think you are confusing with two things here, if you will open Spy++ and check the messages that is being send to the rich edit control you would see that when you press Ctrl+V WM_PASTE message is not being generated!!! Only WM_KEYDOWN/UP for Ctrl + V, and when you call Paste() member function it send the WM_PASTE message and it can be trapped so maybe this is confusing you.

    Cheers
    What I am confused about is why WM_PASTE is not sent. I dont see any reason why this should differ from a regular CEdit control. Do you?

    Thanks for great help!

    Laitinen

  11. #11
    Join Date
    May 2005
    Posts
    4,954

    Re: How to override the Ctrl+V on CRichEditCtrl?

    Quote Originally Posted by laitinen
    What I am confused about is why WM_PASTE is not sent. I dont see any reason why this should differ from a regular CEdit control. Do you?

    Thanks for great help!

    Laitinen
    Well i have no idea why its differ , But, this is what Spy++ shows...

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured