__declspec (dllimport) LONG GetInstanceCount (void);
__declspec (dllimport) LONG IncrementInstanceCount (void);
__declspec (dllimport) LONG DecrementInstanceCount (void);
.
.
.
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
static char szAppName[] = "MyApp";
static char szWndClass[] = "MyWindowClass";
WNDCLASS wc;
HWND hwnd;
MSG msg;
if (GetInstanceCount ())
{
MessageBox (NULL, "Another instance of this application is running", "Error", MB_OK |
MB_ICONSTOP);
return -1;
}
IncrementInstanceCount ();
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);
}
DecrementInstanceCount ();
return msg.wParam;
}