Why doesn't FindWindowEx find all my buttons?

喜夏-厌秋 提交于 2020-07-22 08:33:34

问题


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.

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
      );

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.

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.

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!


回答1:


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?

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.



来源:https://stackoverflow.com/questions/14860155/why-doesnt-findwindowex-find-all-my-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!