zoukankan      html  css  js  c++  java
  • 一个程序只能启动一次实现

    原文网址: http://free56.cn/post/3.html
    using System;
    using System.Runtime.InteropServices;

    namespace JKLib
    {
        
        
    /// <summary>
        
    /// 一个程序只能启动一次实现
        
    /// </summary>

        public class SingleInstance
        
    {
            [DllImport(
    "user32.dll")] 
            
    private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
            [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);

            
    /// <summary>
            
    /// 显示窗体命令值 
            
    /// </summary>

            private const int SW_RESTORE = 9;

            
    /// <summary>
            
    /// 窗体名称
            
    /// </summary>

            private string WinTitle;

            
    /// <summary>
            
    /// 一个程序只能启动一次实现
            
    /// </summary>
            
    /// <param name="_WinTitle">程序名</param>

            public SingleInstance(string _WinTitle)
            
    {
                WinTitle 
    = _WinTitle;
            }


            
    private IntPtr hWnd = (System.IntPtr)null;

            
    /// <summary>
            
    /// 是否只有一个窗口
            
    /// </summary>

            public bool IsSingleInstance
            
    {
                
    get
                
    {
                    hWnd 
    = FindWindow(null,WinTitle);
                    
    return hWnd == (System.IntPtr)null;
                }

            }

            
    /// <summary>
            
    /// 使当前程序进程处于活动状态
            
    /// </summary>

            public void RaiseOtherProcess()
            
    {
                
    if(hWnd == (System.IntPtr)nullreturn;
                
    else
                
    {
                    
    if (IsIconic(hWnd))
                    
    {
                        ShowWindowAsync(hWnd,SW_RESTORE);
                    }

                    SetForegroundWindow(hWnd);
                    
    return;
                }

            }

        }

    }


    原文网址:  http://free56.cn/post/3.html 
  • 相关阅读:
    redis 用scan 代替keys 解决百万数据模糊查询超时问题
    集成spring-ldap
    IDEA报Unable to save settings: Failed to save settings. Please restart IntelliJ IDEA随后闪退
    struts2响应文件 struts2下载txt
    QRCodeUtil 二维码生成 解析 带图片与不带图片的二维码
    java 手机号正则表达式 截止2019年6月最新
    Java遍历Map对象的四种方式效率对比
    SpringCloud Alibaba系列(二) Nacos高可用和持久化
    SpringCloud Alibaba系列(二) Nacos配置中心-分类配置
    SpringCloud Alibaba系列(二) Nacos使用
  • 原文地址:https://www.cnblogs.com/skywind/p/470682.html
Copyright © 2011-2022 走看看