zoukankan      html  css  js  c++  java
  • PPC中检查某程序是否运行

    有时候经常需要检查某个程序是否正在运行,在windows mobile 5.0系统开发中我经常用到以下几种方法:

    第一种:
    HANDLE hMutex=::CreateMutexW(NULL,true,L"程序名");
     DWORD dwError=GetLastError();
     if(dwError==ERROR_ALREADY_EXISTS)
     {
      ::AfxMessageBox(L"The program is running!");
      return ;
     }
     ::ReleaseMutex(hMutex);

    第二种:
    HWND hWmp=::FindWindowW(L"Dialog",L"程序窗口名");
     if(hWmp)
     {
       ::AfxMessageBox(L"The program is running!");
      return FALSE;
     }

    第三种:
    PROCESSENTRY32   lppe;
     memset(&lppe,0,sizeof(PROCESSENTRY32));  
     HANDLE handle=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
     lppe.dwSize=sizeof(PROCESSENTRY32);
     ::Process32First(handle,&lppe);
     do
     {
      HANDLE hh=::OpenProcess(PROCESS_ALL_ACCESS,FALSE,lppe.th32ProcessID);
      CString temp(lppe.szExeFile);
      if(temp.Find(L"程序名")>=0)
      {
       ::AfxMessageBox(L"The program is running!");
       ::TerminateProcess(hh,0xffffffff);
       ::CloseHandle(hh);
        break;
      }
      ::CloseHandle(handle);
      
     }while(Process32Next(handle,&lppe));
     ::CloseHandle(handle);

    以上三种方法,只能检查其它程序,而不能检查自身是否正在运行,因为windows mobile 系统的运行机制和PC机上的windows XP是不太一样的.
  • 相关阅读:
    24. Swap Nodes in Pairs
    2. Add Two Numbers
    【设计模式】结构型模式
    【设计模式】创建型模式
    【设计模式】初识
    【自考总结】走过的弯路,都是你成长的旅途
    【VMware vSphere】再谈VMware vSphere
    评估网站性能的专业术语
    C/S与B/S之辩
    【VMware vSphere】Veeam备份
  • 原文地址:https://www.cnblogs.com/randylee/p/623241.html
Copyright © 2011-2022 走看看