Example quickfix

This commit is contained in:
2026-05-12 15:13:02 -05:00
parent edc49c57fb
commit 90e91cc25b

View File

@@ -27,73 +27,64 @@ int WINAPI ci2_wWinMain(
HINSTANCE hPrevInstance,
LPSTR pCmdLine,
int nCmdShow) {
// Create a console so stdout/stderr work
UNUSED(hInstance);
UNUSED(hPrevInstance);
UNUSED(pCmdLine);
UNUSED(nCmdShow);
// Create a console so stdout/stderr work
if (AllocConsole()) {
FILE *f;
freopen_s(&f, "CONOUT$", "w", stdout);
freopen_s(&f, "CONOUT$", "w", stderr);
wprintf(L"Allocated console\n");
}
WNDCLASSEXW wc = {0};
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
if (!RegisterClassExW(&wc)) return 0;
HWND hwnd = CreateWindowExW(
0,
"Win32 Window Class",
L"Win32 CI2 App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 200,
NULL, NULL, hInstance, NULL
);
if (!hwnd) return 0;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG msg;
while (GetMessageW(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
wprintf(L"GUI but allocated a console\n");
}
return (int)msg.wParam;
static ci2_sys_char *ci2_window_title = "Win32-GUI Window Title";
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
if (!window) return 1;
while (ci2_poll_events(window)) {
// Your rendering / game loop goes here
Sleep(1);
#ifdef GUI_DEBUG_CLOSE
break;
#endif
}
ci2_destroy_window(window);
ci2_shutdown();
return result;
}
int WINAPI ci2_wmain(int argc, ci2_sys_char *wargv[]) {
wprintf(L"Console present. argc=%d\n", argc);
UNUSED(wargv);
HINSTANCE hInst = GetModuleHandleW(NULL);
WNDCLASSW wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInst;
wc.lpszClassName = L"Win32 Window Class";
RegisterClassW(&wc);
HWND hwnd = CreateWindowExW(
0, wc.lpszClassName, L"Win32 CI2 App",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
NULL, NULL, hInst, NULL);
ShowWindow(hwnd, SW_SHOW);
if (!ci2_init()) return 1;
MSG msg;
while (GetMessageW(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
static ci2_sys_char *ci2_window_title = "Win32-CLI Window Title";
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
if (!window) return 1;
while (ci2_poll_events(window)) {
// Your rendering / game loop goes here
Sleep(1);
#ifdef GUI_DEBUG_CLOSE
break;
#endif
}
wprintf(L"Message loop ended, exit code=%d\n", (int)msg.wParam);
return (int)msg.wParam;
ci2_destroy_window(window);
ci2_shutdown();
return result;
}