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 
  • 相关阅读:
    How a webpage is loaded and displayed
    Tree知识总结
    Install Cassandra Locally
    axios接口封装
    Jsonp解决跨域问题
    react使用swiper,解决添加点击事件首位图片点击失效,解决轮播按钮被覆盖问题
    vue 生产环境和测试环境的配置
    vue使用远程在线更新代码
    vue.js axios实现跨域http请求接口
    leetcode每日一题(2020-05-27):974. 和可被 K 整除的子数组
  • 原文地址:https://www.cnblogs.com/skywind/p/470682.html
Copyright © 2011-2022 走看看