[英]EnumChildWindows never calls its callback
我正在嘗試操縱特定的Internet Explorer 11窗口。 使用WinSpy ++,我發現
我編寫了一個簡單的測試用例,用於查找以三種不同方式在“ https://encrypted.google.com/ ”上打開的IE11的網絡視圖:
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都會失敗(通過不調用回調AT!)。 為什么?
問題是,當我尋找窗口標題時,我假設只有一個帶有該標題的窗口。 但是,Internet Explorer會執行一些詭計,並創建多個具有相同標題的窗口,但是其中只有一個具有IEFrame類。
碰巧的是,找到的第一個窗口是錯誤的窗口,它沒有任何子窗口(因此EnumChildWindows沒有任何要迭代的窗口)。 只需添加一個額外的檢查標題+類的作品。
但是,正如@wakjah所建議的那樣,最好將IE(或任何其他瀏覽器)直接集成到您的代碼中。 在google上,我找到了很多有關如何通過IE和Chrome進行此操作的文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.