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}"); }
关掉的是主窗口,而不是画图窗口。
解决方案 »
- 问下webBrowser控件的问题
- .net中怎么把文件存入数据库
- 将文本框中的值锁定几秒钟
- 关于在服务器创建文件夹的问题
- asp.net
- 请问Winform里怎么手动设置combobox的实际值
- 做了一个程序,启动太慢,想在启动时新开一个界面,让这个界面先显示十几秒后关闭。
- 求教windows系统里格式化u盘为linux ext3.哪位高手愿意做赏金猎人?
- Image.FromStream(ms) 参数失效问题
- DBGrid 控件中有没有可以利用下拉式的功能 加快用户的输入 例如“省份”等等,急切?其他控件呢?
- C#调用DLL是否会大幅度影响程序性能?
- 如何让DataGridView的某一格设为DataGridViewComboBoxCell属性。而不用设置整个列为combox
要想关掉mapaint,需要postmessage。
process.WaitForInputIdle(); //<---
string cap = "nihao(" + i + ").jpg" + " - 画图";
...
不要总是说“还是不行啊”
它没有增加有用的信息。要学会怎么定位错误。
比如如果handle还是零,那就试试开一个固定的窗口,检测FindWindow是否工作正常...