2012-08-10 144 views

回答

1

你可以試試這個PInvoke的電話:

[DllImport("User32")] extern IntPtr GetTopWindow(IntPtr hWnd); 
[DllImport("User32")] extern IntPtr GetNextWindow(IntPtr hWnd, uint wCmd); 

,並以此作爲參數

uint GW_HWNDNEXT = 2; 

所以首先得到頂部窗口(或你的)。在那次調用GetNextWindow和一次又一次的結果句柄之後,...所以你會得到所有的窗口

+0

你實際上不能調用'GetNextWindow',因爲它是'GetWindow'的子函數(它應該被調用相反),有點誤導。 :) – Edgar 2017-04-01 11:47:56

0

您可以使用GetNextWindow函數獲取下一個或上一個窗口(z順序)。

編輯:我剛纔在pinvoke.net上看到GetNextWindow是一個宏GetWindow。從pinvoke.net

代碼:所以你還不如直接調用GetWindow

[DllImport("user32.dll", SetLastError = true)] 
static extern IntPtr GetWindow(IntPtr hWnd, GetWindow_Cmd uCmd); 

enum GetWindow_Cmd : uint { 
    GW_HWNDFIRST = 0, 
    GW_HWNDLAST = 1, 
    GW_HWNDNEXT = 2, 
    GW_HWNDPREV = 3, 
    GW_OWNER = 4, 
    GW_CHILD = 5, 
    GW_ENABLEDPOPUP = 6 
}