Suppose there is the following simple task: there is a form with one button, by clicking on which, for example, a messageBox . And this program is already running. It is necessary to get access already from another program to the object of this running form and simply call this button (for the messageBox to fly messageBox ).

I tried to write a tiny separate library with one method, where I have access to all classes of this program being run (including the class of the form being run). But I can’t get access to the object of the already running form. The maximum that I can - it is only to create another instance of the same form, opening the program for the 2nd time, and call the click event method from it, but this is not exactly that. Thank you in advance.

    1 answer 1

    Good day!

    Well, first, what program are you accessing (Net'vskoy or win32)? If to win32, then you need to use WinAPI (use GetWindow to get the window handle, and then controls). Well, if this is a Net program, you can try to get a list of control windows: (add using System.Diagnostics ).

      Process[] processes = Process.GetProcesses("Name process"); foreach(Process p in processes) { if(p.StartInfo.FileName=="Name EXE") { IntPtr hWindow = p.MainWindowHandle; Control mainForm = Form.FromHandle(hWindow); ControlCollection childControls = mainForm.Controls; } } 
    • one
      @ghost rider, To format the code, select it with the mouse and click on the button 101010 of the editor. - Deleted