int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
static char szAppName[] = "MyApp";
static char szWndClass[] = "MyWindowClass";
static char szMutexName[] = "MyMutex";
WNDCLASS wc;
HWND hwnd;
MSG msg;
HANDLE hMutex;
hMutex = CreateMutex (NULL, FALSE, szMutexName);
if ((hMutex != NULL) && (GetLastError () == ERROR_ALREADY_EXISTS))
{
MessageBox (NULL, "Another instance of this application is running",
"Error", MB_OK | MB_ICONSTOP);
CloseHandle (hMutex);
return -1;
}
wc.style = 0;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = szWndClass;
RegisterClass (&wc);
hwnd = CreateWindow (szWndClass, szAppName,
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, HWND_DESKTOP, NULL, hInstance, NULL);
ShowWindow (hwnd, nCmdShow);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
CloseHandle (hMutex);
return msg.wParam;
}