从另一个应用程序访问 Winforms 中的控制状态 [英] Access the state of control in Winforms from another application

查看:24
本文介绍了从另一个应用程序访问 Winforms 中的控制状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 (Myapp.exe) 的示例 winform 应用程序,其中包含一个表单和一个按钮.我将从另一个应用程序启动此应用程序 (.exe).

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

我的问题是.从另一个应用程序(控制台或 winform)启动(Myapp.exe)应用程序后,我需要访问(Myapp.exe)应用程序中按钮的状态.这是怎么实现的??是否可以?任何人都可以取悦我吗.

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.

推荐答案

这是可能的,但你需要意识到,从外部的角度来看,按钮是一个窗口(带有句柄),其父级是窗体(也是一个带有句柄的窗口),并且它的状态可能无法使用与 WinForms 中的属性显示的非常相同的有用名称来访问.

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.

例如,此 C++ 代码将在 C# 应用程序上运行,即使该应用程序正在通过调试器运行:

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

    }

}

这篇关于从另一个应用程序访问 Winforms 中的控制状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆