WinForms Textbox in MFC CDialogBar

S

Steve Baer

I posted this on the msdn forums. Sorry for crossposting, but I haven't
received any answer and I want to try here before calling someone at
Microsoft.

We have an MFC application that supports both MFC and .NET plug-ins. If
plug-ins want to use docking dialogs, we embed UserControls in our CCtrlBar
derived classes. All of this works great except for the .NET TextBoxes. The
TextBoxes will display correctly and receive input; the only problem is that
they don't receive KeyDown events for "Enter" and "Escape" keys.

I have written a simple example with VC2005 that displays this problem by
embedding a multiline TextBox on a CDialogBar. The TextBox will not allow
for multiline input because the "Enter" KeyDown event is getting eaten
somewhere along the way. I posted the project at
http://en.wiki.mcneel.com/content/upload/files/WinFormsCtrlBar.zip
in case anyone is interested.

My question is:
How do I get a multiline WinForms textbox to work if it is a child of a
CDialogBar?

Any help would be appreciated. Thanks,
-Steve

Steve Baer
Robert McNeel & Associates
 
F

Frank Hickman

Steve Baer said:
I posted this on the msdn forums. Sorry for crossposting, but I haven't
received any answer and I want to try here before calling someone at
Microsoft.

We have an MFC application that supports both MFC and .NET plug-ins. If
plug-ins want to use docking dialogs, we embed UserControls in our
CCtrlBar derived classes. All of this works great except for the .NET
TextBoxes. The TextBoxes will display correctly and receive input; the
only problem is that they don't receive KeyDown events for "Enter" and
"Escape" keys.

I have written a simple example with VC2005 that displays this problem by
embedding a multiline TextBox on a CDialogBar. The TextBox will not allow
for multiline input because the "Enter" KeyDown event is getting eaten
somewhere along the way. I posted the project at
http://en.wiki.mcneel.com/content/upload/files/WinFormsCtrlBar.zip
in case anyone is interested.

My question is:
How do I get a multiline WinForms textbox to work if it is a child of a
CDialogBar?

Any help would be appreciated. Thanks,
-Steve

Steve Baer
Robert McNeel & Associates


I'm not really sure what is gobbling up the return key but you can force the
control to handle it by adding the following to your OnKeyUp handler...

virtual void OnKeyUp( System::Windows::Forms::KeyEventArgs^ e ) override
{
if ( e->KeyCode == System::Windows::Forms::Keys::Return )
{
if ( this->Multiline )
{
this->AppendText( L"\r\n" );
e->Handled= true;
}
}
int good_break_point = 0;
}

HTH
--
============
Frank Hickman
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
 
S

Steve Baer

Hi Frank,
Yep that is one possible solution, but from the reports I've received from
plug-in developers there are other events not getting fired because of the
missing KeyDown. One developer has a single line textbox that receives
validation events in his standalone version when the enter key is pressed,
but does not get that event when embedded in one of our CCtrlBars. I was
trying to keep the sample as simple as possible and only point out the
obvious problem with multiline textboxes.

Thanks for looking though. I do appreciate it.

-Steve

Steve Baer
Robert McNeel & Associates
 
F

Frank Hickman

Steve Baer said:
Hi Frank,
Yep that is one possible solution, but from the reports I've received from
plug-in developers there are other events not getting fired because of the
missing KeyDown. One developer has a single line textbox that receives
validation events in his standalone version when the enter key is pressed,
but does not get that event when embedded in one of our CCtrlBars. I was
trying to keep the sample as simple as possible and only point out the
obvious problem with multiline textboxes.

Thanks for looking though. I do appreciate it.

-Steve

Steve Baer
Robert McNeel & Associates


Hmm, I would hazard a guess that your problem is related to the problem of
handling the return/escape key in a dialog box. Have you attempted to trap
the message from the message loop before anything else can get a hold of it?

--
============
Frank Hickman
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
 
Top