Last active
October 26, 2016 07:38
-
-
Save z4none/231bb50b99690c8e2ddbd26aa371a7ac to your computer and use it in GitHub Desktop.
one instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| HANDLE mMutexOneInstance; | |
| UINT mMsgLaunched; | |
| mMsgLaunched = RegisterWindowMessage(_T("SOMETHING")); | |
| mMutexOneInstance = ::CreateMutex(NULL, FALSE, _T("MY_APP_ONE_INSTANCE")); | |
| if((mMutexOneInstance != NULL) && (GetLastError() != ERROR_ALREADY_EXISTS)) | |
| { | |
| CMyDlg dlg; | |
| dlg.DoModal(); | |
| } | |
| else | |
| { | |
| ::SendMessage(HWND_BROADCAST, mMsgLaunched, 0, 0); | |
| return FALSE; // app exit | |
| } | |
| // important | |
| ON_REGISTERED_MESSAGE(theApp.mMsgLaunched, OnLaunched) | |
| // | |
| LRESULT CMyDlg::OnLaunched(WPARAM wParam, LPARAM lParam) | |
| { | |
| ShowWindow(SW_RESTORE); | |
| return TRUE; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment