-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSingleProcess.cpp
More file actions
57 lines (46 loc) · 1.14 KB
/
SingleProcess.cpp
File metadata and controls
57 lines (46 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "stdafx.h"
#include "SingleProcess.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
namespace
{
const TCHAR singleProcessMutexName[] = _T("WindowLayoutManager - single process");
const unsigned int WM_SINGLE_PROCESS = ::RegisterWindowMessage(_T("WindowLayoutManager - single process"));
} // anonymous namespace
HANDLE SingleProcess::singleProcessMutex = NULL;
bool SingleProcess::check()
{
HANDLE sSingleProcessMutex;
sSingleProcessMutex = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, singleProcessMutexName);
if (sSingleProcessMutex)
{
return false;
}
::CloseHandle(singleProcessMutex);
singleProcessMutex = NULL;
return true;
}
void SingleProcess::lock()
{
if (!singleProcessMutex)
{
singleProcessMutex = ::CreateMutex(NULL, FALSE, singleProcessMutexName);
}
}
void SingleProcess::unlock()
{
if (singleProcessMutex)
{
::CloseHandle(singleProcessMutex);
singleProcessMutex = NULL;
}
}
unsigned int SingleProcess::getMsg()
{
return WM_SINGLE_PROCESS;
}
void SingleProcess::postMsg()
{
::PostMessage(HWND_BROADCAST, WM_SINGLE_PROCESS, 0, 0);
}