检索窗口句柄然后按下按钮编程方式 [英] Retrieve Window Handle and Press Button Programatically
问题描述
我敢肯定,这是可能以某种方式,但不知道是否有一个数太多箍跳通过,使其值得的,希望有人会指出我在正确的方向。我有一个问题(与安装程序),由此我相当有规律,我需要按取消有一个对话框弹出。
I'm sure this is possible somehow, but not sure if there are a few too many hoops to jump through to make it worthwhile, hoping someone might point me in the right direction. I've got a problem (related to an installer) whereby I have a dialog popup quite regularly which I need to press cancel on.
我想怎么办接近它编程/通过服务也许因此它在我的方式得到停止(假设我不能修复的根本问题)。所以,我想知道是,如果有一种方法可以抓住一个手柄以某种方式的窗口(检查它是正确的,也许这样做在标签上的文本比较),然后在窗口中定位控制(取消按钮),并发送事件呢?
What I'd like to do is close it programatically/maybe via a service so it stops getting in my way (assuming I can't fix the root issue). So, what I'm wondering is if there is a way to grab a handle to the window somehow (checking it's correct maybe by doing a text comparison on the label), then locating a control on the window (cancel button) and sending an event to it?
如果有谁知道我怎么可能做到这一点还是有些新手那简直太好了。
If anyone knows how I might achieve this or some starters that'd be great.
推荐答案
两种方法可以做到这一点:
Two ways to do this:
- 要获取句柄,当你谈论一个窗口,使用 FindWindow函数API 的,那么你就必须列举与之相关的控件处理,并发送消息WM_BUTTONDOWN,WM_BUTTONUP在一起,通过使用 SendMessage函数模拟鼠标点击一>。
- 但更简单的方法存在,假设取消按钮被称为
btnCancel
,那么这将足以btnCancel。点击()
。
- To get the handle, when you talk about a window, use the FindWindow API, then you would have to enumerate the controls associated with that handle, and send a message WM_BUTTONDOWN, WM_BUTTONUP together to simulate a mouse click via using a SendMessage.
- But the simpler method exists, suppose the cancel button is called
btnCancel
, then this would sufficebtnCancel.Click()
.
除非我错了,你是在谈论一个过程的一个窗口,是不是你的,那么我的第一个建议做。既然你不说,如果你是在谈论自己的应用程序或进程的窗口,是不是你的...那么奥利弗的建议可能会更容易...
Unless I am mistaken, that you are talking about a window of a process that is not yours, then my first suggestion would do. Since you did not say, if you are talking about your own application or a process's window that is not yours...then Oliver's suggestion might be easier...
不过,这引出了一个问题:为什么你要这么做,你是假设有一个取消按钮某处...
But that begs the question: why would you want to do that as you are assuming there is a Cancel button somewhere...
希望这可以帮助,
此致,
汤姆。
Hope this helps, Best regards, Tom.
这篇关于检索窗口句柄然后按下按钮编程方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!