首页 > 代码库 > 线程互斥
线程互斥
//////////////////////////////////////////////////////////////// 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; }
线程互斥
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。