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}"); }
关掉的是主窗口,而不是画图窗口。
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}"); }
关掉的是主窗口,而不是画图窗口。
要想关掉mapaint,需要postmessage。
process.WaitForInputIdle(); //<---
string cap = "nihao(" + i + ").jpg" + " - 画图";
...
不要总是说“还是不行啊”
它没有增加有用的信息。要学会怎么定位错误。
比如如果handle还是零,那就试试开一个固定的窗口,检测FindWindow是否工作正常...