mfc host app and keyboard navigation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a problem with keyboard navigation using winforms and an MFC based
host application. Do you see any problems calling PreProcessMessage as a
work around?

Here is the solution I came up with:

// override CWinApp::PreTranslateMessage
bool HandleMessage(MSG* pMsg);
BOOL CMfcHostDialogApp::PreTranslateMessage(MSG* pMsg)
{
if (HandleMessage(pMsg))
return TRUE;
return CWinApp::PreTranslateMessage(pMsg);
}

// attempt to handle messages for managed controls
using namespace System;
using namespace System::Windows::Forms;

bool HandleMessage(MSG* pMsg)
{
if (pMsg != NULL && pMsg->hwnd != NULL)
{
Control^ control = Control::FromHandle(IntPtr(pMsg->hwnd));
if (control != nullptr)
return control->PreProcessMessage(Message::Create(IntPtr(pMsg->hwnd),
pMsg->message, IntPtr((void*)pMsg->wParam), IntPtr(pMsg->lParam)));
}
return false;
}


// end sample code

I can send a full sample solution if necessary.
 
I need to be able to tab between controls on winforms based dialogs. I also
need to use keyboard accelerators on winforms based dialogs. Keyboard
navigation is broken when the dialogs are created modeless in an MFC app.
 
Back
Top