zoukankan      html  css  js  c++  java
  • 只允许应用程序执行一个实例

    若要应用程序只允许运行一个实例,只需要在 main 或 WinMain 函数中调用 Create*  函数,以便创建一个命名对象(创建的是什么对象则是无所谓的)。当 Create* 函数返回时,调用 GetLastError 函数。如果 GetLastError 函数返回 ERROR_ALREADY_EXISTS,那么你的应用程序的另一个实例正在运行,新实例可以退出。
    下面是说明这种情况的部分代码:

       1: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pszCmdLine, int nCmdShow) {
       2:     HANDLE handle = CreateMutex(NULL, FALSE, "one instance");
       3:     if(GetLastError() == ERROR_ALREADY_EXISTS) {
       4:         // There is already an instance of this application running.
       5:         return 0;
       6:     }
       7:     ...
       8:     return 0;    
       9: }

  • 相关阅读:
    IE8、IE9解决浏览器跨域。
    英语写作-Introduction
    qt添加图标
    Qt 编译错误 :cannot find file .pro
    python
    数据集
    基金
    visio2010求交操作
    书籍网站
    ROS安装xtion
  • 原文地址:https://www.cnblogs.com/mforestlaw/p/3289385.html
Copyright © 2011-2022 走看看