• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Intercepting Carriage Return in Modal Dialog

I have a modal dialog which has an Edit control and
a radio box.  Whenever I hit carriage return when the Edit
control or a radio box button has focus, it causes the
dialog to close.  How can I stop this from happening?  I
would rather have the carriage returns ignored.
0
kaplan1
Asked:
kaplan1
  • 2
1 Solution
 
chensuCommented:
This is the function of a dialog box. When you press Return key, it will activate the default pushbutton, such as the OK or Cancel button. Try overriding CDialog::OnKeyDown() (or OnKeyUp). When you detect it is a Return key, do nothing. Otherwise, call the base class function CDialog::OnKeyDown().
0
 
kaplan1Author Commented:
I overrode the CDialog::OnKeyDown() however this function is
not being called when I type in the edit contol.
0
 
chensuCommented:
Yes, because the CEdit::OnKeyDown() is called in this case. Do you mean this method works when the radio button has focus and it does not when the edit control has focus?
0
 
wpintoCommented:
Hi kaplan1,

The messages OnKeyDown(), OnKeyUp()... won't be called for a modal dialog box.

Check out Article ID: Q126874 in Microsoft KB for more info
PRB: Modal Dialog Box Prevents Calls to PreTranslateMessage

The article also suggests a solution, which if implemented will allow messages to be sent to the dialog box. Then you can trap the OnKeyDown() message... & check for the Return key.

Hope this helps

Wilfred
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now