mfc host app and keyboard navigation

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top