简体   繁体   English

如何使用c#获取另一个应用程序中主窗口的子进程状态(活动或不活动)

[英]How to get Child Process state(active or not) of a main window in another application using c#

I've a client application which having some tabs in the menu tab as follows 我有一个客户端应用程序,在菜单选项卡中具有一些选项卡,如下所示 在此处输入图片说明 .I need to perform some action when the browse tab is selected. 选择浏览标签后,我需要执行一些操作。 how can i get that event in my application. 我如何在我的应用程序中获取该事件。 i want to write my own application to perform this action. 我想编写自己的应用程序来执行此操作。 I tried in this way 我以这种方式尝试

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

I want to dispaly some message when Browse tab is active. 当“浏览”选项卡处于活动状态时,我想显示一些消息。 Please help me. 请帮我。

If you are using tabcontrol, below is the code to know which tabpage is selected by user. 如果您使用的是tabcontrol,下面的代码将知道用户选择了哪个选项卡页。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM