2

I have a sample winform application called (Myapp.exe) with a form and a button. I will launch this application (.exe) from another application.

My questions here is. After launching the (Myapp.exe) application from another application (console or winform), i need to access the state of the button in (Myapp.exe) application. How this is achieved?? Is it possible? Can any one please me on this.

Sanjaybxl
  • 63
  • 8

2 Answers2

1

It's possible, but you need to realise that from an outside point of view a button is a window (with a handle) whose parent is the form (also a window with a handle), and its state may not be accessible with quite the same useful names as the properties in WinForms show it.

For example, this C++ code will work on a C# app even if that app is being run through the debugger:

HWND hwndCSharp = ::FindWindow(NULL,_T("Form1") ); 
if (hwndCSharp != NULL) 
{
    // Walk the window's child windows (controls / views): 
    HWND hwndChild = ::GetWindow(hwndCSharp, GW_CHILD); 
    while (hwndChild != NULL) 
    {
        // Get state here... 

        hwndChild = ::GetWindow(hwndChild, GW_HWNDNEXT); 

    }

}
JTeagle
  • 2,196
  • 14
  • 15
0

this has already been discussed in stack.so here is just a same code just give it try.

  Application application = Application.Launch("Myapp.exe");
       Window window = application.GetWindow("bar", InitializeOption.NoCache);

       Button button = window.Get<Button>("button1");
       button.Click();
Subek Shakya
  • 595
  • 4
  • 10
  • 28