【问题标题】:How to get Child Process state(active or not) of a main window in another application using c#如何使用 c# 在另一个应用程序中获取主窗口的子进程状态(活动与否)
【发布时间】:2016-06-10 09:29:02
【问题描述】:

我有一个客户端应用程序,它在菜单选项卡中有一些选项卡,如下所示。我需要在选择浏览选项卡时执行一些操作。我怎样才能在我的应用程序中获得该事件。我想编写自己的应用程序来执行此操作。我是这样尝试的

int chars = 256;
                StringBuilder buff = new StringBuilder(chars);
                // Obtain the handle of the active window.
                IntPtr handle = GetForegroundWindow();
                if (GetWindowText(handle, buff, chars) > 0)
                {
                   if (buff.ToString() == mainWindowName)
                    {
                        IntPtr WndToFind = FindWindowByCaption(IntPtr.zero, "Browse");
                        if(WndToFind != IntPtr.Zero)
                        {
                            MessageBox.Show("Inside Browse");
                        }     
                    }
                }

我想在浏览选项卡处于活动状态时显示一些消息。请帮帮我。

【问题讨论】:

  • 这个是选项卡控件还是菜单控件?
  • 它是一个客户端工具。所以我们不知道应用程序内部的组件。

标签: c# .net window-handles


【解决方案1】:

如果您使用的是tabcontrol,下面是知道用户选择了哪个标签页的代码。

 private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
 {          
      if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage2"])
      {
           ...add your code here
      }
  }

【讨论】:

  • 我需要从我的应用程序访问另一个应用程序的 tabcontrol。
猜你喜欢
  • 2012-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-25
  • 2011-08-06
  • 1970-01-01
相关资源
最近更新 更多