-
June 22nd, 2009, 04:40 AM
#1
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
-
June 22nd, 2009, 05:04 AM
#2
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);
}
-
June 22nd, 2009, 05:16 AM
#3
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?
-
June 22nd, 2009, 05:32 AM
#4
Re: WM_CUT & WM_PASTE Messages in Dialog Box
Victor Nijegorodov
-
June 22nd, 2009, 05:54 AM
#5
Re: WM_CUT & WM_PASTE Messages in Dialog Box
Originally Posted by VictorN
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;
}
// ...
-
June 22nd, 2009, 06:23 AM
#6
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.
-
June 22nd, 2009, 06:31 AM
#7
Re: WM_CUT & WM_PASTE Messages in Dialog Box
Originally Posted by skoutso
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|