一个程序只能启动一次实现

原文网址: http://free56.cn/post/3.html
None.gif using  System;
None.gif
using  System.Runtime.InteropServices;
None.gif
None.gif
namespace  JKLib
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 一个程序只能启动一次实现
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class SingleInstance
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        [DllImport(
"user32.dll")] 
InBlock.gif        
private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
InBlock.gif        [DllImport(
"user32.dll")] 
InBlock.gif        
private static extern bool SetForegroundWindow(IntPtr hWnd);
InBlock.gif        [DllImport(
"user32.dll")] 
InBlock.gif        
private static extern bool ShowWindowAsync(IntPtr hWnd,int nCmdShow);
InBlock.gif        [DllImport(
"user32.dll")] 
InBlock.gif        
private static extern bool IsIconic(IntPtr hWnd);
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 显示窗体命令值 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private const int SW_RESTORE = 9;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 窗体名称
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private string WinTitle;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 一个程序只能启动一次实现
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="_WinTitle">程序名</param>

InBlock.gif        public SingleInstance(string _WinTitle)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            WinTitle 
= _WinTitle;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private IntPtr hWnd = (System.IntPtr)null;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 是否只有一个窗口
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public bool IsSingleInstance
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                hWnd 
= FindWindow(null,WinTitle);
InBlock.gif                
return hWnd == (System.IntPtr)null;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 使当前程序进程处于活动状态
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public void RaiseOtherProcess()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(hWnd == (System.IntPtr)nullreturn;
InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (IsIconic(hWnd))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    ShowWindowAsync(hWnd,SW_RESTORE);
ExpandedSubBlockEnd.gif                }

InBlock.gif                SetForegroundWindow(hWnd);
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

原文网址:  http://free56.cn/post/3.html 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值