[idd] helper: add simple static widget implementation

This commit is contained in:
Quantum authored and Geoffrey McRae committed 2025-09-17 18:05:00 +10:00
1 parent 042450a708
commit 85e728b59e
7 files changed
+75

No files matched your search

+3
View File
@@ -2,6 +2,7 @@
#include <CDebug.h>
#include <windowsx.h>
#include <strsafe.h>
#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)
+4
View File
@@ -1,11 +1,15 @@
#pragma once
#include "CWindow.h"
#include "CStaticWidget.h"
#include <functional>
#include <memory>
class CConfigWindow : public CWindow
{
static ATOM s_atom;
std::unique_ptr<CStaticWidget> m_version;
std::function<void()> m_onDestroy;
virtual LRESULT handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
+15
View File
@@ -0,0 +1,15 @@
#include "CStaticWidget.h"
#include <commctrl.h>
#include <CDebug.h>
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);
}
+10
View File
@@ -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);
};
+21
View File
@@ -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;
}
}
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
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; }
};
+4
View File
@@ -180,6 +180,8 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
<ClCompile Include="CConfigWindow.cpp" />
<ClCompile Include="CNotifyWindow.cpp" />
<ClCompile Include="CPipeClient.cpp" />
<ClCompile Include="CStaticWidget.cpp" />
<ClCompile Include="CWidget.cpp" />
<ClCompile Include="CWindow.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
@@ -188,6 +190,8 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
<ClInclude Include="CConfigWindow.h" />
<ClInclude Include="CNotifyWindow.h" />
<ClInclude Include="CPipeClient.h" />
<ClInclude Include="CStaticWidget.h" />
<ClInclude Include="CWidget.h" />
<ClInclude Include="CWindow.h" />
</ItemGroup>
<ItemGroup>