C#判斷某程序是否運(yùn)行的方法
更新時(shí)間:2014年09月29日 11:05:33 投稿:shichen2014
這篇文章主要介紹了C#判斷某程序是否運(yùn)行的方法,代碼結(jié)構(gòu)簡(jiǎn)單功能實(shí)用,需要的朋友可以參考下
本文實(shí)例講述了C#判斷某程序是否運(yùn)行的方法,分享給大家供大家參考。
具體實(shí)現(xiàn)方法如下:
[DllImport("user32.dll")]
private static extern bool
SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd);
// 消息函數(shù)
[DllImport("user32.dll", EntryPoint = "PostMessageA")]
public static extern bool PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string strclassName, string strWindowName);
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MAXIMIZE = 0xF030;
private string exeName = "SaoMiaoApp";
public void SetForm()
{
Process[] processes = Process.GetProcessesByName(exeName);
if (processes.Length > 0)
{
IntPtr hWnd = processes[0].MainWindowHandle;
if (IsIconic(hWnd))
ShowWindowAsync(hWnd, 9);// 9就是SW_RESTORE標(biāo)志,表示還原窗體
//SendMessage(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
SetForegroundWindow(hWnd);
}
else
{
Process.Start(exeName + ".exe");
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
用C#的params關(guān)鍵字實(shí)現(xiàn)方法形參個(gè)數(shù)可變示例
params關(guān)鍵字以實(shí)現(xiàn)方法形參個(gè)數(shù)可變是C#語法的一大優(yōu)點(diǎn),下面是用C#中的params關(guān)鍵字實(shí)現(xiàn)方法形參個(gè)數(shù)可變2014-09-09
C# 實(shí)現(xiàn)Trim方法去除字符串前后的所有空格
這篇文章主要介紹了C# 實(shí)現(xiàn)Trim方法去除字符串前后的所有空格,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-12-12
Unity使用DoTween實(shí)現(xiàn)拋物線效果
這篇文章主要為大家詳細(xì)介紹了Unity使用DoTween實(shí)現(xiàn)拋物線效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-05-05
C#使用Aspose.Cells創(chuàng)建和讀取Excel文件
這篇文章主要為大家詳細(xì)介紹了C#使用Aspose.Cells創(chuàng)建和讀取Excel文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-10-10
C# IDE VS2005中的Hosting Process (vshost.exe)作用介紹
這篇文章主要介紹了C# IDE VS2005中的Hosting Process (vshost.exe)作用介紹,vshost.exe是一個(gè)宿主進(jìn)程,主要用來提高調(diào)試效率,需要的朋友可以參考下2015-01-01

