CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2004
    Location
    Athens
    Posts
    7

    WM_CUT & WM_PASTE Messages in Dialog Box

    Hi all,

    I have a CDialog derived class that contains a number of Edit controls. Dialog is modal.
    I want to capture the WM_CUT, WM_CLEAR, WM_PASTE Messages to anyone of the edit controls and apply a common routine before these messages are dispatched to their owners.
    I was puzzled a lot with the ON_NOTIFY_RANGE etc. but without any success.

    I use already the PresTranslateMessage function to capture keyborad events, but this does not work for the CUT,PASTE,CLEAR messages.

    Is there any easy way to do this? A sample code would be very usefull.

    Thanks

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: WM_CUT & WM_PASTE Messages in Dialog Box

    Derive your own class from CEdit and override WindowProc.
    Code:
    LRESULT CMyEdit::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch(message)
        {
        case WM_PASTE:
            TRACE0("\nWM_PASTE");
            break;
        case WM_CUT:
            TRACE0("\nWM_CUT");
            break;
        // ...
        }
        return CEdit::WindowProc(message, wParam, lParam);
    }
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Jul 2004
    Location
    Athens
    Posts
    7

    Re: WM_CUT & WM_PASTE Messages in Dialog Box

    Many thanks for your reply,

    I understand that I have to create a CEdit class for each one of the edit controls? Is that right?
    Isn't there any way to avoid this?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: WM_CUT & WM_PASTE Messages in Dialog Box

    Quote Originally Posted by skoutso View Post
    I understand that I have to create a CEdit class for each one of the edit controls? Is that right?
    Isn't there any way to avoid this?
    Why "to avoid it"?
    Creating a new class derived from CEdit is the only correct way! Why are you afraid it?

    PS: I wouldn't override the WindowProc in the derived class; instead I'd create message handlers for WM_PASTE, WM_CUT and so on...
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: WM_CUT & WM_PASTE Messages in Dialog Box

    Quote Originally Posted by VictorN View Post
    PS: I wouldn't override the WindowProc in the derived class; instead I'd create message handlers for WM_PASTE, WM_CUT and so on...
    @To VictorN: Right. Overriding WindowProc can become a mess, so your solution is a little bit more elegant.

    @To skoutso: As VictorN suggested, you can map handlers for WM_CUT, WM_PASTE, and so on as follows:
    Code:
    class CMyEdit : public CEdit
    {
    // ...
        afx_msg LRESULT OnCopy(WPARAM wParam, LPARAM lParam);
    // ...
    };
    Code:
       //...
       ON_MESSAGE(WM_COPY, &CMyEdit::OnCopy)
       // ...
    END_MESSAGE_MAP()
    
    LRESULT CMyEdit::OnCopy(WPARAM wParam, LPARAM lParam)
    {
        // ...
        return 0;
    }
    // ...
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Jul 2004
    Location
    Athens
    Posts
    7

    Smile Re: WM_CUT & WM_PASTE Messages in Dialog Box

    To VictorN

    I was trying to find a way "to avoid" writing too much and messing with the code for something that might be simple.

    To ovidiocucu

    I agree. It's better to map messages (a VictorN suggested) than overriding the WindowsProc

    Thank you both.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: WM_CUT & WM_PASTE Messages in Dialog Box

    Quote Originally Posted by skoutso View Post
    To VictorN

    I was trying to find a way "to avoid" writing too much and messing with the code for something that might be simple.
    There is no any other more simpler way than to derive a new class.
    Victor Nijegorodov

Tags for this Thread

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