2010-03-20 28 views
0

是的,我想獲得另一個應用程序的子窗口。 給我總的想法或代碼如何獲取CurrentWindow?

+0

這不完全清楚自己想要做什麼。你想獲得應用程序或其他應用程序的頂級窗口嗎?或者你想要一個孩子的窗戶?如果是的話,你想得到哪個孩子(因爲通常有多個孩子)?那麼如何指定子窗口?通過它的類名? –

+0

是的,我想獲得另一個應用程序的子窗口。 給我總結的想法或代碼 – Sarvesh

回答

1

這裏是你如何可以使用FindWindow檢索把手給定標題的窗口:

class Program 
{ 
    [DllImport("user32.dll", SetLastError = true)] 
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 

    static void Main(string[] args) 
    { 
     var hWnd = FindWindow(null, "Untitled - Notepad"); 
     if (hWnd != IntPtr.Zero) 
     { 
      Console.WriteLine("window found"); 
     } 
     else 
     { 
      Console.WriteLine("No window with given title has been found"); 
     } 
    } 
} 
+0

@Sarvesh:在你的評論中,你表示你想要檢索一個子窗口。但請注意,上述示例爲您提供了另一個應用程序的*頂級*窗口的句柄。爲了更好地理解你可能想用Spy ++玩一下的差異。 –