检索窗口句柄然后按下按钮编程方式 [英] Retrieve Window Handle and Press Button Programatically

查看:129
本文介绍了检索窗口句柄然后按下按钮编程方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定,这是可能以某种方式,但不知道是否有一个数太多箍跳通过,使其值得的,希望有人会指出我在正确的方向。我有一个问题(与安装程序),由此我相当有规律,我需要按取消有一个对话框弹出。

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:

  • 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 suffice btnCancel.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屋!

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