65.9K
CodeProject is changing. Read more.
Home

CRichEditCtrl Does Not Take the Return

starIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

1.00/5 (2 votes)

Mar 6, 2014

CPOL
viewsIcon

13652

CRichEditCtrl does not take the return

Introduction

Using the CRichEditCtrl control in combination with the Dialog creates a small problem like Dialog eats the return key pressed message. Although I was searching for a simple and quick solution for that, I have struggled to find a definite answer.

The quickest way to get around that problem is to override PreTranslateMessage() function of a Dialog and just return FALSE when the return key pressed message is called for the Rich Edit control...

Just copy/paste:

BOOL EditDlg::PreTranslateMessage(MSG* pMsg) 
{
    if(pMsg->message == WM_KEYDOWN)
    {
        if((pMsg->lParam == IDC_RICHDIALOG_EDIT_ID/*id of a Edit Box*/) && 
            (pMsg->wParam == VK_RETURN)
        {
            return FALSE;
        }
    }
    return CDialogEx::PreTranslateMessage(pMsg);
}