?
Solved

Return key in CEdit on CDialogBar

Posted on 1997-03-21
4
Medium Priority
?
631 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
sapek earned 600 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 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