From f98cacdde33eb5c7093191f3aadcaefd807fc23b Mon Sep 17 00:00:00 2001 From: David Hackbarth Date: Wed, 3 Sep 2025 16:10:19 +0200 Subject: [PATCH] add window (WIP) --- GDP/D3D9/Window.cpp | 29 ++++++++++++++++++++++++++++- GDP/D3D9/Window.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/GDP/D3D9/Window.cpp b/GDP/D3D9/Window.cpp index 1b684a0..8819944 100644 --- a/GDP/D3D9/Window.cpp +++ b/GDP/D3D9/Window.cpp @@ -1,16 +1,38 @@ #include "Window.h" +// https://learn.microsoft.com/en-us/windows/win32/learnwin32/creating-a-window + INT Window::init(HINSTANCE hInstance, UINT width, UINT height) { // 1. describe window class + WNDCLASS wc = {}; + wc.hInstance = hInstance; + wc.lpszClassName = TEXT("D3D9"); // class name + wc.lpfnWndProc = WindowProc; // callback function for windows to communicate with our application + wc.hbrBackground = CreateSolidBrush(RGB(0, 255, 0)); // 2. register window class + if (!RegisterClass(&wc)) return 100; // 3. adjust window size (optional) // 4. create window instance + _hWnd = CreateWindow( + wc.lpszClassName, // class name of window class to be instantiated + wc.lpszClassName, // window title + WS_OVERLAPPEDWINDOW, // visual style + 100, 100, // window position (left-top corner) + width, height, // window size + nullptr, // handle to parent window + nullptr, // handle to menu instance + hInstance, + nullptr // pointer to optional parameter + ); + if (_hWnd == nullptr) return 110; // 5. show window + ShowWindow(_hWnd, SW_SHOW); + SetFocus(_hWnd); return 0; } @@ -19,9 +41,14 @@ BOOL Window::run() { // 6. run window - return 0; + return true; } void Window::deInit() { } + +LRESULT WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + return DefWindowProc(hWnd, msg, wParam, lParam); +} diff --git a/GDP/D3D9/Window.h b/GDP/D3D9/Window.h index 3ef230c..ea76a26 100644 --- a/GDP/D3D9/Window.h +++ b/GDP/D3D9/Window.h @@ -14,3 +14,4 @@ private: HWND _hWnd = nullptr; // handle to window instance }; +LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);