Author: dchapyshev
Date: Sun Apr 27 12:14:58 2008
New Revision: 33171
URL:
http://svn.reactos.org/svn/reactos?rev=33171&view=rev
Log:
- Don't be loaded more than one copy of the application (based on mutex)
Modified:
trunk/reactos/base/applications/kbswitch/kbswitch.c
Modified: trunk/reactos/base/applications/kbswitch/kbswitch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch…
==============================================================================
--- trunk/reactos/base/applications/kbswitch/kbswitch.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/kbswitch/kbswitch.c [iso-8859-1] Sun Apr 27 12:14:58
2008
@@ -9,6 +9,9 @@
#include "kbswitch.h"
#define WM_NOTIFYICONMSG (WM_USER + 248)
+
+TCHAR szKbSwitcherName[] = _T("kbswitcher");
+
static BOOL
GetLayoutID(LPTSTR szLayoutNum, LPTSTR szLCID);
@@ -370,6 +373,11 @@
{
WNDCLASS WndClass = {0};
MSG msg;
+ HANDLE hMutex;
+
+ hMutex = CreateMutex(NULL, FALSE, szKbSwitcherName);
+ if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS))
+ return 1;
hInst = hInstance;
hProcessHeap = GetProcessHeap();
@@ -383,12 +391,12 @@
WndClass.hCursor = NULL;
WndClass.hbrBackground = NULL;
WndClass.lpszMenuName = NULL;
- WndClass.lpszClassName = _T("kbswitch");
+ WndClass.lpszClassName = szKbSwitcherName;
if (!RegisterClass(&WndClass))
return 1;
- CreateWindow(_T("kbswitch"), NULL, 0, 0, 0, 1, 1, HWND_DESKTOP, NULL,
hInstance, NULL);
+ CreateWindow(szKbSwitcherName, NULL, 0, 0, 0, 1, 1, HWND_DESKTOP, NULL, hInstance,
NULL);
while(GetMessage(&msg,NULL,0,0))
{
@@ -396,5 +404,7 @@
DispatchMessage(&msg);
}
+ CloseHandle(hMutex);
+
return 0;
}