C#使用API的问题-求助 1、我用API抓取程序标题,得到的结果与程序显示的不一致。2、得到当前窗体句柄的情况下,如何判断窗体中的控件的状态是否可见。希望可以得到大牛的指点!谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 GetWindowText()和SPY++抓到的比较下。有些窗口的“标题栏”根本不是标题栏,而是程序模拟出来的。比如用一个无标题的窗口,顶部用static控件自己绘制的。 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的按键。但不知道怎么做可以判断控件的状态是隐藏还是显示的? [DllImport("user32.dll ", EntryPoint = "IsWindowVisible")] private static extern bool IsWindowVisible(IntPtr hwnd); winform单例模式问题。。。 怎样解决winform程序占用内存高的问题! 用vs2005做网站 出现了一个错误 web窗体的问题 如何获取当前日期前一个月或两个月的日期! 请教new和override 怎样给mssqlserver系统表创建触发器? 如何让我写的Xml文件第一行 xml读取求救啊! 安装项目,怎么取消自动安装.net 框架? Excel如何导入到现有SQL中? C#串口通信接收数据部完整
和SPY++抓到的比较下。有些窗口的“标题栏”根本不是标题栏,而是程序模拟出来的。比如用一个无标题的窗口,顶部用static控件自己绘制的。
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的按键。但不知道怎么做可以判断控件的状态是隐藏还是显示的?
[DllImport("user32.dll ", EntryPoint = "IsWindowVisible")]
private static extern bool IsWindowVisible(IntPtr hwnd);