繁体   English   中英

FindWindowEx没有运行

[英]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.

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