查找功能区按钮的窗口句柄
我正在尝试对 Windows 应用程序进行一些自动化。 为了做我想做的事情,我需要一些控件的窗口句柄。
以前,我会通过组合 EnumWindows、EnumChildWindows 和 GetWindowText 来完成此操作。但现在,一些较新的程序不再有带有按钮的工具栏。 相反,他们有一条丝带。
起初这对我来说似乎不是什么大问题,但现在我注意到功能区上的按钮没有显示在 EnumChildWindows 中! 或者至少 GetWindowText 不会返回与屏幕上看到的文本相同的文本。
长话短说: 谁能告诉我如何以编程方式找到功能区上按钮的手柄?
谢谢。 问候, LDX
I'm trying to do some automation of windows applications.
To do whatever I want to do, I need the window handles of some controls.
Before, I would accomplish this with a combination EnumWindows, EnumChildWindows and GetWindowText. But now, some newer programs no longer have toolbar with buttons on it.
Instead, they have a ribbon.
This didn't seem like much of a problem to me at first, but now I notice that the buttons on the ribbon don't show up in EnumChildWindows!
Or at least GetWindowText does not return the same text as the one seen on the screen.
So to make a long story short:
Can anybody tell me how I can programatically find the handle of a button on a ribbon?
Thanks.
Regards,
ldx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用 Visual Studio 附带的 Spy++(或任何其他类似工具)来查看这些按钮是否实际上是窗口。如果是,请查看有关使用该工具的详细信息。但是,该应用程序很可能在父窗口上下文上自行绘制它们,在这种情况下,您无法获取窗口句柄,因为它们不是真正的窗口。
Use Spy++ shipped with Visual Studio (or any other similar tool) to see if these buttons are actually windows. If yes, see the detailed information about them using that tool. However, it's very likely that this app draws them by itself on the parent window context, in which case you can't get the window handle because they are not real windows.
简而言之,我认为你做不到。越来越多的 Windows 应用程序正在使用 GUI 框架,这些框架不使用离散的子窗口呈现控件。 Ribbon UI 框架似乎就是其中之一。
枚举不使用子窗口的应用程序中的控件的唯一方法是使用辅助功能 API:Windows Automation API:UI Automation 是文档中的起点。
Simply put, I don't think you can. More and more windows applications are using GUI frameworks that do not render controls with discreet child windows. The Ribbon UI framework seems to be one of those.
The only way to enumerate controls in an application that doesn't use child windows is to use the accessibility APIs: Windows Automation API: UI Automation is the starting point in the documentation.
好吧,
所以确实不可能控制这些按钮。
我通过使用 SendKeys 发送激活按钮的键盘快捷键解决了这个问题。
就我而言,它是保存按钮,所以我使用了
“也许这可以为其他有同样问题的人带来想法:)
Gr,
LDX
Okay,
So it was indeed not possible to get a handle on these buttons.
I solved this by using SendKeys to send the keyboard-shortcut that activates the button.
In my case it was the save button, so I used
Maybe this can spawn ideas for other people with the same problem :)
Gr,
ldx
您可以拥有称为功能区的窗口句柄。
但你无法控制所谓的按钮。
从逻辑上讲:你怎么称呼句柄?你想要一个 HWND 吗?如果您想要一个 HWND,那么您需要一个窗口...但您拥有的唯一窗口是功能区。
这称为无窗口编程。
但是,您可以使用 COM 技术组件:COM 接口 I可访问。
You can have the handle of the window that you call a ribbon.
But you can't have a handle on what you call a button.
Logically: what do you call a handle ? do you want a HWND ? If you want a HWND then you need to a a window... but the only window you have is the ribbon.
This is called windowless programming.
However you could use a COM technology component: the COM interface IAccesible.
也许这可以提供一些指导?
http://msgroups.net/microsoft .public.excel.programming/获取特定按钮-Handle-inside-ribbon
may be this could give some guidance?
http://msgroups.net/microsoft.public.excel.programming/Get-a-specifc-button-Handle-inside-ribbon