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
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);
}
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?
Re: WM_CUT & WM_PASTE Messages in Dialog Box
Quote:
Originally Posted by
skoutso
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"? :confused: :confused:
Creating a new class derived from CEdit is the only correct way! Why are you afraid it? :confused:
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...
Re: WM_CUT & WM_PASTE Messages in Dialog Box
Quote:
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;
}
// ...
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.
Re: WM_CUT & WM_PASTE Messages in Dialog Box
Quote:
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. :cool: