HwndSource win32 与 Ribbons 和 KeyTips 集成
我的情况比较复杂,但我见过其他人这样做。不幸的是,没有提及我的具体问题。 我正在尝试将包含功能区的 WPF UserControl 集成到 Win32 主机应用程序中。到目前为止,一切都运行得非常顺利(甚至令我惊讶)。我正在使用 HwndSource 创建一个原始 Win32 子窗口并将其嵌入到 Win32 主机顶级窗口中。我已经尝试过 TabControls、Buttons、RadioButtons、WebBrowsers 以及 UserControl 中的所有内容,它们都可以在我的 Win32 主机应用程序中使用。当然,UserControl 网格的顶行有一个 Ribbon 控件。
基本上这就是我正在做的事情:
mHwnd = new HwndSource (
0, 0x40000000 | 0x10000000,
0,
left,
top,
width,
height,
"CIntegrationTest",
parentHandle);
mUserCtrl = new UserControl1 ();
mHwnd.RootVisual = mUserCtrl;
这效果相当好。 我在功能区下方的 UserControl1 中有一些其他控件(例如编辑和一些按钮)。当键盘焦点位于这些控件之一内时,我可以使用 Alt+ 访问 RibbonTab 及其元素的按键提示。但是,当焦点不在 WPF UserControl 内部,而是来自 Win32 主机的某些控件时,热键不起作用。
我查看了热键的实现,发现一个名为 KeyTipService 的类(位于 RibbonControlsLibrary\Microsoft\Windows\Controls\KeyTipService.cs 中)使用 InputManager.Current.PostProcessInput 和 InputManager.Current.PreProcessInput 来处理 KeyTip 热键。
不幸的是,我完全不知道如何将必要的关键事件从 Win32 应用程序转发到功能区。我什至不知道如何识别需要转发的消息。
也许这里有人遇到了类似的问题,或者对 WPF 消息处理有更多线索,可以帮助我或给出一些提示。
PS:我在 Windows XP SP3 上运行 Visual Studio 2010 Premium,并从 2010 年 10 月开始使用 Microsoft Ribbons for WPF。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够将未处理的按键事件从 Windows 窗体传递到 WPF 层。覆盖 OnKeyDown、OnKeyUp 以及您可能需要的任何其他内容。如果没有任何 Form1 控件处理该事件,则 KeyEventArgs 的 Handled 属性将为 false。
然后,您可以将 Forms.KeyEventArgs 转换为 Controls.KeyEventArgs 并将其传递到 WPF 层。确保不要复制 Handled 布尔值,否则您的 WPF 部分将根本无法处理它。 :)
我附上了一些示例代码来说明这个想法。
You should be able to pass unhandled key events from the Windows form into the WPF layer. Override OnKeyDown, OnKeyUp, and any other you might need. If not any of your Form1 controls handle the event, the Handled property of the KeyEventArgs will be false.
You can then convert the Forms.KeyEventArgs into a Controls.KeyEventArgs and pass it into the WPF layer. Make sure not to copy the Handled boolean, or else your WPF part will not handle it at all. :)
I have attached some sample code that illustrates the idea.