1.请问怎么判断一个应用程序已经启动一次了!
2.启动一次后就不让程序再启动了!
请问用程序怎么实现呀!
谢谢!

解决方案 »

  1.   


    看这里
    http://www.csdn.net/Develop/article/15/15174.shtm
      

  2.   

    1.你可以通过读写注册表来实现!!!
    2.在你的工程中找到InitInstance()这个函数,然后添加如下的代码!!!
    int x;
    x=GetProfileInt("test", "times", 0);
    if(x>1)
    {
    AfxMessageBox("1 times!", MB_OK);
    return false;
    }
    WriteProfileInt("test", "times", x+1);
    上面这断代码要添加在InitInstance()函数中LoadStdProfileSettings();的后面就可以了.
      

  3.   

    1. 定义一个全局的HANDLE g_Mutex
    2. 在CWinApp::InitInstance()里做如下代码
       g_Mutex = CreateMutex(NULL, FALSE, _T("YourAppName"));
       if(g_Mutex == NULL)
      {
          DWORD dwErr;
          dwErr = GetLastError();
          if(dwErr == ERROR_ALREADY_EXISTS)
          {  // 已有一个程序正在运行
               ....
          }
          else
          {
               ....
          }
      }3. 在ExitInstance()中
        CloseHandle(g_Mutex);
      

  4.   

    1.最简单: 用FindWindow查找窗口标题,若找到,则已运行. 缺点:对标题常变 的程序不适合.2.较好的方法:
    在应用类xxxApp::InitInstance()中的开始加入:   ::CreateMutex(NULL,TRUE,"Your program name or else");
    if ( GetLastError() == ERROR_ALREADY_EXISTS )
    {
    AfxMessageBox("程序已经在运行");
    return FALSE;
    }
      

  5.   

    在CWinApp::InitInstance()里添加HANDLE hMutex=CreateMutex(0,FALSE,"program_name");
    if(hMutex)
    {
    if(GetLastError()==ERROR_ALREADY_EXISTS)
    return 0;
    }