Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
When subclassing from a CEdit class, the default clipboard functions (Ctrl + X, C, V, Z, A) (Using the keyboard input & not the context menu) wont work.

How to make it possible in both CDialog based apps & so for CFormView on SDI or MDI apps !?

Help me please
Posted

C++
BOOL CEditEx::PreTranslateMessage(MSG* pMsg)
{
    // TODO: Add your specialized code here and/or call the base class
    // Intercept Ctrl + Z (Undo), Ctrl + X (Cut), Ctrl + C (Copy), Ctrl + V (Paste) and Ctrl + A (Select All)
    // before CEdit base class gets a hold of them.
    if (pMsg->message == WM_KEYDOWN && ::GetKeyState(VK_CONTROL) < 0)
        switch (pMsg->wParam)
        {
        case 'Z':
            Undo();

            return TRUE;

        case 'X':
            Cut();

            return TRUE;

        case 'C':
            Copy();

            return TRUE;

        case 'V':
            Paste();

            return TRUE;

        case 'A':
            SetSel(0, -1);

            return TRUE;
        }

    return CEdit::PreTranslateMessage(pMsg);
}
 
Share this answer
 
You need to add keyboard handling in your application and respond to these key combinations as required. When you receive a CTL + C you should call the CEdit::Copy()[^] function, etc.
 
Share this answer
 
Comments
Mr. Tomay 26-Jan-12 13:17pm    
Where to handle a CTRL + C combination key (Which handler function should I use from the CEdit subclassed class) ?
Richard MacCutchan 27-Jan-12 3:38am    
Which handler function ...
Whichever one you decide should handle it. Personally I would set Ctrl + C as an accelerator connected to my Copy menu item, and use an OnXXX handler to deal with it.
Mr. Tomay 6-Feb-12 12:33pm    
you don't understand my question. Anyway I have found a solution to my issue (The handler function I was talking about is as follows):

BOOL CEditEx::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
// Intercept Ctrl + Z (Undo), Ctrl + X (Cut), Ctrl + C (Copy), Ctrl + V (Paste) and Ctrl + A (Select All)
// before CEdit base class gets a hold of them.
if (pMsg->message == WM_KEYDOWN && ::GetKeyState(VK_CONTROL) < 0)
switch (pMsg->wParam)
{
case 'Z':
Undo();

return TRUE;

case 'X':
Cut();

return TRUE;

case 'C':
Copy();

return TRUE;

case 'V':
Paste();

return TRUE;

case 'A':
SetSel(0, -1);

return TRUE;
}

return CEdit::PreTranslateMessage(pMsg);
}
Mohibur Rashid 13-May-12 19:21pm    
Richard MacCutchan understood your question very well, but you didn't understand his answer. He answered the same as your solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900