From 60e5410eed93e4f80fd4f037f4d0dd1caab1c262 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Fri, 6 Jan 2023 16:31:05 +0800 Subject: [PATCH] Initial commit Setup WinAPI. --- .gitignore | 2 ++ CMakeLists.txt | 6 ++++++ src/main.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..990936c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +cmake-build-debug/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f43f6c3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.24) +project(cerberus C) + +set(CMAKE_C_STANDARD 11) + +add_executable(cerberus WIN32 src/main.c) diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..6d25960 --- /dev/null +++ b/src/main.c @@ -0,0 +1,50 @@ +#include + +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); + +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, + PWSTR pCmdLine, int nCmdShow) { + + MSG msg; + HWND hwnd; + WNDCLASSW wc = { + .style = CS_HREDRAW | CS_VREDRAW, + .cbClsExtra = 0, + .cbWndExtra = 0, + .lpszClassName = L"Window", + .hInstance = hInstance, + .hbrBackground = GetSysColorBrush(COLOR_3DFACE), + .lpszMenuName = NULL, + .lpfnWndProc = WndProc, + .hCursor = LoadCursor(NULL, IDC_ARROW), + .hIcon = LoadIcon(NULL, IDI_APPLICATION), + }; + + RegisterClassW(&wc); + hwnd = CreateWindowW(wc.lpszClassName, L"Window", + WS_OVERLAPPEDWINDOW | WS_VISIBLE, + 100, 100, 350, 250, NULL, NULL, hInstance, NULL); + + ShowWindow(hwnd, nCmdShow); + UpdateWindow(hwnd); + + while (GetMessage(&msg, NULL, 0, 0)) { + DispatchMessage(&msg); + } + + return (int) msg.wParam; +} + +LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, + WPARAM wParam, LPARAM lParam) { + + switch(msg) { + + case WM_DESTROY: + + PostQuitMessage(0); + break; + } + + return DefWindowProcW(hwnd, msg, wParam, lParam); +}