Pailes

Hello Everybody,

I'm trying to embed a WPF-Page into a regular MFC Dialog and I'm having problems with typing data into the WPF edit fields.

I can click into the field and the cursor shows up, but typing data into it doesn't work.

It's also possible to press a WPF button and catching the event on the MFC side and installing an HwndSourceHook I can easily catch all the WM_KEYDOWN events which are routed to the HwndSource.

I also notice that after focusing an WPF edit field a tab key press shifts focus on one of my MFC buttons rather than the next WPF edit field.

Did anybody encounter similiar problems

Any help is appreciated.



Re: Windows Presentation Foundation (WPF) Problems with HwndSource in MFC Dialog

Chango V. - MSFT

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1100471&SiteID=1





Re: Windows Presentation Foundation (WPF) Problems with HwndSource in MFC Dialog

Pailes

I have been looking at that page already but I wasn't sure if it would help me.

Still I'm not really sure how to solve my problem within my MFC example code since the typical win32 event loop is not exposed in an MFC app and I'm also wondering why my problem does not exist in the example code from the SDK because neither of the ComponentDispatcher methods are called there as it uses a standard win32 message loop.





Re: Windows Presentation Foundation (WPF) Problems with HwndSource in MFC Dialog

Chango V. - MSFT

If you post a paired down repro of the problem, someone can likely help.




Re: Windows Presentation Foundation (WPF) Problems with HwndSource in MFC Dialog

Pailes

Here is the code:
http://peter.nxbone.net/MFCHostWPF.zip

Hopefully somebody has the time to look at it, it's a ready-to-compile VS 2005 solution.




Re: Windows Presentation Foundation (WPF) Problems with HwndSource in MFC Dialog

Chango V. - MSFT

Sharing the message pump with MFC is easy. Here's what you need to enable proper input handling in your application:

BOOL CSkinnedAppApp :: PreTranslateMessage(MSG* pMsg)
{
return System::Windows::Interop::ComponentDispatcher::RaiseThreadMessage(
*reinterpret_cast<System::Windows::Interop::MSG*>(pMsg));
}

Further, you shouldn't need to use a HwndSourceHook, unless you are handling some non-standard messages or want to alter the handling of some message.

To get tabbing to work between the MFC and WPF controls, you have to implement IKeyboardInputSite and attach it to the HwndSource. The MSDN documentation is a good starting point. This can also help you: http://blogs.msdn.com/nickkramer/Default.aspx p=2

Good luck.






Re: Windows Presentation Foundation (WPF) Problems with HwndSource in MFC Dialog

Pailes

Works great, thanks.

P.S.: I knew I wouldn't need the HwndSourceHook, it was just a test to see whether I'm receiving the right Windows message.