Click here to Skip to main content
15,885,914 members
Articles / Programming Languages / Visual C++ 10.0
Tip/Trick

CRichEditCtrl Does Not Take the Return

Rate me:
Please Sign up or sign in to vote.
1.00/5 (2 votes)
6 Mar 2014CPOL 13.1K   2   5
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:

C++
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);
}

License

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Question[My vote of 1] The RichEdit control has a documented interface for that Pin
.:floyd:.7-Mar-14 0:11
.:floyd:.7-Mar-14 0:11 
AnswerRe: [My vote of 1] The RichEdit control has a documented interface for that Pin
Arkadiusz@inquiry8-Mar-14 9:14
Arkadiusz@inquiry8-Mar-14 9:14 
QuestionQuestion Pin
Rick York6-Mar-14 12:51
mveRick York6-Mar-14 12:51 
AnswerRe: Question Pin
Arkadiusz@inquiry8-Mar-14 8:49
Arkadiusz@inquiry8-Mar-14 8:49 
GeneralRe: Question Pin
Rick York10-Mar-14 11:16
mveRick York10-Mar-14 11:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.