int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
    static char szAppName[] = "MyApp";
    static char szWndClass[] = "MyWindowClass";

    // Use a unique name!
    HWND hwnd, hwndPrev;
    WNDCLASS wc;
    MSG msg;
    
    // If a previous instance is running, activate
    // that instance and terminate this one.
    if ((hwndPrev = FindWindow (szWndClass, NULL))! = NULL)
    {
        SetForegroundWindow (hwndPrev);
        return -1;
    }

    // No previous instances are running;
    // proceed normally.
    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);
    }
    
    return msg.wParam;
}