程序进入托盘,运行Exe打开窗口
2012-02-14 18:50
363 查看
程序进入托盘,运行Exe打开窗口,打开原先程序的窗口(未测试)
static class Program
{
private static string strProcessName = "Form1" ;
private static string strAppName = "WindowsFormsApplication1";
static int hWnd = 0;
const int SW_SHOW = 5;
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern int ShowWindow(int hwnd, int nCmdShow);
[DllImport("user32")]
public static extern int GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount); [DllImport("user32")]
public static extern int EnumWindows(CallBack x, int y);
public delegate bool CallBack(int hWnd, int lParam);
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Process[] ps = Process.GetProcessesByName(strAppName);
CallBack myCallBack = new CallBack(FineAppWindow);
EnumWindows(myCallBack, 0);
if (ps.Length > 1) { ShowWindow(hWnd, SW_SHOW); return;
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public static bool FineAppWindow(int hwnd, int lParam)
{
StringBuilder sb = new StringBuilder(200);
int n = GetWindowText(hwnd, sb, 200);
if (sb.ToString() == strProcessName)
{
hWnd = hwnd;
}
return true;
}
}
static class Program
{
private static string strProcessName = "Form1" ;
private static string strAppName = "WindowsFormsApplication1";
static int hWnd = 0;
const int SW_SHOW = 5;
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern int ShowWindow(int hwnd, int nCmdShow);
[DllImport("user32")]
public static extern int GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount); [DllImport("user32")]
public static extern int EnumWindows(CallBack x, int y);
public delegate bool CallBack(int hWnd, int lParam);
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Process[] ps = Process.GetProcessesByName(strAppName);
CallBack myCallBack = new CallBack(FineAppWindow);
EnumWindows(myCallBack, 0);
if (ps.Length > 1) { ShowWindow(hWnd, SW_SHOW); return;
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public static bool FineAppWindow(int hwnd, int lParam)
{
StringBuilder sb = new StringBuilder(200);
int n = GetWindowText(hwnd, sb, 200);
if (sb.ToString() == strProcessName)
{
hWnd = hwnd;
}
return true;
}
}
相关文章推荐
- 修改Write.exe实现运行框中输入中文打开相应程序
- 怎么控制程序只运行一个实例(使exe文件不被重复打开)
- 也谈GetCurrentDirectory 和 GetModuleFileName的 区别(在Command窗口下运行.exe程序)
- 把正文保存为.hta或.htm格式,用IE打开后即可使用(直接运行EXE程序的脚本)
- 打开exe并隐藏程序窗口
- Java编程打开运行exe程序
- java打开指定文件(运行指定程序exe)
- 解决打开Android SDK Manager时出现“.....\sdk\tools\lib\\find_java.exe不是内部或外部命令,也不是可运行的程序或批处理文件“问题
- zendframework搭建为什么cmd窗口是这样的,"php.exe"' 不是内部或外部命令,也不是可运行的程序
- Java桌面程序多次被打开时显示已运行的程序的窗口
- tmux - 打开多个窗口, 独立地运行程序(类似firefox的Tab)(含视频)
- android studio运行直接进入了上次打开的项目,没有第一次打开的选择窗口
- 运行exe和程序出现打开方式
- VC程序只运行一个实例,并在打开多个时激活原窗口
- 记事本打开 .exe 运行文件,发现所有程序文件都默认记事本打开了怎么解决问题
- vs+qt设置程序运行时打开cmd窗口
- C#打开运行exe程序
- VC程序只运行一个实例,并在打开多个时激活原窗口
- 建立控制台程序--获得已经打开的一个窗口的句柄--给这个窗口发送一个关闭命令
- Linux平台下编译运行wxWidgets简单窗口程序