Solved

Return key in CEdit on CDialogBar

Posted on 1997-03-21
4
614 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maxBlock challenge 30 142
post4 challenge 28 104
FizzBuzz challenge 9 82
noX challenge 17 129
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 …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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