[idd] helper: use CWindow helper to avoid global state

This commit is contained in:
Quantum authored and Geoffrey McRae committed 2025-09-14 09:49:39 +10:00
1 parent 9d48e70983
commit 94550e09b4
4 files changed
+86 -20

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
#include "CWindow.h"
#include <strsafe.h>
#include <CDebug.h>
ATOM CWindow::s_atom = 0;
static HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
bool CWindow::registerClass()
{
WNDCLASSEX wx = {};
wx.cbSize = sizeof(WNDCLASSEX);
wx.lpfnWndProc = wndProc;
wx.hInstance = hInstance;
wx.lpszClassName = L"LookingGlassIddHelper";
wx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wx.hCursor = LoadCursor(NULL, IDC_ARROW);
wx.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE;
s_atom = RegisterClassEx(&wx);
return s_atom;
}
CWindow::CWindow()
{
CreateWindowEx(0, MAKEINTATOM(s_atom), NULL,
0, 0, 0, 0, 0, NULL, NULL, hInstance, this);
}
LRESULT CWindow::wndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CWindow *self;
if (uMsg == WM_NCCREATE)
{
LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
self = (CWindow*)lpcs->lpCreateParams;
self->m_hwnd = hwnd;
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LPARAM) self);
}
else
{
self = (CWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
}
if (self)
return self->handleMessage(uMsg, wParam, lParam);
else
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
LRESULT CWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(m_hwnd, uMsg, wParam, lParam);
}
CWindow::~CWindow()
{
if (m_hwnd)
DestroyWindow(m_hwnd);
}