diff --git a/include/platform.h b/include/platform.h index a991da7..0c76496 100644 --- a/include/platform.h +++ b/include/platform.h @@ -1,6 +1,6 @@ #ifndef PLATFORM_INCLUDED #define PLATFORM_INCLUDED -extern int plat_main(void); +extern int plat_main(int argc, char **argv); #endif // platform.h diff --git a/src/linux_platform.c b/src/linux_platform.c index a4b9241..5b99419 100644 --- a/src/linux_platform.c +++ b/src/linux_platform.c @@ -5,7 +5,9 @@ #include "../include/platform.h" -int plat_main(void) { +int plat_main(int argc, char **argv) { + (void) argc; + (void) argv; Display *display = XOpenDisplay(NULL); if (!display) { fprintf(stderr, "Cannot open display\n"); diff --git a/src/windows_platform.c b/src/windows_platform.c index a759d5c..92bbc11 100644 --- a/src/windows_platform.c +++ b/src/windows_platform.c @@ -14,44 +14,50 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return DefWindowProc(hwnd, msg, wParam, lParam); } -int WINAPI plat_main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +int plat_main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - // 1. Register the window class - WNDCLASS wc = {}; - wc.lpfnWndProc = WndProc; - wc.hInstance = hInstance; - wc.lpszClassName = "MyWindowClass"; - wc.hCursor = LoadCursor(NULL, IDC_ARROW); +HINSTANCE hInstance = GetModuleHandle(NULL); + const char CLASS_NAME[] = "MyWindowClass"; + + // Step 1: Register the window class + WNDCLASS wc = {0}; + wc.lpfnWndProc = WndProc; + wc.hInstance = hInstance; + wc.lpszClassName = CLASS_NAME; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); - RegisterClass(&wc); + if (!RegisterClass(&wc)) { + MessageBox(NULL, "Failed to register window class!", "Error", MB_OK | MB_ICONERROR); + return; + } - // 2. Create the window + // Step 2: Create the window HWND hwnd = CreateWindowEx( - 0, // Extended style - "MyWindowClass", // Class name - "Hello, Win32!", // Window title - WS_OVERLAPPEDWINDOW, // Style (title bar, border, min/max/close buttons) - CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, // x, y, width, height - NULL, // Parent window + 0, // Optional window styles + CLASS_NAME, // Window class + "My Win32 Window", // Window title + WS_OVERLAPPEDWINDOW, // Window style + CW_USEDEFAULT, CW_USEDEFAULT, 500, 400, // x, y, width, height + NULL, // Parent window NULL, // Menu - hInstance, - NULL + hInstance, // Instance handle + NULL // Additional application data ); - if (!hwnd) return -1; + if (!hwnd) { + MessageBox(NULL, "Failed to create window!", "Error", MB_OK | MB_ICONERROR); + return; + } - // 3. Show the window - ShowWindow(hwnd, nCmdShow); + ShowWindow(hwnd, SW_SHOW); UpdateWindow(hwnd); - // 4. Message loop - MSG msg = {}; - while (GetMessage(&msg, NULL, 0, 0)) - { + // Step 3: Message loop + MSG msg; + while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } - return (int)msg.wParam; } diff --git a/tests/01_platform.c b/tests/01_platform.c index ca89ea8..ee3425e 100644 --- a/tests/01_platform.c +++ b/tests/01_platform.c @@ -1,6 +1,6 @@ #define DEBUG #include "../include/platform.h" -int main(void){ +int main(int argc, char **argv){ - return plat_main(); + return plat_main(argc,argv); }