From 688982d429ecdb31a1c7167040ee9a29e49d98e6 Mon Sep 17 00:00:00 2001 From: Vitaly Orekhov Date: Sat, 14 Feb 2026 19:54:38 +0300 Subject: [PATCH] [SNDVOL32] Deduplicate dialog control retrieval code --- base/applications/sndvol32/dialog.c | 115 ++++++++++++---------------- 1 file changed, 47 insertions(+), 68 deletions(-) diff --git a/base/applications/sndvol32/dialog.c b/base/applications/sndvol32/dialog.c index df0d22d2386..7ff0fa3f5e6 100644 --- a/base/applications/sndvol32/dialog.c +++ b/base/applications/sndvol32/dialog.c @@ -767,69 +767,20 @@ LoadDialogCtrls( } } -VOID -UpdateDialogLineSwitchControl( +HWND +GetLineDialogControl( PPREFERENCES_CONTEXT PrefContext, LPMIXERLINE Line, - LONG fValue) + DWORD dwDialogID) { DWORD Index; - DWORD wID; - HWND hDlgCtrl; - WCHAR LineName[MIXER_LONG_NAME_CHARS]; /* find the index of this line */ for (Index = 0; Index < PrefContext->MixerWindow->DialogCount; Index++) { /* get id */ - wID = (Index + 1) * IDC_LINE_NAME; - - if (GetDlgItemText(PrefContext->MixerWindow->hWnd, wID, LineName, MIXER_LONG_NAME_CHARS) == 0) - { - /* failed to retrieve id */ - continue; - } - - /* check if the line name matches */ - if (!_wcsicmp(LineName, Line->szName)) - { - /* found matching line name */ - wID = (Index + 1) * IDC_LINE_SWITCH; - - /* get dialog control */ - hDlgCtrl = GetDlgItem(PrefContext->MixerWindow->hWnd, wID); - - if (hDlgCtrl != NULL) - { - /* check state */ - if (SendMessageW(hDlgCtrl, BM_GETCHECK, 0, 0) != fValue) - { - /* update control state */ - SendMessageW(hDlgCtrl, BM_SETCHECK, (WPARAM)fValue, 0); - } - } - break; - } - } -} - -VOID -UpdateDialogLineSliderControl( - PPREFERENCES_CONTEXT PrefContext, - LPMIXERLINE Line, - DWORD dwDialogID, - DWORD Position) -{ - DWORD Index; - DWORD wID; - HWND hDlgCtrl; - WCHAR LineName[MIXER_LONG_NAME_CHARS]; - - /* find the index of this line */ - for (Index = 0; Index < PrefContext->MixerWindow->DialogCount; Index++) - { - /* get id */ - wID = (Index + 1) * IDC_LINE_NAME; + WCHAR LineName[MIXER_LONG_NAME_CHARS]; + DWORD wID = (Index + 1) * IDC_LINE_NAME; if (GetDlgItemText(PrefContext->MixerWindow->hWnd, wID, LineName, MIXER_LONG_NAME_CHARS) == 0) { @@ -843,20 +794,48 @@ UpdateDialogLineSliderControl( /* found matching line name */ wID = (Index + 1) * dwDialogID; - /* get dialog control */ - hDlgCtrl = GetDlgItem(PrefContext->MixerWindow->hWnd, wID); - - if (hDlgCtrl != NULL) - { - /* check state */ - LRESULT OldPosition = SendMessageW(hDlgCtrl, TBM_GETPOS, 0, 0); - if (OldPosition != Position) - { - /* update control state */ - SendMessageW(hDlgCtrl, TBM_SETPOS, (WPARAM)TRUE, Position); - } - } - break; + return GetDlgItem(PrefContext->MixerWindow->hWnd, wID); } } + + return NULL; +} + +VOID +UpdateDialogLineSwitchControl( + PPREFERENCES_CONTEXT PrefContext, + LPMIXERLINE Line, + LONG fValue) +{ + HWND hDlgCtrl = GetLineDialogControl(PrefContext, Line, IDC_LINE_SWITCH); + + if (hDlgCtrl != NULL && SendMessageW(hDlgCtrl, BM_GETCHECK, 0, 0) != fValue) + SendMessageW(hDlgCtrl, BM_SETCHECK, (WPARAM)fValue, 0); +} + +DWORD +GetDialogLineSliderCurrentPosition( + PPREFERENCES_CONTEXT PrefContext, + LPMIXERLINE Line, + DWORD dwDialogID) +{ + HWND hDlgCtrl = GetLineDialogControl(PrefContext, Line, dwDialogID); + + return hDlgCtrl != NULL + ? SendMessageW(hDlgCtrl, TBM_GETPOS, 0, 0) + : 0; +} + +VOID +UpdateDialogLineSliderControl( + PPREFERENCES_CONTEXT PrefContext, + LPMIXERLINE Line, + DWORD dwDialogID, + DWORD Position) +{ + HWND hDlgCtrl = GetLineDialogControl(PrefContext, Line, dwDialogID); + BOOL isPositionChanged = GetDialogLineSliderCurrentPosition(PrefContext, Line, dwDialogID) != Position; + + if (hDlgCtrl != NULL && isPositionChanged) + SendMessageW(hDlgCtrl, TBM_SETPOS, (WPARAM)TRUE, Position); }