Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 C++ C MFC clipboard
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 26-Jan-12 5:02am
tomay30001.2K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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);
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
tomay3000 at 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 at 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.
tomay3000 at 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 at 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)

  Print Answers RSS
0 DamithSL 265
1 CPallini 235
2 OriginalGriff 233
3 Maciej Los 175
4 George Jonsson 170
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 13 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100