https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cae51e8f776404bb5a39b…
commit cae51e8f776404bb5a39be65e80cd8f60f7572c8
Author: Thamatip Chitpong <tangaming123456(a)outlook.com>
AuthorDate: Sun Dec 4 21:12:36 2022 +0700
Commit: GitHub <noreply(a)github.com>
CommitDate: Sun Dec 4 17:12:36 2022 +0300
[MMSYS] Prevent the same sound from being added multiple times (#4898)
Check if the list already contains the sound.
---
dll/cpl/mmsys/sounds.c | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/dll/cpl/mmsys/sounds.c b/dll/cpl/mmsys/sounds.c
index 57461ea09ec..5285599908c 100644
--- a/dll/cpl/mmsys/sounds.c
+++ b/dll/cpl/mmsys/sounds.c
@@ -896,6 +896,33 @@ FreeSoundFiles(HWND hwndDlg)
}
}
+static
+LRESULT
+FindSoundFileInList(HWND hwndDlg, LPCWSTR pSoundPath)
+{
+ LRESULT lCount, lIndex, lResult;
+ LPWSTR pszPath;
+ HWND hwndComboBox;
+
+ hwndComboBox = GetDlgItem(hwndDlg, IDC_SOUND_LIST);
+ lCount = ComboBox_GetCount(hwndComboBox);
+ if (lCount == CB_ERR)
+ return CB_ERR;
+
+ for (lIndex = 0; lIndex < lCount; lIndex++)
+ {
+ lResult = ComboBox_GetItemData(hwndComboBox, lIndex);
+ if (lResult == CB_ERR || lResult == 0)
+ continue;
+
+ pszPath = (LPWSTR)lResult;
+ if (_wcsicmp(pszPath, pSoundPath) == 0)
+ return lIndex;
+ }
+
+ return CB_ERR;
+}
+
BOOL
ShowSoundScheme(PGLOBAL_DATA pGlobalData, HWND hwndDlg)
{
@@ -1182,7 +1209,13 @@ SoundsDlgProc(HWND hwndDlg,
if (GetOpenFileNameW(&ofn))
{
- // FIXME search if list already contains that sound
+ // search if list already contains that sound
+ lResult = FindSoundFileInList(hwndDlg, filename);
+ if (lResult != CB_ERR)
+ {
+ SendDlgItemMessageW(hwndDlg, IDC_SOUND_LIST, CB_SETCURSEL,
(WPARAM)lResult, 0);
+ break;
+ }
// extract file name
pFileName = wcsrchr(filename, L'\\');