z4none
10/26/2016 - 7:37 AM

one instance

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;
}