[idd] helper: save mode changes into registry and update listview

This commit is contained in:
Quantum
2025-10-04 04:07:54 -04:00
committed by Geoffrey McRae
parent bf77128053
commit 7d33b93a50
4 changed files with 31 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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