码迷,mamicode.com
首页 > 编程语言 > 详细

线程互斥

时间:2014-11-01 06:27:50      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:mutex

////////////////////////////////////////////////////////////////
 HINSTANCE hInsta=::LoadLibrary("language\\XSelf.dll");
 if(hInsta!=NULL) AfxSetResourceHandle(hInsta);
/////////////////////////////////////////////////////////////////////////
 char pszExeName[32]="OnXDC XSelf";
 ::CreateMutex(NULL, TRUE, m_pszExeName);
 if (GetLastError()==ERROR_ALREADY_EXISTS) 
 {
  //Find our previous application‘s main window
  CWnd *pPrevWnd=CWnd::GetDesktopWindow()->GetWindow(GW_CHILD);
  while (pPrevWnd)
  {
   //Does this window have the previous instance tag set?
   if (::GetProp(pPrevWnd->GetSafeHwnd(), m_pszExeName))
   {
    //found window,now set focus to the window
    //first restore window if it is currently iconic
    if (pPrevWnd->IsIconic())
     pPrevWnd->ShowWindow(SW_RESTORE);
    //set focus to main window
    pPrevWnd->SetForegroundWindow();
    //if window has a pop-up window, set focus to pop-up
    pPrevWnd->GetLastActivePopup()->SetForegroundWindow();
    return FALSE;
   }
   //Did not find window,get next window in list
   pPrevWnd = pPrevWnd->GetWindow(GW_HWNDNEXT);
  }
  return FALSE;
 }

 

线程互斥

标签:mutex

原文地址:http://embeded.blog.51cto.com/3989210/1570524

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!