Example quickfix
This commit is contained in:
@@ -27,73 +27,64 @@ int WINAPI ci2_wWinMain(
|
|||||||
HINSTANCE hPrevInstance,
|
HINSTANCE hPrevInstance,
|
||||||
LPSTR pCmdLine,
|
LPSTR pCmdLine,
|
||||||
int nCmdShow) {
|
int nCmdShow) {
|
||||||
// Create a console so stdout/stderr work
|
|
||||||
|
UNUSED(hInstance);
|
||||||
UNUSED(hPrevInstance);
|
UNUSED(hPrevInstance);
|
||||||
UNUSED(pCmdLine);
|
UNUSED(pCmdLine);
|
||||||
UNUSED(nCmdShow);
|
UNUSED(nCmdShow);
|
||||||
|
|
||||||
|
// Create a console so stdout/stderr work
|
||||||
if (AllocConsole()) {
|
if (AllocConsole()) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
freopen_s(&f, "CONOUT$", "w", stdout);
|
freopen_s(&f, "CONOUT$", "w", stdout);
|
||||||
freopen_s(&f, "CONOUT$", "w", stderr);
|
freopen_s(&f, "CONOUT$", "w", stderr);
|
||||||
wprintf(L"Allocated console\n");
|
wprintf(L"GUI but allocated a 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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[]) {
|
int WINAPI ci2_wmain(int argc, ci2_sys_char *wargv[]) {
|
||||||
|
|
||||||
wprintf(L"Console present. argc=%d\n", argc);
|
wprintf(L"Console present. argc=%d\n", argc);
|
||||||
UNUSED(wargv);
|
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(
|
if (!ci2_init()) return 1;
|
||||||
0, wc.lpszClassName, L"Win32 CI2 App",
|
|
||||||
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
|
|
||||||
NULL, NULL, hInst, NULL);
|
|
||||||
ShowWindow(hwnd, SW_SHOW);
|
|
||||||
|
|
||||||
MSG msg;
|
static ci2_sys_char *ci2_window_title = "Win32-CLI Window Title";
|
||||||
while (GetMessageW(&msg, NULL, 0, 0)) {
|
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
|
||||||
TranslateMessage(&msg);
|
if (!window) return 1;
|
||||||
DispatchMessageW(&msg);
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user