ReactOS  0.4.14-dev-593-g1793dcc
advanced.c
Go to the documentation of this file.
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 typedef struct _ADVANCED_DATA
11 {
13 
16 
17  /* Bass and Treble */
20 
22 
23 static
24 VOID
26  HWND hwndDlg,
28 {
29  MIXERCONTROLDETAILS_UNSIGNED UnsignedDetails;
30  MIXERCONTROLDETAILS_BOOLEAN BooleanDetails;
31  WCHAR szRawBuffer[256], szCookedBuffer[256];
33  UINT ControlCount = 0, Index;
34  DWORD i, dwStep, dwPosition;
35  DWORD dwOtherControls = 0;
36  RECT rect;
37  LONG dy;
38 
39  /* Set the dialog title */
40  LoadStringW(hAppInstance, IDS_ADVANCED_CONTROLS, szRawBuffer, ARRAYSIZE(szRawBuffer));
41  StringCchPrintfW(szCookedBuffer, ARRAYSIZE(szCookedBuffer), szRawBuffer, pData->Context->LineName);
42  SetWindowTextW(hwndDlg, szCookedBuffer);
43 
44  /* Disable the tone controls */
46  EnableWindow(GetDlgItem(hwndDlg, i), FALSE);
47 
48  /* Initialize the bass and treble trackbars */
55 
56  /* Calculate and set ticks */
57  dwStep = (VOLUME_MAX / (VOLUME_TICKS + 1));
58  if (VOLUME_MAX % (VOLUME_TICKS + 1) != 0)
59  dwStep++;
60  for (i = dwStep; i < VOLUME_MAX; i += dwStep)
61  {
64  }
65 
66  /* Hide the other controls */
68  ShowWindow(GetDlgItem(hwndDlg, i), SW_HIDE);
69 
70  if (SndMixerQueryControls(pData->Context->Mixer, &ControlCount, pData->Context->Line, &Control))
71  {
72  for (Index = 0; Index < ControlCount; Index++)
73  {
74  if (Control[Index].dwControlType == MIXERCONTROL_CONTROLTYPE_BASS)
75  {
76  /* Bass control */
77 
78  if (SndMixerGetVolumeControlDetails(pData->Context->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)&UnsignedDetails) != -1)
79  {
81  EnableWindow(GetDlgItem(hwndDlg, i), TRUE);
82 
83  dwStep = (Control[Index].Bounds.dwMaximum - Control[Index].Bounds.dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
84  dwPosition = (UnsignedDetails.dwValue - Control[Index].Bounds.dwMinimum) / dwStep;
86 
87  pData->bEnabled[0] = TRUE;
88  pData->dwControlId[0] = Control[Index].dwControlID;
89  pData->dwMaximum[0] = Control[Index].Bounds.dwMaximum;
90  pData->dwMinimum[0] = Control[Index].Bounds.dwMinimum;
91  }
92  }
93  else if (Control[Index].dwControlType == MIXERCONTROL_CONTROLTYPE_TREBLE)
94  {
95  /* Treble control */
96 
97  if (SndMixerGetVolumeControlDetails(pData->Context->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)&UnsignedDetails) != -1)
98  {
100  EnableWindow(GetDlgItem(hwndDlg, i), TRUE);
101 
102  dwStep = (Control[Index].Bounds.dwMaximum - Control[Index].Bounds.dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
103  dwPosition = (UnsignedDetails.dwValue - Control[Index].Bounds.dwMinimum) / dwStep;
105 
106  pData->bEnabled[1] = TRUE;
107  pData->dwControlId[1] = Control[Index].dwControlID;
108  pData->dwMaximum[1] = Control[Index].Bounds.dwMaximum;
109  pData->dwMinimum[1] = Control[Index].Bounds.dwMinimum;
110  }
111  }
113  (Control[Index].dwControlType != MIXERCONTROL_CONTROLTYPE_MUTE))
114  {
115  /* All boolean controls but the Mute control (Maximum of 2) */
116 
117  if (dwOtherControls < 2)
118  {
119  if (SndMixerGetVolumeControlDetails(pData->Context->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN), (LPVOID)&BooleanDetails) != -1)
120  {
121  LoadStringW(hAppInstance, IDS_OTHER_CONTROLS1 + dwOtherControls, szRawBuffer, ARRAYSIZE(szRawBuffer));
122  StringCchPrintfW(szCookedBuffer, ARRAYSIZE(szCookedBuffer), szRawBuffer, Control[Index].szName);
123  SetWindowTextW(GetDlgItem(hwndDlg, IDC_ADV_OTHER_CHECK1 + dwOtherControls), szCookedBuffer);
124 
125  ShowWindow(GetDlgItem(hwndDlg, IDC_ADV_OTHER_CHECK1 + dwOtherControls), SW_SHOWNORMAL);
126 
127  SendDlgItemMessageW(hwndDlg, IDC_ADV_OTHER_CHECK1 + dwOtherControls, BM_SETCHECK, (WPARAM)BooleanDetails.fValue, 0);
128 
129  pData->bEnabled[dwOtherControls + 2] = TRUE;
130  pData->dwControlId[dwOtherControls + 2] = Control[Index].dwControlID;
131 
132  dwOtherControls++;
133  }
134  }
135  }
136  }
137 
138  /* Free controls */
140  }
141 
142  if (dwOtherControls != 0)
143  {
144  /* Show the 'Other controls' groupbox and text */
147 
148  /* Resize the dialog */
149  GetWindowRect(hwndDlg, &rect);
150 
151  dy = MulDiv((dwOtherControls == 1) ? 73 : (73 + 15), pData->Context->MixerWindow->baseUnit.cy, 8);
152  rect.bottom += dy;
153 
154  SetWindowPos(hwndDlg, HWND_TOP, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER);
155 
156  /* Move the 'Close' button down */
157  GetWindowRect(GetDlgItem(hwndDlg, IDOK), &rect);
158  MapWindowPoints(HWND_DESKTOP, hwndDlg, (LPPOINT)&rect, 2);
159 
160  rect.top += dy;
161  rect.bottom += dy;
162 
163  SetWindowPos(GetDlgItem(hwndDlg, IDOK), HWND_TOP, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOSIZE | SWP_NOZORDER);
164 
165  if (dwOtherControls == 2)
166  {
167  /* Resize the 'Other Controls' groupbox */
169  MapWindowPoints(HWND_DESKTOP, hwndDlg, (LPPOINT)&rect, 2);
170 
171  dy = MulDiv(15, pData->Context->MixerWindow->baseUnit.cy, 8);
172  rect.bottom += dy;
173 
174  SetWindowPos(GetDlgItem(hwndDlg, IDC_ADV_OTHER_CONTROLS), HWND_TOP, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER);
175  }
176  }
177 }
178 
179 
180 static
181 VOID
183  HWND hwndDlg,
185  DWORD dwCtrlID)
186 {
188  DWORD dwControlID = 0, dwStep, dwPosition;
190 
191  if (dwCtrlID != IDC_ADV_BASS_SLIDER &&
192  dwCtrlID != IDC_ADV_TREBLE_SLIDER)
193  return;
194 
195  if (dwCtrlID == IDC_ADV_BASS_SLIDER)
196  {
197  if (pData->bEnabled[0] == FALSE)
198  return;
199 
200  dwControlID = pData->dwControlId[0];
201  dwMaximum = pData->dwMaximum[0];
202  dwMinimum = pData->dwMinimum[0];
203  }
204  else if (dwCtrlID == IDC_ADV_TREBLE_SLIDER)
205  {
206  if (pData->bEnabled[1] == FALSE)
207  return;
208 
209  dwControlID = pData->dwControlId[1];
210  dwMaximum = pData->dwMaximum[1];
211  dwMinimum = pData->dwMinimum[1];
212  }
213 
214  dwPosition = (DWORD)SendDlgItemMessage(hwndDlg, dwCtrlID, TBM_GETPOS, 0, 0);
215  dwStep = (dwMaximum - dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
216 
217  Details.dwValue = (dwPosition * dwStep) + dwMinimum;
218 
219  SndMixerSetVolumeControlDetails(pData->Context->Mixer, dwControlID, 1, sizeof(MIXERCONTROLDETAILS_UNSIGNED), &Details);
220 }
221 
222 
223 INT_PTR
224 CALLBACK
226  HWND hwndDlg,
227  UINT uMsg,
228  WPARAM wParam,
229  LPARAM lParam)
230 {
232 
234 
235  switch (uMsg)
236  {
237  case WM_INITDIALOG:
239  if (pData != NULL)
240  {
242  pData->Context = (PADVANCED_CONTEXT)((LONG_PTR)lParam);
243  OnInitDialog(hwndDlg, pData);
244  }
245  return TRUE;
246 
247  case WM_COMMAND:
248  switch (LOWORD(wParam))
249  {
250  case IDOK:
251  EndDialog(hwndDlg, IDOK);
252  break;
253  }
254  break;
255 
256  case WM_HSCROLL:
257  if (pData != NULL)
258  {
259  if (LOWORD(wParam) == TB_THUMBTRACK)
260  OnHScroll(hwndDlg, pData, GetDlgCtrlID((HWND)lParam));
261  }
262  break;
263 
264  case WM_CLOSE:
265  EndDialog(hwndDlg, IDCANCEL);
266  break;
267 
268  case WM_DESTROY:
269  if (pData != NULL)
270  {
273  }
274  break;
275  }
276 
277  return FALSE;
278 }
279 
280 /* EOF */
#define TB_THUMBTRACK
Definition: commctrl.h:2074
#define VOLUME_TICKS
Definition: sndvol32.h:20
#define MIXERCONTROL_CT_UNITS_MASK
Definition: mmsystem.h:370
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
int WINAPI MapWindowPoints(_In_opt_ HWND hWndFrom, _In_opt_ HWND hWndTo, _Inout_updates_(cPoints) LPPOINT lpPoints, _In_ UINT cPoints)
#define SW_HIDE
Definition: winuser.h:762
GLint dy
Definition: linetemp.h:97
#define CALLBACK
Definition: compat.h:27
#define TBM_SETRANGE
Definition: commctrl.h:2033
struct _ADVANCED_CONTEXT * PADVANCED_CONTEXT
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define HWND_TOP
Definition: winuser.h:1193
#define TBM_SETPOS
Definition: commctrl.h:2032
#define IDC_ADV_OTHER_CONTROLS
Definition: resources.h:36
#define VOLUME_MAX
Definition: sndvol32.h:19
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
UINT_PTR WPARAM
Definition: windef.h:207
#define SendDlgItemMessage
Definition: winuser.h:5817
#define SWP_NOZORDER
Definition: winuser.h:1232
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
int32_t INT_PTR
Definition: typedefs.h:62
DWORD dwMinimum[2]
Definition: advanced.c:19
#define IDC_ADV_TREBLE_LOW
Definition: resources.h:33
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define DWORD
Definition: nt_native.h:44
#define SetWindowLongPtr
Definition: treelist.c:70
& rect
Definition: startmenu.cpp:1413
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
#define IDC_ADV_TREBLE_SLIDER
Definition: resources.h:35
#define MIXERCONTROL_CT_CLASS_MASK
Definition: mmsystem.h:353
int WINAPI GetDlgCtrlID(_In_ HWND)
INT SndMixerSetVolumeControlDetails(PSND_MIXER Mixer, DWORD dwControlID, DWORD cChannels, DWORD cbDetails, LPVOID paDetails)
Definition: mixer.c:474
INT_PTR CALLBACK AdvancedDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: advanced.c:225
BOOL SndMixerQueryControls(PSND_MIXER Mixer, PUINT DisplayControls, LPMIXERLINE LineInfo, LPMIXERCONTROL *Controls)
Definition: mixer.c:112
struct _ADVANCED_DATA * PADVANCED_DATA
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
#define MIXERCONTROL_CONTROLTYPE_BASS
Definition: mmsystem.h:399
long LONG
Definition: pedump.c:60
#define TBM_GETPOS
Definition: commctrl.h:2027
#define IDC_ADV_OTHER_CHECK1
Definition: resources.h:38
#define MAKELONG(a, b)
Definition: typedefs.h:248
#define TBM_SETPAGESIZE
Definition: commctrl.h:2047
smooth NULL
Definition: ftsmooth.c:416
#define IDC_ADV_OTHER_TEXT
Definition: resources.h:37
PADVANCED_CONTEXT Context
Definition: advanced.c:12
LONG_PTR LPARAM
Definition: windef.h:208
struct _ADVANCED_DATA ADVANCED_DATA
#define MIXERCONTROL_CONTROLTYPE_BOOLEAN
Definition: mmsystem.h:382
#define WM_DESTROY
Definition: winuser.h:1591
DWORD dwMaximum[2]
Definition: advanced.c:18
#define IDC_ADV_BASS_LOW
Definition: resources.h:30
#define BM_SETCHECK
Definition: winuser.h:1903
DWORD dwMinimum
Definition: mmsystem.h:1291
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WM_CLOSE
Definition: winuser.h:1603
INT SndMixerGetVolumeControlDetails(PSND_MIXER Mixer, DWORD dwControlID, DWORD cChannels, DWORD cbDetails, LPVOID paDetails)
Definition: mixer.c:498
static const UCHAR Index[8]
Definition: usbohci.c:18
#define IDS_ADVANCED_CONTROLS
Definition: resources.h:44
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwControlId[4]
Definition: advanced.c:15
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static VOID OnHScroll(HWND hwndDlg, PADVANCED_DATA pData, DWORD dwCtrlID)
Definition: advanced.c:182
BOOL bEnabled[4]
Definition: advanced.c:14
#define DWLP_USER
Definition: winuser.h:866
#define TBM_SETTIC
Definition: commctrl.h:2031
static VOID OnInitDialog(HWND hwndDlg, PADVANCED_DATA pData)
Definition: advanced.c:25
#define WM_COMMAND
Definition: winuser.h:1722
static const WCHAR Control[]
Definition: interface.c:27
DWORD dwMaximum
Definition: mmsystem.h:1292
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define SWP_NOSIZE
Definition: winuser.h:1230
#define MIXERCONTROL_CT_SUBCLASS_MASK
Definition: mmsystem.h:362
#define SW_SHOWNORMAL
Definition: winuser.h:764
#define MIXERCONTROL_CONTROLTYPE_MUTE
Definition: mmsystem.h:384
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
#define VOLUME_MIN
Definition: sndvol32.h:18
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define HWND_DESKTOP
Definition: winuser.h:1195
#define IDC_ADV_OTHER_CHECK2
Definition: resources.h:39
unsigned int UINT
Definition: ndis.h:50
#define WM_HSCROLL
Definition: winuser.h:1725
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
static const WCHAR szName[]
Definition: msipriv.h:1194
#define MIXERCONTROL_CONTROLTYPE_TREBLE
Definition: mmsystem.h:400
#define IDS_OTHER_CONTROLS1
Definition: resources.h:45
#define SWP_NOMOVE
Definition: winuser.h:1229
#define VOLUME_PAGE_SIZE
Definition: sndvol32.h:21
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define IDC_ADV_BASS_SLIDER
Definition: resources.h:32
#define GetWindowLongPtr
Definition: treelist.c:73
#define IDCANCEL
Definition: winuser.h:825
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define HeapFree(x, y, z)
Definition: compat.h:402
#define MulDiv(x, y, z)
Definition: gdifloat.h:86
HINSTANCE hAppInstance
Definition: mmc.c:23