简体   繁体   English

FindWindowEx没有运行

[英]FindWindowEx is not running

I have a problem with the API windows function FindWindowEx, in fact I obtain the handle of the MainWindow of the process, but when i try to retrieve the handle of one of its buttons with FindWindowEx, it's not running. 我的API Windows函数FindWindowEx遇到问题,实际上我获得了进程MainWindow的句柄,但是当我尝试使用FindWindowEx检索其按钮之一的句柄时,它没有运行。 I had verified the window and its buttons with spy++, and everything runs well, even the handle of the mainwindow returned by my program matches the spy++'s one. 我已经用spy ++验证了窗口及其按钮,并且一切运行良好,即使程序返回的主窗口的句柄也与spy ++的句柄匹配。 i have tested the error code returned by "Marshal.GetLastWin32Error()", i always obtain error 1008. i have searched in many old posts dealing with my problem, but i hadn't find any solution for it. 我已经测试了由“ Marshal.GetLastWin32Error()”返回的错误代码,我始终会收到错误1008。我已经搜索了很多处理我的问题的旧帖子,但是我没有找到任何解决方案。 here is my code : 这是我的代码:

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() ; 

as Mr Hans Passant say, the class name is unpredictable, so the solution is to not specify the class name in the FindWindowEx function so to obtain all the controls handles in the mainwindow we can use : 正如Hans Passant先生所说,类名是不可预测的,因此解决方案是不在FindWindowEx函数中指定类名,以便在主窗口中获取所有控件句柄,我们可以使用:

do {
           IntPtr hwndchild = FindWindowEx(hwndparent, hwndchild , null, null) ;
        }while( hwndchild != IntPtr.Zero );

and we can find the handle of the "suivant" button in the main window : 我们可以在主窗口中找到“辅助”按钮的句柄:

IntPtr hwndchild = FindWindowEx(hwnd, hwndchild , null, "suivant") ;

Thank you for your help. 谢谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM