[idd] helper: add CListBox widget

This commit is contained in:
Quantum
2025-09-22 01:55:51 -04:00
committed by Geoffrey McRae
parent c99f516b29
commit 96367e83f1
6 changed files with 52 additions and 3 deletions

View File

@@ -0,0 +1,30 @@
#include "CListBox.h"
#include <commctrl.h>
#include <windows.h>
#include <windowsx.h>
#include <CDebug.h>
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;
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include "CWidget.h"
#include <string>
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);
};

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -180,6 +180,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
<ItemGroup>
<ClCompile Include="$(SolutionDir)LGCommon\*.cpp" />
<ClCompile Include="CConfigWindow.cpp" />
<ClCompile Include="CListBox.cpp" />
<ClCompile Include="CNotifyWindow.cpp" />
<ClCompile Include="CPipeClient.cpp" />
<ClCompile Include="CRegistrySettings.cpp" />
@@ -192,6 +193,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
<ItemGroup>
<CLInclude Include="$(SolutionDir)LGCommon\*.h" />
<ClInclude Include="CConfigWindow.h" />
<ClInclude Include="CListBox.h" />
<ClInclude Include="CNotifyWindow.h" />
<ClInclude Include="CPipeClient.h" />
<ClInclude Include="CRegistrySettings.h" />

View File

@@ -43,6 +43,9 @@
<ClCompile Include="CRegistrySettings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CListBox.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="UIHelpers.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -79,6 +82,9 @@
<ClInclude Include="CRegistrySettings.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CListBox.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />