首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#使用API的有关问题

2012-12-26 
C#使用API的问题-求助1、我用API抓取程序标题,得到的结果与程序显示的不一致。2、得到当前窗体句柄的情况下,

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.Sleep(500);


            }

            // 获取文本框的句柄
            IntPtr hChild = FindWindowEx(hMain, IntPtr.Zero, "CalcFrame", "");
            if (hChild != null)
            {
                // 设置隐藏
                ShowWindow(hChild, 0);
            }

            Console.ReadKey();
        }
    }
}



以上代码可以隐藏calc的按键。但不知道怎么做可以判断控件的状态是隐藏还是显示的?
[其他解释]
谢谢 楼上的兄弟了!

热点排行