From 96367e83f1394214ea3d64055896b02655484807 Mon Sep 17 00:00:00 2001 From: Quantum Date: Mon, 22 Sep 2025 01:55:51 -0400 Subject: [PATCH] [idd] helper: add CListBox widget --- idd/LGIddHelper/CListBox.cpp | 30 +++++++++++++++++++++ idd/LGIddHelper/CListBox.h | 11 ++++++++ idd/LGIddHelper/CWidget.cpp | 4 +-- idd/LGIddHelper/CWidget.h | 2 +- idd/LGIddHelper/LGIddHelper.vcxproj | 2 ++ idd/LGIddHelper/LGIddHelper.vcxproj.filters | 6 +++++ 6 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 idd/LGIddHelper/CListBox.cpp create mode 100644 idd/LGIddHelper/CListBox.h diff --git a/idd/LGIddHelper/CListBox.cpp b/idd/LGIddHelper/CListBox.cpp new file mode 100644 index 00000000..766d24b8 --- /dev/null +++ b/idd/LGIddHelper/CListBox.cpp @@ -0,0 +1,30 @@ +#include "CListBox.h" +#include +#include +#include +#include + +CListBox::CListBox(DWORD style, HWND parent) +{ + m_hwnd = createWindowSimple(WC_LISTBOX, nullptr, style, parent, WS_EX_CLIENTEDGE); + if (!m_hwnd) + DEBUG_ERROR_HR(GetLastError(), "Failed to create listbox"); +} + +void CListBox::initStorage(DWORD count, size_t perItem) +{ + SendMessage(m_hwnd, LB_INITSTORAGE, count, perItem); +} + +int CListBox::addItem(const std::wstring &display, LPARAM data) +{ + int result = ListBox_AddString(m_hwnd, display.c_str()); + if (result == LB_ERRSPACE) + { + DEBUG_ERROR(L"Out of memory while adding to listbox: %s", display.c_str()); + return -1; + } + + ListBox_SetItemData(m_hwnd, result, data); + return result; +} diff --git a/idd/LGIddHelper/CListBox.h b/idd/LGIddHelper/CListBox.h new file mode 100644 index 00000000..5f28c59c --- /dev/null +++ b/idd/LGIddHelper/CListBox.h @@ -0,0 +1,11 @@ +#pragma once +#include "CWidget.h" +#include + +class CListBox : public CWidget +{ +public: + CListBox(DWORD style, HWND parent); + void initStorage(DWORD count, size_t perItem); + int addItem(const std::wstring &display, LPARAM data); +}; diff --git a/idd/LGIddHelper/CWidget.cpp b/idd/LGIddHelper/CWidget.cpp index e78ff660..4d90c303 100644 --- a/idd/LGIddHelper/CWidget.cpp +++ b/idd/LGIddHelper/CWidget.cpp @@ -1,8 +1,8 @@ #include "CWidget.h" -HWND CWidget::createWindowSimple(LPCWSTR cls, LPCWSTR title, DWORD style, HWND parent) +HWND CWidget::createWindowSimple(LPCWSTR cls, LPCWSTR title, DWORD style, HWND parent, DWORD dwExStyle) { - return CreateWindow(cls, title, style, 0, 0, 0, 0, parent, + return CreateWindowEx(dwExStyle, cls, title, style, 0, 0, 0, 0, parent, NULL, (HINSTANCE)GetModuleHandle(NULL), NULL); } diff --git a/idd/LGIddHelper/CWidget.h b/idd/LGIddHelper/CWidget.h index ff1c6f77..34882a97 100644 --- a/idd/LGIddHelper/CWidget.h +++ b/idd/LGIddHelper/CWidget.h @@ -6,7 +6,7 @@ class CWidget { protected: HWND m_hwnd = NULL; - HWND createWindowSimple(LPCWSTR cls, LPCWSTR title, DWORD style, HWND parent); + HWND createWindowSimple(LPCWSTR cls, LPCWSTR title, DWORD style, HWND parent, DWORD dwExStyle = 0); public: virtual ~CWidget(); diff --git a/idd/LGIddHelper/LGIddHelper.vcxproj b/idd/LGIddHelper/LGIddHelper.vcxproj index 7a676a35..e68840ad 100644 --- a/idd/LGIddHelper/LGIddHelper.vcxproj +++ b/idd/LGIddHelper/LGIddHelper.vcxproj @@ -180,6 +180,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd + @@ -192,6 +193,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd + diff --git a/idd/LGIddHelper/LGIddHelper.vcxproj.filters b/idd/LGIddHelper/LGIddHelper.vcxproj.filters index ab4eea1f..37b9f8ab 100644 --- a/idd/LGIddHelper/LGIddHelper.vcxproj.filters +++ b/idd/LGIddHelper/LGIddHelper.vcxproj.filters @@ -43,6 +43,9 @@ Source Files + + Source Files + Source Files @@ -79,6 +82,9 @@ Header Files + + Header Files +