FindWindow找不到窗口
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string className, string windowName);
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool IsIconic(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool OpenIcon(IntPtr hWnd);
for (int i = 1; i <= number; i++)
{
textBox1.Text = folderBrowserDialog1.SelectedPath+"\\";
string path = textBox1.Text + "nihao(" + i + ").jpg";
Process.Start("mspaint.exe", path);
string cap = "nihao(" + i + ").jpg" + " - 画图";
IntPtr handle = FindWindow(null, cap);
if (handle != IntPtr.Zero)
{
//MessageBox.Show("nihao");
if (IsIconic(handle))
{
OpenIcon(handle);
}
else
{
SetForegroundWindow(handle);
Thread.Sleep(2000);
}
}
//SendKeys.Send("^S");
SendKeys.Send("%{F4}");
}
关掉的是主窗口,而不是画图窗口。