关于打开新窗体的求助 应用程序stringapp 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 自己补上API定义h = FindWindow(主程序标题, null);SetForeGroundWindow(h);Application.Exit(); 哥API定义什么呢。。我是新手。。可以说明白点吗? if (yearTermForm == null || yearTermForm.IsDisposed) { yearTermForm = new YearTermForm(); yearTermForm.MdiParent = this; yearTermForm.WindowState = FormWindowState.Maximized; yearTermForm.Show(); } else yearTermForm.Activate();yearTermForm 是定义好的全局变量。 [DllImport("user32.dll",EntryPoint="Findwindow")]public static extern int FindWindow (string lpClassName, string lpWindowName);[DllImport("user32.dll")]public static extern bool SetForegroundWindow(IntPtr hWnd);这就是那两个需要导入的API 在program.cs里操作如下:添加命名空间:using System.Diagnostics;using System.Threading;然后在主函数里:main(){ bool instantiated; Mutex mutex = new Mutex(true,"f6ForSingle", out instantiated); if (!instantiated) { MessageBox.Show("你已经启动程序了。别闹了,好吗?"); return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Login()); GC.KeepAlive(mutex);} 哥,您的方法的确可以,但是不明白当中的f6ForSingle是什么意思,然后 MessageBox.Show("你已经启动程序了。别闹了,好吗?");怎么做到如果已经有运行了,那么把运行了的最前置呢? [DllImport("User32.dll", EntryPoint = "FindWindow")] private static extern int FindWindow(string lpClassName, string lpWindowName);private void test(){ int count = FindWindow(null, "主程序标题"); if(count!=0){ //已打开 }else { //未打开 }} [DllImport("User32.dll", EntryPoint = "FindWindow")] private static extern int FindWindow(string lpClassName, string lpWindowName);private void test(){ int count = FindWindow(null, "Home"); if(count!=0){ //已打开 }else { //未打开 }} 哥 您的这个是需要写在 Program 中的吗? 8楼的那个方法我感觉可以实现具体就不会了 [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); private const int SW_RESTORE = 9; [STAThread] static void Main() { bool flag = false; Mutex mutex = new Mutex(true, "ZZZZZ", out flag); if (!flag) { Process proc = Process.GetCurrentProcess(); Process.GetProcesses(); foreach (Process otherProc in Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName)) { if (proc.Id != otherProc.Id) { IntPtr hWnd = otherProc.MainWindowHandle; if (IsIconic(hWnd)) { ShowWindowAsync(hWnd, 9); } SetForegroundWindow(hWnd); break; } } Application.Exit(); } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Home()); } }Program中需要填写的内容,首先需要获取窗口句柄,然后判断进程,最后激活之前的窗口 http://www.360doc.com/content/13/0325/15/10504424_273826790.shtml 给你个写的比较乱的参考。 太奇怪了,谁能帮我看看 请教 遍历Struct内的常量 ??? c# 日历控件 怎样把有数据的日期凸显出? Pocket PC开发,求EVC++3.0,急用! 改变数据源刷新窗体? AE截取地图 以类为成员的数组碰到的问题, 使用axWebBrowser控件,保存网页中的图片 [100分]求关于图片噪点控制的算法!只要管用分可以再加! 如能解决这个问题,立马给200分! VS2013问题 传奇类游戏的视野计算有做过的大神咩
SetForeGroundWindow(h);
Application.Exit();
哥API定义什么呢。。我是新手。。可以说明白点吗?
if (yearTermForm == null || yearTermForm.IsDisposed)
{
yearTermForm = new YearTermForm();
yearTermForm.MdiParent = this;
yearTermForm.WindowState = FormWindowState.Maximized;
yearTermForm.Show();
}
else
yearTermForm.Activate();yearTermForm 是定义好的全局变量。
public static extern int FindWindow (string lpClassName, string lpWindowName);[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);这就是那两个需要导入的API
添加命名空间:
using System.Diagnostics;
using System.Threading;
然后在主函数里:
main()
{
bool instantiated;
Mutex mutex = new Mutex(true,"f6ForSingle", out instantiated);
if (!instantiated)
{
MessageBox.Show("你已经启动程序了。别闹了,好吗?");
return;
} Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
GC.KeepAlive(mutex);}
怎么做到如果已经有运行了,那么把运行了的最前置呢?
private static extern int FindWindow(string lpClassName, string lpWindowName);private void test()
{
int count = FindWindow(null, "主程序标题");
if(count!=0){
//已打开
}else
{
//未打开
}
}
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern int FindWindow(string lpClassName, string lpWindowName);private void test()
{
int count = FindWindow(null, "Home");
if(count!=0){
//已打开
}else
{
//未打开
}
}
哥 您的这个是需要写在 Program 中的吗? 8楼的那个方法我感觉可以实现具体就不会了
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);
private const int SW_RESTORE = 9; [STAThread]
static void Main()
{
bool flag = false;
Mutex mutex = new Mutex(true, "ZZZZZ", out flag);
if (!flag)
{
Process proc = Process.GetCurrentProcess();
Process.GetProcesses();
foreach (Process otherProc in Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName))
{
if (proc.Id != otherProc.Id)
{
IntPtr hWnd = otherProc.MainWindowHandle;
if (IsIconic(hWnd))
{
ShowWindowAsync(hWnd, 9);
}
SetForegroundWindow(hWnd);
break;
}
}
Application.Exit();
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Home());
}
}
Program中需要填写的内容,首先需要获取窗口句柄,然后判断进程,最后激活之前的窗口
给你个写的比较乱的参考。