HWND RunningHandle=FindWindowEx(NULL,NULL,"自己程序的名字",NULL);
if(RunningHandel!=NULL)
{ 
   ShowMessage(...)
 }

解决方案 »

  1.   

    在你的App的InitInstance()函数里加上:HANDLE m_mutex;
    if((m_mutex=CreateMutex(NULL,TRUE,"MyFlag"))==0)  //MyFlag:你的程序标识,任意值
    {
       AfxMessageBox("创建互斥量失败,程序不能运行!");
       return FALSE;
    }
    if(GetLastError()==ERROR_ALREADY_EXISTS)
    {
       AfxMessageBox("本程序已在运行,不允许再一次运行!");
       return FALSE;
    }
      

  2.   

    to eknight(小廷):
     HANDLE m_mutex语句应该放在InitInstance()函数外边的
      

  3.   

    同意eknight(小廷) 的其它方法我不提倡
      

  4.   

    Add these code to your InitInstance().
    {
     ATOM atom=GlobalFindAtom("YourAppName");
     if(!atom)
     {
       AfxMessageBox("You aready run it");
       return false;
     }
     m_atom=GlobalAddAtom("YourAppName");
     //add your other code
    //before exit your process,be sure to call GlobalDeleteAtom(m_atom);
      

  5.   

    sorry! third row is error!
    Modify to: if(atom)