看到豆腐兄弟的如何让程序只运行一次,我认为他介绍的 CreateMutex比FindWindow好用.

和他抬一下木头,他要把木头扔下来的时候我躲开,不要砸我的脚.

代码如下:

BOOL DoesThisInstanceExist()
{

 CString strInstanceName;

 strInstanceName.Load(IDR_MAINFRAME);
 // Create the mutex with the class name
 m_Mutex = CreateMutex(NULL, FALSE, strInstanceName);

 // Check for errors
 if (GetLastError() == ERROR_ALREADY_EXISTS)
 {
  m_Mutex = NULL;
  return FALSE;
 }

 // Return that we already exist
 return TRUE;
}