0
我試圖操縱特定的Internet Explorer 11窗口。使用WinSpy ++我發現EnumChildWindows永遠不會調用它的回調
- 頂層窗口的類是與文檔的標題作爲文本的IEFrame(由GetWindowText函數返回)
- 實際的Web視圖類被稱爲「互聯網Explorer_Server」,是前者的孩子。
我寫了一個簡單的測試案例發現IE11的Web視圖以三種不同方式開了「https://encrypted.google.com/」:
HWND FindIE_A()
{
// Use FindWindow, works!
HWND hWndTop = ::FindWindowA(NULL, "Google - Internet Explorer");
// Find the web view window, the callback (FindIEServer) is NEVER called!
HWND hWnd = NULL;
::EnumChildWindows(hWndTop, &FindIEServer, (LPARAM)&hWnd);
return hWnd;
}
HWND FindIE_B()
{
// Use EnumChildWindows with NULL as parent, works!
HWND hWndTop = NULL;
::EnumChildWindows(NULL, &FindIEMain, (LPARAM)&hWndTop);
// Find the web view window, the callback (FindIEServer) is NEVER called!
HWND hWnd = NULL;
::EnumChildWindows(hWndTop, &FindIEServer, (LPARAM)&hWnd);
return hWnd;
}
HWND FindIE_C()
{
// Simple EnumWindows, works!
HWND hWndTop = NULL;
::EnumWindows(&FindIEMain, (LPARAM)&hWndTop);
// Find the web view window, the callback (FindIEServer) is NEVER called!
HWND hWnd = NULL;
::EnumChildWindows(hWndTop, &FindIEServer, (LPARAM)&hWnd);
return hWnd;
}
是非常簡單的回調;當父窗口提供
BOOL CALLBACK FindIEServer(HWND hWnd, LPARAM lParam)
{
char className[64];
::GetClassNameA(hWnd, className, sizeof(className));
if (!strcmp(className, "Internet Explorer_Server"))
{
*(HWND*)lParam = hWnd;
return FALSE;
}
return TRUE;
}
BOOL CALLBACK FindIEMain(HWND hWnd, LPARAM lParam)
{
char text[128];
::GetWindowTextA(hWnd, text, sizeof(text));
if (!strcmp(text, "Google - Internet Explorer"))
{
*(HWND*)lParam = hWnd;
return FALSE;
}
return TRUE;
}
EnumChildWindows失敗(通過不調用回調在所有!)每次:您可以通過窗口的屬性和比較反對的硬編碼值。爲什麼?
我不知道你的最終目標是什麼,但你可能最好使用通過COM的IE自動化。有關示例,請參閱http://support.microsoft.com/kb/167658 – wakjah 2014-09-20 00:11:57
也許Internet Explorer不希望您僞造它的子項。 – 2014-09-20 00:16:25
您是否試圖在網頁中獲取控件,例如Web窗體中的控件?如果是這樣,你應該知道[這些不是真正的窗口句柄的真正控制,而是IE模擬真正的控制](http://blogs.msdn.com/b/oldnewthing/archive/2005/02/11/371042。 ASPX)。 – andlabs 2014-09-20 00:23:01