1、我用API抓取程序标题,得到的结果与程序显示的不一致。
2、得到当前窗体句柄的情况下,如何判断窗体中的控件的状态是否可见。
希望可以得到大牛的指点!谢谢!

解决方案 »

  1.   

    GetWindowText()
    和SPY++抓到的比较下。有些窗口的“标题栏”根本不是标题栏,而是程序模拟出来的。比如用一个无标题的窗口,顶部用static控件自己绘制的。
      

  2.   

    using System;
    using System.Runtime.InteropServices;namespace ConsoleApplication1
    {
        public class Program
        {
            [DllImport("shell32.dll")]
            static extern IntPtr ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);        [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);        [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);        [DllImport("user32.dll")]
            static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);        static void Main()
            {
                // 打开计算器
                ShellExecute(IntPtr.Zero, "open", "calc.exe", "", "", 1);            // 获取计算器窗体的够本
                IntPtr hMain = IntPtr.Zero;
                for (int i = 0; i < 2; i++)
                {
                    hMain = FindWindow("CalcFrame", "计算器");
                    if (hMain != IntPtr.Zero)
                    {
                        break;
                    }                System.Threading.Thread.Sleep(500);
                }            // 获取文本框的句柄
                IntPtr hChild = FindWindowEx(hMain, IntPtr.Zero, "CalcFrame", "");
                if (hChild != null)
                {
                    // 设置隐藏
                    ShowWindow(hChild, 0);
                }            Console.ReadKey();
            }
        }
    }
    以上代码可以隐藏calc的按键。但不知道怎么做可以判断控件的状态是隐藏还是显示的?
      

  3.   


            [DllImport("user32.dll ", EntryPoint = "IsWindowVisible")]
            private static extern bool IsWindowVisible(IntPtr hwnd);