日期:2014-05-17 浏览次数:20791 次
[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.Slee