保证程序单实例运行
来源:互联网 发布:awk 数组 编辑:程序博客网 时间:2024/05/21 13:23
#region 保证程序单实例运行 modified by ychh
private const int WS_SHOWNORMAL = 1;
public const Int32 AW_BLEND = 0x00080000;
[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("User32.dll")]
private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
public static Process GetRunningInstance()
{
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(current.ProcessName);
foreach (Process process in processes)
{
if (process.Id != current.Id)
if (Assembly.GetExecutingAssembly().Location.Replace("/", "//") == current.MainModule.FileName)
return process;
}
return null;
}
public static void HandleRunningInstance(Process instance)
{
if (instance != null && instance.MainWindowHandle.ToInt32() != 0)
{
//MessageBox.Show(instance.MainWindowHandle.ToInt32().ToString());
string windowTile = instance.MainWindowTitle.Trim();
if (windowTile == "广东省林业有害生物管理信息系统")
ShowWindowAsync(instance.MainWindowHandle, 3);
else
ShowWindowAsync(instance.MainWindowHandle, 1);
SetForegroundWindow(instance.MainWindowHandle);
}
else
{
IntPtr hwnd = FindWindow(null, "广东省林业有害生物管理信息系统");
if (hwnd.ToInt32() == 0)
{
hwnd = FindWindow(null, "用户登录");
ShowWindowAsync(hwnd, 1);
SetForegroundWindow(hwnd);
}
else
{
ShowWindowAsync(hwnd, 3);
SetForegroundWindow(hwnd);
}
}
}
#endregion
- 保证程序单实例运行
- 单实例运行程序
- 程序单实例运行
- 保证程序只运行一个实例(delphi)
- shell保证一个程序实例在运行
- 保证程序只有一个运行实例
- hs程序之启动(保证程序单实例、 程序自启动、判断程序是否有实例运行、查找对话框窗体)
- 使程序单实例运行
- WINCE程序单实例运行
- c++程序单实例运行
- c++程序单实例运行
- 保证一个实例运行
- 保证系统中只运行一个程序实例
- 保证程序只运行一个实例问题总结
- QT 保证Qt程序只运行一个实例
- QT 保证Qt程序只运行一个实例
- 使用互斥量保证程序最多只有一个实例运行
- Delphi----怎样保证程序只运行一个实例
- SourceInsight一个不错的配置文件下载地址
- 事件传播和冒泡事件
- 软件测试--术语、名词定义
- 项目管理过程:制定工作分解结构
- CALLBACK回调函数使用之三
- 保证程序单实例运行
- php-addslashes、stripslashes、魔术引号(字符串转义)
- 软件命名规范
- WCF与STA COM互操作
- 测试任务描述
- PHP报表地址
- 我学spring的一点小总结(—)
- ORACLE to_char函数详解
- 在Eclipse中反编译Class文件完全详解