ReactOS 0.4.16-dev-136-g52192f1
speakervolume.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Multimedia Control Panel
3 * FILE: dll/cpl/mmsys/speakervolume.c
4 * PURPOSE: ReactOS Multimedia Control Panel
5 * PROGRAMMER: Eric Kohl <eric.kohl@reactos.com>
6 */
7
8#include "mmsys.h"
9
10typedef struct _PAGE_DATA
11{
12 HMIXER hMixer;
21
22
23static
24BOOL
26 PPAGE_DATA pPageData,
27 HWND hwndDlg)
28{
29 WCHAR szBuffer[256];
30 MIXERLINEW mxln;
31 MIXERCONTROLW mxc;
32 MIXERLINECONTROLSW mxlctrl;
34 INT i, j;
35
36 /* Open the mixer */
38 {
39 MessageBoxW(hwndDlg, L"Cannot open mixer", NULL, MB_OK);
40 return FALSE;
41 }
42
43 /* Retrieve the mixer information */
44 mxln.cbStruct = sizeof(MIXERLINEW);
46
48 return FALSE;
49
50 pPageData->volumeChannels = mxln.cChannels;
51
52 /* Retrieve the line information */
53 mxlctrl.cbStruct = sizeof(MIXERLINECONTROLSW);
54 mxlctrl.dwLineID = mxln.dwLineID;
56 mxlctrl.cControls = 1;
57 mxlctrl.cbmxctrl = sizeof(MIXERCONTROLW);
58 mxlctrl.pamxctrl = &mxc;
59
61 return FALSE;
62
63 pPageData->volumeControlID = mxc.dwControlID;
64 pPageData->volumeMinimum = mxc.Bounds.dwMinimum;
65 pPageData->volumeMaximum = mxc.Bounds.dwMaximum;
66 pPageData->volumeStep = (pPageData->volumeMaximum - pPageData->volumeMinimum) / (VOLUME_MAX - VOLUME_MIN);
67
68 /* Allocate a buffer for all channel volume values */
70 0,
72 if (pPageData->volumeValues == NULL)
73 return FALSE;
74
75 /* Retrieve the channel volume values */
76 mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
77 mxcd.dwControlID = mxc.dwControlID;
78 mxcd.cChannels = mxln.cChannels;
79 mxcd.cMultipleItems = 0;
81 mxcd.paDetails = pPageData->volumeValues;
82
84 return FALSE;
85
86 /* Initialize the channels */
87 for (i = 0; i < min(mxln.cChannels, 5); i++)
88 {
89 j = i * 4;
90
91 /* Set the channel name */
92 LoadStringW(hApplet, IDS_SPEAKER_LEFT + i, szBuffer, _countof(szBuffer));
93 SetWindowTextW(GetDlgItem(hwndDlg, 9472 + j), szBuffer);
94
95 /* Initialize the channel trackbar */
99 SendDlgItemMessageW(hwndDlg, 9475 + j, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(pPageData->volumeValues[i].dwValue - pPageData->volumeMinimum) / pPageData->volumeStep);
100 }
101
102 /* Hide the unused controls */
103 for (i = mxln.cChannels; i < 8; i++)
104 {
105 j = i * 4;
106 ShowWindow(GetDlgItem(hwndDlg, 9472 + j), SW_HIDE);
107 ShowWindow(GetDlgItem(hwndDlg, 9473 + j), SW_HIDE);
108 ShowWindow(GetDlgItem(hwndDlg, 9474 + j), SW_HIDE);
109 ShowWindow(GetDlgItem(hwndDlg, 9475 + j), SW_HIDE);
110 }
111
112 return TRUE;
113}
114
115
116static
117VOID
119 PPAGE_DATA pPageData,
120 HWND hwndDlg)
121{
123 INT i, j;
124
125 /* Retrieve the channel volume values */
126 mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
127 mxcd.dwControlID = pPageData->volumeControlID;
128 mxcd.cChannels = pPageData->volumeChannels;
129 mxcd.cMultipleItems = 0;
131 mxcd.paDetails = pPageData->volumeValues;
132
134 return;
135
136 for (i = 0; i < pPageData->volumeChannels; i++)
137 {
138 j = i * 4;
139
140 SendDlgItemMessageW(hwndDlg, 9475 + j, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(pPageData->volumeValues[i].dwValue - pPageData->volumeMinimum) / pPageData->volumeStep);
141 }
142}
143
144
145static
146VOID
148 PPAGE_DATA pPageData,
149 HWND hwndDlg,
152{
154 DWORD dwValue, dwPosition;
155 INT id, idx, i, j;
156
158 if (id < 9475 || id > 9503)
159 return;
160
161 if ((id - 9475) % 4 != 0)
162 return;
163
164 dwPosition = (DWORD)SendDlgItemMessageW(hwndDlg, id, TBM_GETPOS, 0, 0);
165
166 if (dwPosition == VOLUME_MIN)
167 dwValue = pPageData->volumeMinimum;
168 else if (dwPosition == VOLUME_MAX)
169 dwValue = pPageData->volumeMaximum;
170 else
171 dwValue = (dwPosition * pPageData->volumeStep) + pPageData->volumeMinimum;
172
173 if (pPageData->volumeSync)
174 {
175 for (i = 0; i < pPageData->volumeChannels; i++)
176 {
177 j = 9475 + (i * 4);
178 if (j != id)
179 SendDlgItemMessageW(hwndDlg, j, TBM_SETPOS, (WPARAM)TRUE, dwPosition);
180
181 pPageData->volumeValues[i].dwValue = dwValue;
182 }
183 }
184 else
185 {
186 idx = (id - 9475) / 4;
187 pPageData->volumeValues[idx].dwValue = dwValue;
188 }
189
190 mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
191 mxcd.dwControlID = pPageData->volumeControlID;
192 mxcd.cChannels = pPageData->volumeChannels;
193 mxcd.cMultipleItems = 0;
195 mxcd.paDetails = pPageData->volumeValues;
196
198 return;
199}
200
201
202static
203VOID
205 PPAGE_DATA pPageData,
206 HWND hwndDlg)
207{
209 DWORD dwValue, i;
210
211 dwValue = ((VOLUME_MAX - VOLUME_MIN) / 2 * pPageData->volumeStep) + pPageData->volumeMinimum;
212
213 for (i = 0; i < pPageData->volumeChannels; i++)
214 pPageData->volumeValues[i].dwValue = dwValue;
215
216 mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
217 mxcd.dwControlID = pPageData->volumeControlID;
218 mxcd.cChannels = pPageData->volumeChannels;
219 mxcd.cMultipleItems = 0;
221 mxcd.paDetails = pPageData->volumeValues;
222
224 return;
225}
226
227
231 HWND hwndDlg,
232 UINT uMsg,
235{
236 PPAGE_DATA pPageData;
237
238 pPageData = (PPAGE_DATA)GetWindowLongPtrW(hwndDlg, DWLP_USER);
239
240 switch (uMsg)
241 {
242 case WM_INITDIALOG:
244 SetWindowLongPtrW(hwndDlg, DWLP_USER, (LONG_PTR)pPageData);
245
246 if (pPageData)
247 {
248 OnInitDialog(pPageData, hwndDlg);
249 }
250 break;
251
252 case WM_DESTROY:
253 if (pPageData)
254 {
255 if (pPageData->volumeValues)
256 HeapFree(GetProcessHeap(), 0, pPageData->volumeValues);
257
258 if (pPageData->hMixer)
259 mixerClose(pPageData->hMixer);
260
261 HeapFree(GetProcessHeap(), 0, pPageData);
262 pPageData = NULL;
264 }
265 break;
266
267 case WM_HSCROLL:
268 if (pPageData)
269 {
270 OnHScroll(pPageData, hwndDlg, wParam, lParam);
271 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
272 }
273 break;
274
275 case WM_COMMAND:
276 switch (LOWORD(wParam))
277 {
278 case 9504:
279 if (HIWORD(wParam) == BN_CLICKED)
280 pPageData->volumeSync = (SendDlgItemMessageW(hwndDlg, 9504, BM_GETCHECK, 0, 0) == BST_CHECKED);
281 break;
282
283 case 9505:
284 OnSetDefaults(pPageData, hwndDlg);
285 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
286 break;
287 }
288 break;
289
290 case WM_NOTIFY:
291 return TRUE;
292
294 if (pPageData)
295 OnMixerControlChange(pPageData, hwndDlg);
296 break;
297 }
298
299 return FALSE;
300}
301
302
305 HWND hwndDlg)
306{
307 PROPSHEETPAGEW psp[1];
309
310 ZeroMemory(&psh, sizeof(PROPSHEETHEADERW));
311 psh.dwSize = sizeof(PROPSHEETHEADERW);
313 psh.hwndParent = hwndDlg;
314 psh.hInstance = hApplet;
316 psh.nPages = _countof(psp);
317 psh.nStartPage = 0;
318 psh.ppsp = psp;
319
321 psp[0].dwFlags |= PSP_USETITLE;
322 psp[0].hInstance = hApplet;
324
325 return (LONG)(PropertySheetW(&psh) != -1);
326}
static VOID InitPropSheetPage(PROPSHEETPAGE *psp, PSERVICEPROPSHEET dlgInfo, WORD idDlg, DLGPROC DlgProc)
Definition: propsheet.c:15
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HINSTANCE hApplet
Definition: access.c:17
#define IDS_SPEAKER_VOLUME
Definition: resource.h:73
#define IDD_MULTICHANNEL
Definition: resource.h:29
#define IDS_SPEAKER_LEFT
Definition: resource.h:74
unsigned int idx
Definition: utils.c:41
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
Definition: propsheet.c:2916
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define PtrToUlong(u)
Definition: config.h:107
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint id
Definition: glext.h:5910
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
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 GLint GLint j
Definition: glfuncs.h:250
if(dx< 0)
Definition: linetemp.h:194
#define VOLUME_PAGESIZE
Definition: mmsys.h:45
#define VOLUME_TICFREQ
Definition: mmsys.h:44
#define CALLBACK_WINDOW
Definition: mmsystem.h:148
struct tagMIXERLINECONTROLSW MIXERLINECONTROLSW
#define MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
Definition: mmsystem.h:319
#define MIXER_OBJECTF_MIXER
Definition: mmsystem.h:300
#define MIXER_SETCONTROLDETAILSF_VALUE
Definition: mmsystem.h:415
#define MIXER_GETCONTROLDETAILSF_VALUE
Definition: mmsystem.h:412
#define MM_MIXM_CONTROL_CHANGE
Definition: mmsystem.h:83
struct tagMIXERCONTROLW MIXERCONTROLW
#define MIXERCONTROL_CONTROLTYPE_VOLUME
Definition: mmsystem.h:398
#define MIXER_GETLINEINFOF_COMPONENTTYPE
Definition: mmsystem.h:347
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
struct tMIXERCONTROLDETAILS MIXERCONTROLDETAILS
struct tMIXERCONTROLDETAILS_UNSIGNED MIXERCONTROLDETAILS_UNSIGNED
#define MIXER_GETLINECONTROLSF_ONEBYTYPE
Definition: mmsystem.h:410
#define MIXER_OBJECTF_HMIXER
Definition: mmsystem.h:301
struct tagMIXERLINEW MIXERLINEW
#define min(a, b)
Definition: monoChain.cc:55
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
long LONG
Definition: pedump.c:60
#define INT
Definition: polytest.cpp:20
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
#define PSP_USETITLE
Definition: prsht.h:26
#define PSH_PROPSHEETPAGE
Definition: prsht.h:43
struct _PROPSHEETHEADERW PROPSHEETHEADERW
#define TBM_SETPAGESIZE
Definition: commctrl.h:2056
#define TBM_GETPOS
Definition: commctrl.h:2036
#define TBM_SETRANGE
Definition: commctrl.h:2042
#define TBM_SETPOS
Definition: commctrl.h:2041
#define TBM_SETTICFREQ
Definition: commctrl.h:2055
#define WM_NOTIFY
Definition: richedit.h:61
#define VOLUME_MAX
Definition: sndvol32.h:19
#define _countof(array)
Definition: sndvol32.h:70
#define VOLUME_MIN
Definition: sndvol32.h:18
static VOID OnSetDefaults(PPAGE_DATA pPageData, HWND hwndDlg)
struct _PAGE_DATA PAGE_DATA
INT_PTR CALLBACK SpeakerVolumeDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
static VOID OnMixerControlChange(PPAGE_DATA pPageData, HWND hwndDlg)
struct _PAGE_DATA * PPAGE_DATA
static BOOL OnInitDialog(PPAGE_DATA pPageData, HWND hwndDlg)
Definition: speakervolume.c:25
INT_PTR SpeakerVolume(HWND hwndDlg)
static VOID OnHScroll(PPAGE_DATA pPageData, HWND hwndDlg, WPARAM wParam, LPARAM lParam)
DWORD volumeStep
Definition: speakervolume.c:17
DWORD volumeControlID
Definition: speakervolume.c:13
DWORD volumeMinimum
Definition: speakervolume.c:15
BOOL volumeSync
Definition: speakervolume.c:19
DWORD volumeChannels
Definition: speakervolume.c:14
HMIXER hMixer
Definition: speakervolume.c:12
DWORD volumeMaximum
Definition: speakervolume.c:16
PMIXERCONTROLDETAILS_UNSIGNED volumeValues
Definition: speakervolume.c:18
LPCPROPSHEETPAGEW ppsp
Definition: prsht.h:308
HINSTANCE hInstance
Definition: prsht.h:296
DWORD dwSize
Definition: prsht.h:293
DWORD dwFlags
Definition: prsht.h:294
HWND hwndParent
Definition: prsht.h:295
UINT nStartPage
Definition: prsht.h:304
LPCWSTR pszCaption
Definition: prsht.h:301
DWORD dwFlags
Definition: prsht.h:215
LPCWSTR pszTitle
Definition: prsht.h:225
HINSTANCE hInstance
Definition: prsht.h:216
union tagMIXERCONTROLW::@3041 Bounds
LPMIXERCONTROLW pamxctrl
Definition: mmsystem.h:1350
DWORD dwLineID
Definition: mmsystem.h:1258
DWORD cChannels
Definition: mmsystem.h:1262
DWORD cbStruct
Definition: mmsystem.h:1255
DWORD dwComponentType
Definition: mmsystem.h:1261
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#define HIWORD(l)
Definition: typedefs.h:247
#define ZeroMemory
Definition: winbase.h:1712
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW, DWORD fdwControls)
Definition: winmm.c:571
UINT WINAPI mixerClose(HMIXER hMix)
Definition: winmm.c:386
UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdW, DWORD fdwDetails)
Definition: winmm.c:423
UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW, DWORD fdwInfo)
Definition: winmm.c:592
UINT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen)
Definition: winmm.c:339
UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd, DWORD fdwDetails)
Definition: winmm.c:681
#define SW_HIDE
Definition: winuser.h:771
#define DWLP_USER
Definition: winuser.h:875
#define GetWindowLongPtrW
Definition: winuser.h:4832
#define WM_HSCROLL
Definition: winuser.h:1746
#define MAKELPARAM(l, h)
Definition: winuser.h:4011
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define WM_COMMAND
Definition: winuser.h:1743
#define WM_INITDIALOG
Definition: winuser.h:1742
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
#define MB_OK
Definition: winuser.h:793
HWND WINAPI GetParent(_In_ HWND)
#define GWLP_ID
Definition: winuser.h:863
#define BN_CLICKED
Definition: winuser.h:1928
#define WM_DESTROY
Definition: winuser.h:1612
#define SetWindowLongPtrW
Definition: winuser.h:5358
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define BST_CHECKED
Definition: winuser.h:197
#define BM_GETCHECK
Definition: winuser.h:1921
__wchar_t WCHAR
Definition: xmlstorage.h:180