From 7d33b93a50990970aefb65f4997d45e6fa0554f5 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 4 Oct 2025 04:07:54 -0400 Subject: [PATCH] [idd] helper: save mode changes into registry and update listview --- idd/LGIddHelper/CConfigWindow.cpp | 11 +++++++++-- idd/LGIddHelper/CListBox.cpp | 19 ++++++++++++++++++- idd/LGIddHelper/CListBox.h | 3 +++ idd/LGIddHelper/CRegistrySettings.cpp | 2 +- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/idd/LGIddHelper/CConfigWindow.cpp b/idd/LGIddHelper/CConfigWindow.cpp index 2faea601..f5ae3d80 100644 --- a/idd/LGIddHelper/CConfigWindow.cpp +++ b/idd/LGIddHelper/CConfigWindow.cpp @@ -150,11 +150,18 @@ LRESULT CConfigWindow::onCommand(WORD id, WORD code, HWND hwnd) } else if (hwnd == *m_modeUpdate && code == BN_CLICKED && m_modes) { - auto &mode = (*m_modes)[m_modeBox->getSelData()]; + int sel = m_modeBox->getSel(); + int index = m_modeBox->getData(sel); + auto &mode = (*m_modes)[index]; mode.width = m_modeWidth->getNumericValue(); mode.height = m_modeHeight->getNumericValue(); mode.refresh = m_modeRefresh->getNumericValue(); - DEBUG_INFO(L"Updated mode to %s", mode.toString().c_str()); + m_modeBox->delItem(sel); + m_modeBox->setSel(m_modeBox->addItem(mode.toString().c_str(), index)); + + LRESULT result = m_settings.setModes(*m_modes); + if (result != ERROR_SUCCESS) + DEBUG_ERROR_HR(result, "Failed to save modes"); } return 0; } diff --git a/idd/LGIddHelper/CListBox.cpp b/idd/LGIddHelper/CListBox.cpp index cef54a93..9bb31a23 100644 --- a/idd/LGIddHelper/CListBox.cpp +++ b/idd/LGIddHelper/CListBox.cpp @@ -29,6 +29,12 @@ int CListBox::addItem(const std::wstring &display, LPARAM data) return result; } +void CListBox::delItem(int index) +{ + if (!ListBox_DeleteString(m_hwnd, index)) + DEBUG_ERROR("listbox: failed to delete string at %d", index); +} + int CListBox::getSel() { return ListBox_GetCurSel(m_hwnd); @@ -36,5 +42,16 @@ int CListBox::getSel() int CListBox::getSelData() { - return ListBox_GetItemData(m_hwnd, getSel()); + return getData(getSel()); +} + +int CListBox::getData(int index) +{ + return ListBox_GetItemData(m_hwnd, index); +} + +void CListBox::setSel(int index) +{ + if (!ListBox_SetCurSel(m_hwnd, index)) + DEBUG_ERROR("listbox: failed to set selection to %d", index); } diff --git a/idd/LGIddHelper/CListBox.h b/idd/LGIddHelper/CListBox.h index 76d55571..f51709ed 100644 --- a/idd/LGIddHelper/CListBox.h +++ b/idd/LGIddHelper/CListBox.h @@ -8,6 +8,9 @@ public: CListBox(DWORD style, HWND parent); void initStorage(DWORD count, size_t perItem); int addItem(const std::wstring &display, LPARAM data); + void delItem(int index); int getSel(); int getSelData(); + int getData(int index); + void setSel(int index); }; diff --git a/idd/LGIddHelper/CRegistrySettings.cpp b/idd/LGIddHelper/CRegistrySettings.cpp index c3076cba..32a38a9c 100644 --- a/idd/LGIddHelper/CRegistrySettings.cpp +++ b/idd/LGIddHelper/CRegistrySettings.cpp @@ -17,7 +17,7 @@ CRegistrySettings::~CRegistrySettings() LSTATUS CRegistrySettings::open() { HKEY key; - LSTATUS result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, LGIDD_REGKEY, 0, KEY_QUERY_VALUE, &key); + LSTATUS result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, LGIDD_REGKEY, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &key); if (result == ERROR_SUCCESS) hKey = key;