[英]FindWindowEx is not running
我的API Windows函數FindWindowEx遇到問題,實際上我獲得了進程MainWindow的句柄,但是當我嘗試使用FindWindowEx檢索其按鈕之一的句柄時,它沒有運行。 我已經用spy ++驗證了窗口及其按鈕,並且一切運行良好,即使程序返回的主窗口的句柄也與spy ++的句柄匹配。 我已經測試了由“ Marshal.GetLastWin32Error()”返回的錯誤代碼,我始終會收到錯誤1008。我已經搜索了很多處理我的問題的舊帖子,但是我沒有找到任何解決方案。 這是我的代碼:
DllImport("user32.dll" , CharSet = CharSet.Auto)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
// ....
IntPtr hwnd = proc.MainWindowHandle;
string str = proc.MainWindowTitle;
Console.WriteLine("Main window Title : " + str);
Console.WriteLine("Main window Handle : " + hwnd.ToString());
//Get a handle for the "suivant" button
IntPtr hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "Button", "suivant" );
int error = Marshal.GetLastWin32Error() ;
正如Hans Passant先生所說,類名是不可預測的,因此解決方案是不在FindWindowEx函數中指定類名,以便在主窗口中獲取所有控件句柄,我們可以使用:
do {
IntPtr hwndchild = FindWindowEx(hwndparent, hwndchild , null, null) ;
}while( hwndchild != IntPtr.Zero );
我們可以在主窗口中找到“輔助”按鈕的句柄:
IntPtr hwndchild = FindWindowEx(hwnd, hwndchild , null, "suivant") ;
謝謝您的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.