-2

I'm using FindWindow() and FindWindowEx() to control an application. There are 2 buttons in the application, one named "I Agree" and the second "Cancel". I can find the "Cancel" button but can't find the "I Agree" button.

I'm using FindWindow() to find the application, and I store the window's process in the hwnd variable. Then I do this to find and get a button:

hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "Button", "Cancel");

Why can't I find the "I Agree" button, but I can find the "Cancel" button?.

The Buttons in the application.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Flafy
  • 176
  • 1
  • 3
  • 15
  • try the following: hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "Button", null); – demoncrate Dec 11 '19 at 09:07
  • 4
    If you're wanting to control another application, have you considered using something like UI Automation which lets you work at a *higher level* than fiddling around with raw windows, etc? – Damien_The_Unbeliever Dec 11 '19 at 09:09
  • That *"higher level"* also allows you to automate applications, that do not use controls backed by native windows. Very common with web browsers. Or WPF and UWP applications. – IInspectable Dec 11 '19 at 12:07
  • Use a tool like Spy++/Inspect to capture the window details..like window name and class correctly. – Ashutosh Raina Dec 12 '19 at 07:10

1 Answers1

2

The "I Agree" button is actually "I &Agree". Check out this to find out why. Thanks!

Flafy
  • 176
  • 1
  • 3
  • 15