HwndSource win32 integration with Ribbons and KeyTips-Collection of common programming errors
My situation is rather complex, but I’ve seen other people do this. Unfortunately, there is no mention of my specific problem. I am in the process of trying to integrate a WPF UserControl including a Ribbon into a Win32 host application. So far, everything has been working pretty neat (to my surprise, even). I am using HwndSource to create a raw Win32 child-window and embed this into a Win32 host top-level window. I have tried TabControls, Buttons, RadioButtons, WebBrowsers and everything inside the UserControl and they all are usable from within my Win32 host application. And, of course, there is a Ribbon control at the top row of the UserControl’s Grid.
Here’s basically what I am doing:
mHwnd = new HwndSource (
0, 0x40000000 | 0x10000000,
0,
left,
top,
width,
height,
"CIntegrationTest",
parentHandle);
mUserCtrl = new UserControl1 ();
mHwnd.RootVisual = mUserCtrl;
This works rather good. I have some other controls (like an edit and a few buttons) in UserControl1 below the Ribbon. When the keyboard focus is inside one of these controls, I can use Alt+ to access the KeyTips of the RibbonTabs and it’s elements. But when the focus is not inside of the WPF UserControl, but some control from the Win32 host, the hotkeys do not work.
I had a look at the implementation of the hotkeys and found out that a class called KeyTipService (found in RibbonControlsLibrary\Microsoft\Windows\Controls\KeyTipService.cs) uses InputManager.Current.PostProcessInput and InputManager.Current.PreProcessInput to handle the KeyTip hotkeys.
Unfortunately, I’m totally out of ideas how I could forward the necessary key events from the Win32 application to the Ribbon. I don’t even know how I could identify the messages that need to be forwarded.
Maybe someone here ran into a similar problem or has some more clue about WPF message processing and can help me or give some hints.
P.S.: I’m running Visual Studio 2010 Premium on Windows XP SP3 here and am using the Microsoft Ribbons for WPF from October 2010.