线程互斥
//////////////////////////////////////////////////////////////// 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; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。