Re: subclassing edit control and preventing copy paste clipboard

"domehead100" <[email protected]>
Newsgroups gmane.comp.windows.wtl
Message-ID <[email protected]>
Hi Don,

Looks good.  By the way, you don't return TRUE to indicate that you've handled the message in WTL.  You should still probably return 0.  If you're using the basic message map entries as in your example (MESSAGE_HANDLER, MESSAGE_HANDLER_EX), then there is that BOOL& bHandled that is passed in.  This is always set to TRUE when entering the handler.  By default it is assumed that you've completely handled the message unless you set bHandled = FALSE.  So, your handler could just contain:  return 0;, which would basically "eat" all of these messages and not pass them on any further or to the underlying window procedure.

If you're using the "new-style" message map entries (e.g., MSG_WM_COPY, etc.), then there is no bHandled reference passed in and the message paramaters are automatically unpacked for you into meaningful variables by the message map macros.  In that case, you call SetMsgHandled(FALSE) to indicate that you have not completely handled the message and want to forward it on for further processing.  If you don't call this, the message is considered handled when the handler exits.

~Mike

--- In [email protected], "amante1il" <is.aviv@...> wrote:
>
> Hi Guys,
> 
> Thanks, this is what i have done: (see below)
> BUT I do think there should be some other better way to do that ...
> Deriving directly from CEdit, or adding CEdit the SubclassWindow procedure.
> Or even some functions with in CEdit to do it ...
> 
> Anyway here is my solution:
> // class that drives from CEdit in order to subclass an Edit Control and prevent copy paste
> class CMyEdit : public CWindowImpl<CMyEdit, CEdit>
> {
> public:
> 	BEGIN_MSG_MAP(CMyEdit)
> 		  // your handlers...
> 		  MESSAGE_HANDLER(WM_RBUTTONDOWN, DoNothing)
> 		  MESSAGE_HANDLER(WM_COPY, DoNothing)
> 		  MESSAGE_HANDLER(WM_CUT, DoNothing)
> 		  MESSAGE_HANDLER(WM_PASTE, DoNothing)
> 		  MESSAGE_HANDLER(WM_CLEAR, DoNothing)
> 		  MESSAGE_HANDLER(WM_UNDO, DoNothing)
> 	END_MSG_MAP()
> 	// other stuff...
> 
> 	LRESULT DoNothing(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
> 	{
> 		return TRUE;
> 	}
> };
> 
> 
> Best regards,
> Don
> 
> --- In [email protected], "domehead100" <domehead100@> wrote:
> >
> > --- In [email protected], "amante1il" <is.aviv@> wrote:
> > >
> > > Hi Guys,
> > > 
> > > I have an Edit Control in my dialog. I want to prevent the user from copying text with Ctrl+C and Clipboard functions with right click.
> > > 
> > > I tried Subclassing the Edit control with a CEdit class - but it dosen't have a SubClass function.
> > > 
> > > I tried catching the WM_COPY, WM_CUT etc' messages in the dialog, but it dosen't catch the Edit Control messages. Only on the dialog.
> > > 
> > > Any ideas how to do it?
> > > 
> > > Thanks in Advanced,
> > > Don
> > >
> > 
> > Use something like:
> > 
> > class CMyEdit : public CWindowImpl<CMyEdit, CEdit>
> > {
> > ...
> > DECLARE_MSG_MAP(CMyEdit)
> >    MSG_WM_COPY(OnCopy)
> >    MSG_WM_PASTE(OnPaste)
> > END_MSG_MAP()
> > ...
> > 
> > }
> > 
> > This is how you subclass a window in WTL.  CWindowImpl-derived classes do have a SubclassWindow function.
> > 
> > I would recommend going to www.codeproject.com and locating and reading the articles in the WTL for MFC Programmers series.  They are a very good introduction to WTL, subclassing controls, etc.
> > 
> > ~Mike
> >
>




------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wtl/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/wtl/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.