日期:2014-05-17  浏览次数:21136 次

用FindWindowEx无法获取句柄
FindWindow返回了主窗口的句柄,但是FindWindowEx无法获取按钮的句柄


IntPtr ptrMainWnd = FindWindow(null,this.Text);
            if (ptrMainWnd == IntPtr.Zero)
            {
                MessageBox.Show("No main window found");
                return;
            }

            IntPtr ptrStartBtn = FindWindowEx(ptrMainWnd, IntPtr.Zero, null, buttonStart.Text);
            if (ptrStartBtn == IntPtr.Zero)
            {
                MessageBox.Show("No start button found.");
                return;
            }

------解决方案--------------------
http://wcb0414.blog.163.com/blog/static/449938242010102895118974/
这个可以啊,你看你还差哪儿
------解决方案--------------------
buttonStart必须直接位于窗体上,而不能装在Panel、GroupBox等之内。
用SPY++看下。
------解决方案--------------------
这个你用spy++看看就行了,肯定是按钮的父窗体不是你找的那个,还有既然是用c#就别掉这些win32api了,有现成的uiautomation比这些好用多了