Solved

Return key in CEdit on CDialogBar

Posted on 1997-03-21
4
611 Views
Last Modified: 2013-11-20
How do I trap a return key in a CEdit derived class when the edit control is on a CDialogBar?  Preferably, I would like the solution to be CEdit related, i.e. CMyEdit::OnReturnKey()

Yes it does matter if the CEdit control is on a CDailogBar, that's the problem, somehow the CDialogBar trapps the return key and the WM_CHAR, WM_KEYUP, WM_KEYDOWN, etc. never come through so that the OnChar(), OnKeyUp(), or OnKeyDown() get called.

If your getting the OnChar() message in your CEdit derived class when it's on a CDialogBar let me know.  I certainly could be doing something else wrong.

0
Comment
Question by:GEN1040
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
sapek earned 200 total points
ID: 1300611
I don't know if it make a difference that the edit is on CDialogBar. I use following code to trap enter in edit on my editable print preview:

BEGIN_MESSAGE_MAP(CEditEnter, CEdit)
    //{{AFX_MSG_MAP(CEditEnter)
    ON_WM_CHAR()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CEditEnter::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    switch(nChar)
    {
        case VK_RETURN:                         /* do somthing */
                        break;

        default:        CEdit::OnChar(nChar, nRepCnt, nFlags);
    }
}

0
 

Author Comment

by:GEN1040
ID: 1300612
Edited text of question
0
 
LVL 2

Expert Comment

by:sapek
ID: 1300613
Well, I checked that and I know what is going on. CDialogBar is like a modeless dialog box and MFC calls IsDialogMessage for it and if it returns TRUE MFC never calls DispatchMessage for the message (this is what you are supposed to do for modeless dialogs). For WM_KEYDOWN(VK_RETURN) and WM_KEYDOWN(VK_ESCAPE) IsDialogMessage returns TRUE and produces WM_COMMAND(IDOK) and WM_COMMAND(IDCANCEL) which are sent to the dialog box.
This means that WM_KEYDOWN(VK_RETURN) will never be dispached to an edit control in a CDialogBar (or other modeless dialog) although such a message is in the message queue.
So how you can work around it? Assuming you don't have a IDOK button on the CDialogBar you can handle WM_COMMAND(IDOK) in a CDialogBar derived class and SendMessage WM_CHAR(VK_RETURN) to a control with focus. Then you can handle OnChar in your CEdit derived class.

Adam

0
 
LVL 2

Expert Comment

by:sapek
ID: 1300614
Now I think I see the whole picture, now.
While investigating your question, the second thing I tried was subclassing the edit and it didn't work. So I was somewhat supriced that it worked for you. It turned out that I tired WM_KEYDOWN and you tried WM_KEYUP. While the later realy makes it to edit control the first one is swallowed by the IsDialogMessage and translated into the WM_COMMAND(IDOK). When I failed with WM_KEYDOWN I never thought about trying WM_KEYUP.

Anyway it turned out to be quite interesting problem.

Adam

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question