Skip to content

Instantly share code, notes, and snippets.

@z4none
Last active October 26, 2016 07:38
Show Gist options
  • Select an option

  • Save z4none/231bb50b99690c8e2ddbd26aa371a7ac to your computer and use it in GitHub Desktop.

Select an option

Save z4none/231bb50b99690c8e2ddbd26aa371a7ac to your computer and use it in GitHub Desktop.
one instance
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