为什么FindWindowEx找不到我所有的按钮? [英] Why doesn't FindWindowEx find all my buttons?

查看:527
本文介绍了为什么FindWindowEx找不到我所有的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该写一个自动安装程序.只是您启动的程序,它应该独自通过安装向导,而无需用户触摸任何东西.

I'm supposed to write an automatic Installer. Just a programme you start and it should go through the installation wizard all by itself, without the user touching anything.

我目前正在开发的程序称为Cygwin.而我要做的就是一遍又一遍地单击下一步"按钮,直到安装完成.我知道我可以使用VBS,也知道我可以使用C#,这会使我的生活变得更加轻松.但是我有一个示例说明它如何在另一个程序中工作,我正在尝试使其适应C ++中的Cygwin.

The programme I'm working on at the moment is called Cygwin. And what I want to do is just click the "Next" Button over and over again until the installation is finished. I know I could use a VBS and I know I could use C# and that would make life quite a bit easier for me. But I have an example of how it could work for another programme and I'm trying to adapt it for Cygwin in C++.

    HWND WINAPI FindWindowEx(
      _In_opt_  HWND hwndParent,
      _In_opt_  HWND hwndChildAfter,
      _In_opt_  LPCTSTR lpszClass,
      _In_opt_  LPCTSTR lpszWindow
      );

这是我用来查找按钮的功能,下一步应该单击它. 我在hwndParent中有程序窗口,并且工作正常. hwndChildAfter和lpszClass为"NULL",而lpszWindow是按钮的名称.适用于"Abbrechen"按钮(德语为取消").但是,当我将该名称更改为"Weiter"(德语为Next)时,它不再起作用.他只是没有找到它. 我认为这与"Weiter"的编写方式有关.它不仅是唯一的词.整个表达式为"Weiter>" 当然,我将整个表达式放在lpszWindow中,并带有",就像使用"Abbrechen"一样. 但是就像我说的,他没有找到它.我已经尝试过编写它的所有方式,但是都行不通.

This is the function I'm using to find the button and in the next step it's supposed to be clicked. I have the programme window in hwndParent and that works fine. hwndChildAfter and lpszClass are "NULL" und lpszWindow is the name of the button. That works for the Button "Abbrechen" (German for Cancel). But when I change that name to "Weiter" (German for Next), it doesnt work anymore. He just doesn't find it. I think it has something to do with the way "Weiter" is written. Its not only the sole word. The whole expression is "Weiter >" Of course I put the whole expression in lpszWindow with "" around it, just like I did with "Abbrechen". But like I said, he doesn't find it. I've tried all the variations of writing it, but it doesn't work.

有人知道>"或"(空格)是否有问题,因此他无法阅读.如果是这样,是否有办法解决? 还是可以获得按钮的ID或类似的东西,可以用来告诉程序在哪里设置鼠标单击.

Does anyone know if the ">" or the " " (space) is a problem and he can't read it because of that. And if so, is there some way round it? Or is it possible to get the ID of the button or something similar that could be used to tell the programme where to set the mouse click.

正如我所说,我知道C ++并不是执行此任务的最佳语言,最后我想我会改用其他语言.但是我真的很想知道为什么它对"Abbrechen"有效,为什么对"Weiter>"不起作用.

I know, as I said, that C++ isn't really the best language for this task and in the end I guess I'll change to something else. But I'd really like to know why it works for "Abbrechen" and why it doesn't work for "Weiter >".

所以,如果有人有解决方案,我将不胜感激.谢谢!

So if someone has a solution I'd be very grateful. Thanks!

推荐答案

我怀疑按钮的 actual 文本不仅是"Weiter >",而且其中还包含&,用于加速键.尝试按Alt键,然后查看字母是否在其下带有反折号.如果是这样,则该字母以&为前缀.

I suspect that the actual text of the button isn't just "Weiter >" but also includes an & in there, for the accelerator key. Try pressing Alt and see if a letter appears with an undescore under it. If it does, then that letter is prefixed with an &.

这个解决方案"实际上非常脆弱,很容易被破坏.例如,如果用户在系统上配置了另一种语言怎么办?

This "solution" is actually pretty flimsy though and could easily break. For example, what if the user has another language configured on their system?

可以获取按钮的ID,该ID不太可能更改.但是您首先必须找到安装程序窗口,然后枚举其子窗口.要查找按钮的ID,请使用JosephH在其注释中建议的Spy ++.

It is possible to get the ID of the button, which would be unlikely to change. But you would first have to find the installer window and then enumerate its child windows. To find the ID of the button, use Spy++ as JosephH suggested in his comment.

这篇关于为什么FindWindowEx找不到我所有的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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