0

i wonder if its possible to create application that somehow look through all opened in windows(7,8,10) system forms(not only main forms but also its inside open forms) ? eg i have some application open and in it i have some forms is it possible to check if form of certain type is opened (or form that have ceratin text in form.text property. Or any other idea how to get info about what forms in application are open ? :)

I once have seen application, create by some guy, that app can open certain windows and click certain buttons in other application. that guy can't know what are name for forms or its buttons for that other application, so he must have checeked somehow which forms are opened in that other app and what controls it has.

So another question is how to check controls on opened forms (especiali i need to read some data from certain text fields from form that has certain text in header of window. ) . I pressume he use winapi but could you provide a help how to do that from c#?

Thanks for help:)

romeck
  • 23
  • 5
  • Every form is a window and windows can be traversed by api. So, it is up to you identify your window. In the easiest case, that can be done by the caption. – Dieter Meemken Apr 13 '16 at 06:31

1 Answers1

0

Have a look at EnumWindows function

https://msdn.microsoft.com/en-us/library/windows/desktop/ms633497(v=vs.85).aspx

And you can enumerate all windows (given by their handles - HWND) like that:

using System.Runtime.InteropServices;
....

[return: MarshalAs(UnmanagedType.Bool)]
private delegate Boolean EnumerationCallback(IntPtr handle, IntPtr parameter);

[DllImport("User32.dll",
           CallingConvention = CallingConvention.Winapi,
           ExactSpelling = true,
           EntryPoint = "EnumWindows",
           CharSet = CharSet.Unicode,
           SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern Boolean EnumWindows(
  EnumerationCallback lpEnumFunc,
  IntPtr lParam);

...

EnumWindows((handle, p) => {
    //TODO: put relevant code here

    return true;
  }, 
  IntPtr.Zero);

You may want EnumChildWindow API function as well

https://msdn.microsoft.com/en-us/library/windows/desktop/ms633494(v=vs.85).aspx

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
  • Thanks all for helpfull comments. I use it and besides i learn a lot about pinvoke and helpfull tools like Spy++ :) – romeck Apr 19 '16 at 07:53