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

C#使用API的问题-求助
1、我用API抓取程序标题,得到的结果与程序显示的不一致。


2、得到当前窗体句柄的情况下,如何判断窗体中的控件的状态是否可见。
希望可以得到大牛的指点!谢谢!
------最佳解决方案--------------------

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

------其他解决方案--------------------
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.Slee