簡體   English   中英

如何使用c#獲取另一個應用程序中主窗口的子進程狀態(活動或不活動)

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

我有一個客戶端應用程序,在菜單選項卡中具有一些選項卡,如下所示 在此處輸入圖片說明 選擇瀏覽標簽后,我需要執行一些操作。 我如何在我的應用程序中獲取該事件。 我想編寫自己的應用程序來執行此操作。 我以這種方式嘗試

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

當“瀏覽”選項卡處於活動狀態時,我想顯示一些消息。 請幫我。

如果您使用的是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