My Own Edit Box(VC++)
We will see here how to create an Edit Box which say disallows CUT+COPY+PASTE
The normal class CEdit does not have API corresponding to this so this essentially requires subclassing
Say we have a Dialog CNoCutCopyPasteDialog
and we have a control IDC_EDIT1 which is an EDIT BOX....
We will have to route all messages coming to the IDC_EDIT1 control to our own class so that we can trap them in the way we want.
This is simple enough.
In DO Data Exchange of the CNoCutCopyPasteDialog
add
DDX_Control(pDX, IDC_EDIT1, m_Edit1);
What this effectively does is routes all messages coming to IDC_EDIT1 to the object m_Edit1.
Create a new class CMyEdit derived from CEdit
Declare CMyEdit m_Edit1 in the CNoCutCopyPasteDialog
In the CMyEdit class add the message handler
LRESULT CMyEdit::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if((WM_PASTE==message)||
(WM_COPY==message)||
(WM_COPY==message))
{
MessageBox("U cannot paste here",NULL,MB_OK);
return 0L;
}
else
{
return CEdit::WindowProc(message,wParam,lParam);
}
}
This means that all Edit box messages are routed to CMyEdit class and CUT,COPY,PASTE messages are handled all other messages are returned to the parent CEdit class
The normal class CEdit does not have API corresponding to this so this essentially requires subclassing
Say we have a Dialog CNoCutCopyPasteDialog
and we have a control IDC_EDIT1 which is an EDIT BOX....
We will have to route all messages coming to the IDC_EDIT1 control to our own class so that we can trap them in the way we want.
This is simple enough.
In DO Data Exchange of the CNoCutCopyPasteDialog
add
DDX_Control(pDX, IDC_EDIT1, m_Edit1);
What this effectively does is routes all messages coming to IDC_EDIT1 to the object m_Edit1.
Create a new class CMyEdit derived from CEdit
Declare CMyEdit m_Edit1 in the CNoCutCopyPasteDialog
In the CMyEdit class add the message handler
LRESULT CMyEdit::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if((WM_PASTE==message)||
(WM_COPY==message)||
(WM_COPY==message))
{
MessageBox("U cannot paste here",NULL,MB_OK);
return 0L;
}
else
{
return CEdit::WindowProc(message,wParam,lParam);
}
}
This means that all Edit box messages are routed to CMyEdit class and CUT,COPY,PASTE messages are handled all other messages are returned to the parent CEdit class
0 Comments:
Post a Comment
<< Home