MFC CRichEditCtrl::PreTranslateMessage

abc abc 351 Reputation points
2020-09-07T13:49:56.35+00:00

Hi,

I subclassed CRichEditCTrl and in PreTranslateMessage I am handling ctrl+x. On ctrl+x I am confirming the user whether to delete text

case 88: //ctrl+x
if(IDNO==AfxMessageBox(_T("Do you want to delete selected text?"),MB_YESNO|MB_ICONQUESTION)) return true;
break;

If I execute AfxMessageBox, the PreTranslateMessage receives message WM_CHAR with char x right after ctrl+x and in the richeditctrl character x is getting typed.. If I am not calling AfxMessageBox on ctrl+x, the PreTranslateMessage does not receive the message WM_CHAR with char x.

How to avoid PreTranslateMessage receiving WM_CHAR with char x ? I need to confirm with the user whether to delete the text or not?

Thanks

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,628 questions
{count} votes

Accepted answer
  1. RLWA32 43,046 Reputation points
    2020-09-07T17:09:42.78+00:00

    Give this a try -

     BOOL CMyRichEditCtrl::PreTranslateMessage(MSG* pMsg)
     {
       // TODO: Add your specialized code here and/or call the base class
    
       if (pMsg->message == WM_KEYDOWN  && pMsg->wParam == 0x58 && (::GetKeyState(VK_CONTROL) & 0x8000) != 0)
       {
         if (AfxMessageBox(_T("Delete Text?"), MB_YESNO) == IDYES)
               PostMessage(WM_CUT);
    
         return TRUE;
       }
    
       return CRichEditCtrl::PreTranslateMessage(pMsg);
     }
    

0 additional answers

Sort by: Most helpful