[SNDVOL32] Advanced controls dialog: Remove the TBS_AUTOTICKS style from the trackbar...
[reactos.git] / base / applications / sndvol32 / advanced.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Sound Volume Control
4 * FILE: base/applications/sndvol32/advanced.c
5 * PROGRAMMERS: Eric Kohl <eric.kohl@reactos.org>
6 */
7
8 #include "sndvol32.h"
9
10 static
11 VOID
12 OnInitDialog(
13 HWND hwndDlg,
14 PADVANCED_CONTEXT Context)
15 {
16 WCHAR szRawTitle[256], szCookedTitle[256];
17 MIXERCONTROLDETAILS_UNSIGNED UnsignedDetails;
18 LPMIXERCONTROL Control = NULL;
19 UINT ControlCount = 0, Index;
20 DWORD i, dwStep, dwPosition;
21
22 /* Set the dialog title */
23 LoadStringW(hAppInstance, IDS_ADVANCED_CONTROLS, szRawTitle, ARRAYSIZE(szRawTitle));
24 StringCchPrintfW(szCookedTitle, ARRAYSIZE(szCookedTitle), szRawTitle, Context->LineName);
25 SetWindowTextW(hwndDlg, szCookedTitle);
26
27 /* Disable the tone controls */
28 for (i = IDC_ADV_BASS_LOW; i<= IDC_ADV_TREBLE_SLIDER; i++)
29 EnableWindow(GetDlgItem(hwndDlg, i), FALSE);
30
31 /* Initialize the bass and treble trackbars */
32 SendDlgItemMessageW(hwndDlg, IDC_ADV_BASS_SLIDER, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(VOLUME_MIN, VOLUME_MAX));
33 SendDlgItemMessageW(hwndDlg, IDC_ADV_TREBLE_SLIDER, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(VOLUME_MIN, VOLUME_MAX));
34 SendDlgItemMessageW(hwndDlg, IDC_ADV_BASS_SLIDER, TBM_SETPAGESIZE, 0, (LPARAM)VOLUME_PAGE_SIZE);
35 SendDlgItemMessageW(hwndDlg, IDC_ADV_TREBLE_SLIDER, TBM_SETPAGESIZE, 0, (LPARAM)VOLUME_PAGE_SIZE);
36 SendDlgItemMessageW(hwndDlg, IDC_ADV_BASS_SLIDER, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)0);
37 SendDlgItemMessageW(hwndDlg, IDC_ADV_TREBLE_SLIDER, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)0);
38
39 /* Calculate and set ticks */
40 dwStep = (VOLUME_MAX / (VOLUME_TICKS + 1));
41 if (VOLUME_MAX % (VOLUME_TICKS + 1) != 0)
42 dwStep++;
43 for (i = dwStep; i < VOLUME_MAX; i += dwStep)
44 {
45 SendDlgItemMessageW(hwndDlg, IDC_ADV_BASS_SLIDER, TBM_SETTIC, 0, (LPARAM)i);
46 SendDlgItemMessageW(hwndDlg, IDC_ADV_TREBLE_SLIDER, TBM_SETTIC, 0, (LPARAM)i);
47 }
48
49 /* Hide the other controls */
50 for (i = IDC_ADV_OTHER_CONTROLS; i<= IDC_ADV_OTHER_CHECK2; i++)
51 ShowWindow(GetDlgItem(hwndDlg, i), SW_HIDE);
52
53 if (SndMixerQueryControls(Context->Mixer, &ControlCount, Context->Line, &Control))
54 {
55 for (Index = 0; Index < ControlCount; Index++)
56 {
57 if (Control[Index].dwControlType == MIXERCONTROL_CONTROLTYPE_BASS)
58 {
59 if (SndMixerGetVolumeControlDetails(Context->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)&UnsignedDetails) != -1)
60 {
61 for (i = IDC_ADV_BASS_LOW; i<= IDC_ADV_BASS_SLIDER; i++)
62 EnableWindow(GetDlgItem(hwndDlg, i), TRUE);
63
64 dwStep = (Control[Index].Bounds.dwMaximum - Control[Index].Bounds.dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
65 dwPosition = (UnsignedDetails.dwValue - Control[Index].Bounds.dwMinimum) / dwStep;
66 SendDlgItemMessageW(hwndDlg, IDC_ADV_BASS_SLIDER, TBM_SETPOS, (WPARAM)TRUE, dwPosition);
67 }
68 }
69 else if (Control[Index].dwControlType == MIXERCONTROL_CONTROLTYPE_TREBLE)
70 {
71 if (SndMixerGetVolumeControlDetails(Context->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)&UnsignedDetails) != -1)
72 {
73 for (i = IDC_ADV_TREBLE_LOW; i<= IDC_ADV_TREBLE_SLIDER; i++)
74 EnableWindow(GetDlgItem(hwndDlg, i), TRUE);
75
76 dwStep = (Control[Index].Bounds.dwMaximum - Control[Index].Bounds.dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
77 dwPosition = (UnsignedDetails.dwValue - Control[Index].Bounds.dwMinimum) / dwStep;
78 SendDlgItemMessageW(hwndDlg, IDC_ADV_TREBLE_SLIDER, TBM_SETPOS, (WPARAM)TRUE, dwPosition);
79 }
80 }
81 else if (Control[Index].dwControlType != MIXERCONTROL_CONTROLTYPE_VOLUME &&
82 Control[Index].dwControlType != MIXERCONTROL_CONTROLTYPE_MUTE)
83 {
84 ShowWindow(GetDlgItem(hwndDlg, IDC_ADV_OTHER_CONTROLS), SW_SHOWNORMAL);
85 ShowWindow(GetDlgItem(hwndDlg, IDC_ADV_OTHER_TEXT), SW_SHOWNORMAL);
86
87 }
88 }
89
90 /* free controls */
91 HeapFree(GetProcessHeap(), 0, Control);
92 }
93 }
94
95
96 INT_PTR
97 CALLBACK
98 AdvancedDlgProc(
99 HWND hwndDlg,
100 UINT uMsg,
101 WPARAM wParam,
102 LPARAM lParam)
103 {
104 PADVANCED_CONTEXT Context;
105
106 switch (uMsg)
107 {
108 case WM_INITDIALOG:
109 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam);
110 Context = (PADVANCED_CONTEXT)((LONG_PTR)lParam);
111 OnInitDialog(hwndDlg, Context);
112 return TRUE;
113
114 case WM_COMMAND:
115 switch (LOWORD(wParam))
116 {
117 case IDOK:
118 EndDialog(hwndDlg, IDOK);
119 break;
120 }
121 break;
122
123 case WM_CLOSE:
124 EndDialog(hwndDlg, IDCANCEL);
125 break;
126 }
127
128 return FALSE;
129 }
130
131 /* EOF */