Solved

Return key in CEdit on CDialogBar

Posted on 1997-03-21
4
602 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
Comment Utility
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
Comment Utility
Edited text of question
0
 
LVL 2

Expert Comment

by:sapek
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now