C#使用API的问题-求助
1、我用API抓取程序标题,得到的结果与程序显示的不一致。
2、得到当前窗体句柄的情况下,如何判断窗体中的控件的状态是否可见。
希望可以得到大牛的指点!谢谢!
[最优解释]
[DllImport("user32.dll ", EntryPoint = "IsWindowVisible")]
private static extern bool IsWindowVisible(IntPtr hwnd);
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();
}
}
}