为什么有些控件没有 Windows 句柄? [英] How come some controls don't have a windows handle?

查看:53
本文介绍了为什么有些控件没有 Windows 句柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想得到一些控件的窗口句柄来用它做一些事情(需要一个句柄).控件位于不同的应用程序中.

I want to get the window handle of some controls to do some stuff with it (requiring a handle). The controls are in a different application.

奇怪的是;我发现许多控件没有 Windows 句柄,例如 Windows 资源管理器中工具栏 (?) 中的按钮.只需尝试获取文件夹/搜索/(等)按钮的句柄即可.它只给我 0.

Strangely enough; I found out that many controls don't have a windows handle, like the buttons in the toolbar (?) in Windows Explorer. Just try to get a handle to the Folder/Search/(etc) buttons. It just gives me 0.

那么.. 第一个问题:为什么有些控件没有窗口句柄?在他们心中不都是控制窗口吗?(只是谈论标准控件,就像我在 Windows 资源管理器中所期望的那样,没有在窗格或类似物上自定义绘制.)

So.. first question: how come that some controls have no windows handle? Aren't all controls windows, in their hearts? (Just talking about standard controls, like I would expect them in Windows Explorer, nothing customdrawn on a pane or the like.)

这让我想到了我的第二个问题:如果您无法控制他们,如何与他们合作(例如使用 EnableWindow)?

Which brings me to my second question: how to work with them (like using EnableWindow) if you cannot get their handle?

非常感谢您的意见!

编辑(附加信息):

Windows 资源管理器只是一个例子.我经常遇到这个问题 - 并且在不同的应用程序中(我真正感兴趣的应用程序,专有应用程序).我有物理"控件(因为我可以获得这些控件的 AutomationElement),但是它们没有窗口句柄.另外,我试图发送一条消息 (SendMessage) 来获取按钮状态,试图找出它是否被按下(它是一个标准按钮,似乎只有通过该消息才能表现出这种行为 - 至少就我已经看到了.此外,该按钮上的按下状态持续时间比您在标准按钮上预期的要长得多,尽管 Windows 资源管理器按钮显示出类似的行为,就像按钮样式的复选框,尽管它们是(按下)按钮).SendMessage 需要一个窗口句柄.

Windows Explorer is just an example. I have the problem frequently - and in a different application (the one I am really interested in, a proprietary one). I have "physical" controls (since I can get an AutomationElement of those controls), but they have no windows handle. Also, I am trying to send a message (SendMessage) to get the button state, trying to find out whether it is pushed or not (it is a standard button that seems to exhibit that behaviour only through that message - at least as far as I have seen. Also, the pushed state can last a lot longer on that button than you would expect on a standard button, though the Windows Explorer buttons show a similar behaviour, acting like button-style checkboxes, though they are (push)buttons). SendMessage requires a window handle.

ToolBar 是否会以某种方式改变其子元素的行为?拿走他们的窗户把手或类似的东西?(使用父句柄/控件 ID 进行标识??)但是如何在需要 Windows 句柄的控件上使用函数?

Does a ToolBar in some way change the behaviour of its child elements? Taking away their window handle or something similar? (Using parent handle/control id for identification??) But then how to use functions on those controls that require a windows handle?

推荐答案

如果它们没有句柄,它们就不是真正的控件,它们只是被绘制成看起来像控件.

If they don't have a handle, they're not real controls, they're just drawn to look like controls.

当然,Windows 资源管理器中的工具栏按钮确实有窗口句柄,它们是工具栏的一部分.使用工具栏操作函数与其交互,而不是EnableWindow.

But of course, the toolbar buttons in Windows Explorer do have window handles, they're part of a toolbar. Use the toolbar manipulation functions to interact with them, not EnableWindow.

或者,更好的是,使用已记录的 API 进行搜索等操作.对任何人来说,逆向工程 Windows 资源管理器从来没有有好结果,尤其是对于那些认为 API 适用于其他所有人的开发人员来说,多年来一直背负着向后兼容性黑客攻击的可怜的 Windows Shell 团队.无论你做什么设法开始工作,很可能会在下一版本的 Windows 上崩溃.

Or, better yet, use the documented APIs for things like search. Reverse-engineering Windows Explorer has never ended well for anyone, least of all the poor Windows Shell team, saddled with years of backwards-compatibility hacks for certain developers who thought that APIs are for everyone else. Whatever you do manage to get to work is very likely to break on the next version of Windows.

这篇关于为什么有些控件没有 Windows 句柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆