From 85e728b59e3d3daf9ddd61d2912a6227e445f73d Mon Sep 17 00:00:00 2001 From: Quantum Date: Mon, 15 Sep 2025 03:56:26 -0400 Subject: [PATCH] [idd] helper: add simple static widget implementation --- idd/LGIddHelper/CConfigWindow.cpp | 3 +++ idd/LGIddHelper/CConfigWindow.h | 4 ++++ idd/LGIddHelper/CStaticWidget.cpp | 15 +++++++++++++++ idd/LGIddHelper/CStaticWidget.h | 10 ++++++++++ idd/LGIddHelper/CWidget.cpp | 21 +++++++++++++++++++++ idd/LGIddHelper/CWidget.h | 18 ++++++++++++++++++ idd/LGIddHelper/LGIddHelper.vcxproj | 4 ++++ 7 files changed, 75 insertions(+) create mode 100644 idd/LGIddHelper/CStaticWidget.cpp create mode 100644 idd/LGIddHelper/CStaticWidget.h create mode 100644 idd/LGIddHelper/CWidget.cpp create mode 100644 idd/LGIddHelper/CWidget.h diff --git a/idd/LGIddHelper/CConfigWindow.cpp b/idd/LGIddHelper/CConfigWindow.cpp index 9d3f169d..9f9256b6 100644 --- a/idd/LGIddHelper/CConfigWindow.cpp +++ b/idd/LGIddHelper/CConfigWindow.cpp @@ -2,6 +2,7 @@ #include #include #include +#include "VersionInfo.h" ATOM CConfigWindow::s_atom = 0; @@ -24,6 +25,8 @@ CConfigWindow::CConfigWindow() { DEBUG_ERROR_HR(GetLastError(), "Failed to create window"); } + + m_version.reset(new CStaticWidget(L"Looking Glass IDD " LG_VERSION_STR, WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, m_hwnd)); } LRESULT CConfigWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) diff --git a/idd/LGIddHelper/CConfigWindow.h b/idd/LGIddHelper/CConfigWindow.h index 0be77066..9665599c 100644 --- a/idd/LGIddHelper/CConfigWindow.h +++ b/idd/LGIddHelper/CConfigWindow.h @@ -1,11 +1,15 @@ #pragma once #include "CWindow.h" +#include "CStaticWidget.h" #include +#include class CConfigWindow : public CWindow { static ATOM s_atom; + std::unique_ptr m_version; + std::function m_onDestroy; virtual LRESULT handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override; diff --git a/idd/LGIddHelper/CStaticWidget.cpp b/idd/LGIddHelper/CStaticWidget.cpp new file mode 100644 index 00000000..6cf8566a --- /dev/null +++ b/idd/LGIddHelper/CStaticWidget.cpp @@ -0,0 +1,15 @@ +#include "CStaticWidget.h" +#include +#include + +CStaticWidget::CStaticWidget(LPCWSTR title, DWORD style, HWND parent) +{ + m_hwnd = createWindowSimple(WC_STATIC, title, style, parent); + if (!m_hwnd) + DEBUG_ERROR_HR(GetLastError(), "Failed to create static widget"); +} + +void CStaticWidget::setText(LPCWSTR text) +{ + SetWindowText(m_hwnd, text); +} diff --git a/idd/LGIddHelper/CStaticWidget.h b/idd/LGIddHelper/CStaticWidget.h new file mode 100644 index 00000000..de374125 --- /dev/null +++ b/idd/LGIddHelper/CStaticWidget.h @@ -0,0 +1,10 @@ +#pragma once + +#include "CWidget.h" + +class CStaticWidget : public CWidget +{ +public: + CStaticWidget(LPCWSTR title, DWORD style, HWND parent); + void setText(LPCWSTR text); +}; diff --git a/idd/LGIddHelper/CWidget.cpp b/idd/LGIddHelper/CWidget.cpp new file mode 100644 index 00000000..e78ff660 --- /dev/null +++ b/idd/LGIddHelper/CWidget.cpp @@ -0,0 +1,21 @@ +#include "CWidget.h" + +HWND CWidget::createWindowSimple(LPCWSTR cls, LPCWSTR title, DWORD style, HWND parent) +{ + return CreateWindow(cls, title, style, 0, 0, 0, 0, parent, + NULL, (HINSTANCE)GetModuleHandle(NULL), NULL); +} + +CWidget::~CWidget() +{ + destroy(); +} + +void CWidget::destroy() +{ + if (m_hwnd) + { + DestroyWindow(m_hwnd); + m_hwnd = NULL; + } +} diff --git a/idd/LGIddHelper/CWidget.h b/idd/LGIddHelper/CWidget.h new file mode 100644 index 00000000..28beed43 --- /dev/null +++ b/idd/LGIddHelper/CWidget.h @@ -0,0 +1,18 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN +#include + +class CWidget { +protected: + HWND m_hwnd = NULL; + + HWND createWindowSimple(LPCWSTR cls, LPCWSTR title, DWORD style, HWND parent); + +public: + virtual ~CWidget(); + void destroy(); + + HWND hwnd() { return m_hwnd; } + operator HWND() { return m_hwnd; } +}; diff --git a/idd/LGIddHelper/LGIddHelper.vcxproj b/idd/LGIddHelper/LGIddHelper.vcxproj index e34120ad..e90ea9ee 100644 --- a/idd/LGIddHelper/LGIddHelper.vcxproj +++ b/idd/LGIddHelper/LGIddHelper.vcxproj @@ -180,6 +180,8 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd + + @@ -188,6 +190,8 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd + +