[idd] helper: implement basic config class

This commit is contained in:
Quantum
2025-09-14 16:04:25 -04:00
committed by Geoffrey McRae
parent 9009217366
commit 042450a708
8 changed files with 119 additions and 8 deletions

View File

@@ -0,0 +1,48 @@
#include "CConfigWindow.h"
#include <CDebug.h>
#include <windowsx.h>
#include <strsafe.h>
ATOM CConfigWindow::s_atom = 0;
bool CConfigWindow::registerClass()
{
WNDCLASSEX wx = {};
populateWindowClass(wx);
wx.hIconSm = wx.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wx.lpszClassName = L"LookingGlassIddConfig";
s_atom = RegisterClassEx(&wx);
return s_atom;
}
CConfigWindow::CConfigWindow()
{
if (!CreateWindowEx(0, MAKEINTATOM(s_atom), L"Looking Glass IDD Configuration",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
NULL, NULL, hInstance, this))
{
DEBUG_ERROR_HR(GetLastError(), "Failed to create window");
}
}
LRESULT CConfigWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
default:
return CWindow::handleMessage(uMsg, wParam, lParam);
}
}
LRESULT CConfigWindow::onCreate()
{
return 0;
}
LRESULT CConfigWindow::onFinal()
{
if (m_onDestroy)
m_onDestroy();
return CWindow::onFinal();
}

View File

@@ -0,0 +1,20 @@
#pragma once
#include "CWindow.h"
#include <functional>
class CConfigWindow : public CWindow
{
static ATOM s_atom;
std::function<void()> m_onDestroy;
virtual LRESULT handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
virtual LRESULT onCreate() override;
virtual LRESULT onFinal() override;
public:
CConfigWindow();
static bool registerClass();
void onDestroy(std::function<void()> func) { m_onDestroy = std::move(func); }
};

View File

@@ -1,9 +1,14 @@
#include "CNotifyWindow.h" #include "CNotifyWindow.h"
#include "CConfigWindow.h"
#include <CDebug.h> #include <CDebug.h>
#include <windowsx.h> #include <windowsx.h>
#include <strsafe.h> #include <strsafe.h>
#define WM_NOTIFY_ICON (WM_USER)
#define WM_CLEAN_UP_CONFIG (WM_USER+1)
#define ID_MENU_SHOW_LOG 3000 #define ID_MENU_SHOW_LOG 3000
#define ID_MENU_SHOW_CONFIG 3001
ATOM CNotifyWindow::s_atom = 0; ATOM CNotifyWindow::s_atom = 0;
UINT CNotifyWindow::s_taskbarCreated = 0; UINT CNotifyWindow::s_taskbarCreated = 0;
@@ -31,6 +36,7 @@ CNotifyWindow::CNotifyWindow() : m_iconData({ 0 }), m_menu(CreatePopupMenu()),
if (m_menu) if (m_menu)
{ {
AppendMenu(m_menu, MF_STRING, ID_MENU_SHOW_LOG, L"Open log directory"); AppendMenu(m_menu, MF_STRING, ID_MENU_SHOW_LOG, L"Open log directory");
AppendMenu(m_menu, MF_STRING, ID_MENU_SHOW_CONFIG, L"Open configuration");
} }
} }
@@ -43,11 +49,15 @@ LRESULT CNotifyWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
switch (uMsg) switch (uMsg)
{ {
case WM_NCDESTROY:
PostQuitMessage(0);
return 0;
case WM_NOTIFY_ICON: case WM_NOTIFY_ICON:
return onNotifyIcon(LOWORD(lParam), HIWORD(lParam), GET_X_LPARAM(wParam), GET_Y_LPARAM(wParam)); return onNotifyIcon(LOWORD(lParam), HIWORD(lParam), GET_X_LPARAM(wParam), GET_Y_LPARAM(wParam));
case WM_CLEAN_UP_CONFIG:
if (m_config && !m_config->hwnd())
{
DEBUG_INFO("Config window closed");
m_config.reset();
}
return 0;
default: default:
if (s_taskbarCreated && uMsg == s_taskbarCreated) if (s_taskbarCreated && uMsg == s_taskbarCreated)
{ {
@@ -71,6 +81,12 @@ LRESULT CNotifyWindow::onClose()
return 0; return 0;
} }
LRESULT CNotifyWindow::onFinal()
{
PostQuitMessage(0);
return CWindow::onFinal();
}
LRESULT CNotifyWindow::onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y) LRESULT CNotifyWindow::onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y)
{ {
switch (uEvent) switch (uEvent)
@@ -81,6 +97,14 @@ LRESULT CNotifyWindow::onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y)
case ID_MENU_SHOW_LOG: case ID_MENU_SHOW_LOG:
ShellExecute(m_hwnd, L"open", g_debug.logDir(), NULL, NULL, SW_NORMAL); ShellExecute(m_hwnd, L"open", g_debug.logDir(), NULL, NULL, SW_NORMAL);
break; break;
case ID_MENU_SHOW_CONFIG:
DEBUG_INFO("Config window opened");
m_config.reset(new CConfigWindow());
m_config->onDestroy([this]() {
PostMessage(m_hwnd, WM_CLEAN_UP_CONFIG, 0, 0);
});
ShowWindow(*m_config, SW_NORMAL);
break;
} }
break; break;
} }

View File

@@ -1,7 +1,8 @@
#pragma once #pragma once
#include "CWindow.h" #include "CWindow.h"
#include <memory>
#define WM_NOTIFY_ICON (WM_USER) class CConfigWindow;
class CNotifyWindow : public CWindow class CNotifyWindow : public CWindow
{ {
@@ -11,6 +12,7 @@ class CNotifyWindow : public CWindow
NOTIFYICONDATA m_iconData; NOTIFYICONDATA m_iconData;
HMENU m_menu; HMENU m_menu;
bool closeRequested; bool closeRequested;
std::unique_ptr<CConfigWindow> m_config;
LRESULT onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y); LRESULT onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y);
void registerIcon(); void registerIcon();
@@ -18,6 +20,7 @@ class CNotifyWindow : public CWindow
virtual LRESULT handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override; virtual LRESULT handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
virtual LRESULT onCreate() override; virtual LRESULT onCreate() override;
virtual LRESULT onClose() override; virtual LRESULT onClose() override;
virtual LRESULT onFinal() override;
public: public:
CNotifyWindow(); CNotifyWindow();

View File

@@ -47,6 +47,8 @@ LRESULT CWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
return onClose(); return onClose();
case WM_DESTROY: case WM_DESTROY:
return onDestroy(); return onDestroy();
case WM_NCDESTROY:
return onFinal();
default: default:
return DefWindowProc(m_hwnd, uMsg, wParam, lParam); return DefWindowProc(m_hwnd, uMsg, wParam, lParam);
} }
@@ -67,13 +69,16 @@ LRESULT CWindow::onDestroy()
return 0; return 0;
} }
LRESULT CWindow::onFinal()
{
m_hwnd = 0;
return 0;
}
void CWindow::destroy() void CWindow::destroy()
{ {
if (m_hwnd) if (m_hwnd)
{
DestroyWindow(m_hwnd); DestroyWindow(m_hwnd);
m_hwnd = NULL;
}
} }
CWindow::~CWindow() CWindow::~CWindow()

View File

@@ -7,11 +7,12 @@
class CWindow { class CWindow {
static LRESULT CALLBACK wndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK wndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
protected:
virtual LRESULT onCreate(); virtual LRESULT onCreate();
virtual LRESULT onClose(); virtual LRESULT onClose();
virtual LRESULT onDestroy(); virtual LRESULT onDestroy();
virtual LRESULT onFinal();
protected:
static HINSTANCE hInstance; static HINSTANCE hInstance;
static void populateWindowClass(WNDCLASSEX &wx); static void populateWindowClass(WNDCLASSEX &wx);
@@ -24,4 +25,5 @@ public:
void destroy(); void destroy();
HWND hwnd() { return m_hwnd; } HWND hwnd() { return m_hwnd; }
operator HWND() { return m_hwnd; }
}; };

View File

@@ -177,6 +177,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="$(SolutionDir)LGCommon\*.cpp" /> <ClCompile Include="$(SolutionDir)LGCommon\*.cpp" />
<ClCompile Include="CConfigWindow.cpp" />
<ClCompile Include="CNotifyWindow.cpp" /> <ClCompile Include="CNotifyWindow.cpp" />
<ClCompile Include="CPipeClient.cpp" /> <ClCompile Include="CPipeClient.cpp" />
<ClCompile Include="CWindow.cpp" /> <ClCompile Include="CWindow.cpp" />
@@ -184,6 +185,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CLInclude Include="$(SolutionDir)LGCommon\*.h" /> <CLInclude Include="$(SolutionDir)LGCommon\*.h" />
<ClInclude Include="CConfigWindow.h" />
<ClInclude Include="CNotifyWindow.h" /> <ClInclude Include="CNotifyWindow.h" />
<ClInclude Include="CPipeClient.h" /> <ClInclude Include="CPipeClient.h" />
<ClInclude Include="CWindow.h" /> <ClInclude Include="CWindow.h" />

View File

@@ -13,6 +13,7 @@ using namespace Microsoft::WRL::Wrappers::HandleTraits;
#include "VersionInfo.h" #include "VersionInfo.h"
#include "CPipeClient.h" #include "CPipeClient.h"
#include "CNotifyWindow.h" #include "CNotifyWindow.h"
#include "CConfigWindow.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof*(x)) #define ARRAY_SIZE(x) (sizeof(x) / sizeof*(x))
#define SVCNAME L"Looking Glass (IDD Helper)" #define SVCNAME L"Looking Glass (IDD Helper)"
@@ -86,6 +87,12 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!CConfigWindow::registerClass())
{
DEBUG_ERROR("Failed to register config window class");
return EXIT_FAILURE;
}
if (!g_pipe.Init()) if (!g_pipe.Init())
return EXIT_FAILURE; return EXIT_FAILURE;