[SNDVOL32] Add the 'Advanced Controls for Volume Control' dialog. It does nothing...
[reactos.git] / base / applications / sndvol32 / sndvol32.c
1 /*
2 * ReactOS Sound Volume Control
3 * Copyright (C) 2004-2005 Thomas Weidenmueller
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS Sound Volume Control
22 * FILE: base/applications/sndvol32/sndvol32.c
23 * PROGRAMMERS: Thomas Weidenmueller <w3seek@reactos.com>
24 */
25
26 #include "sndvol32.h"
27
28 #include <shellapi.h>
29
30 HINSTANCE hAppInstance;
31 ATOM MainWindowClass;
32 HWND hMainWnd;
33 HANDLE hAppHeap;
34 LPTSTR lpAppTitle;
35 PREFERENCES_CONTEXT Preferences;
36
37 #define GetDialogData(hwndDlg, type) \
38 ( P##type )GetWindowLongPtr((hwndDlg), DWLP_USER)
39 #define GetWindowData(hwnd, type) \
40 ( P##type )GetWindowLongPtr((hwnd), GWL_USERDATA)
41
42 /******************************************************************************/
43
44
45
46 typedef struct _PREFERENCES_FILL_DEVICES
47 {
48 PPREFERENCES_CONTEXT PrefContext;
49 HWND hComboBox;
50 UINT Selected;
51 } PREFERENCES_FILL_DEVICES, *PPREFERENCES_FILL_DEVICES;
52
53 static BOOL CALLBACK
54 FillDeviceComboBox(PSND_MIXER Mixer,
55 UINT Id,
56 LPCTSTR ProductName,
57 PVOID Context)
58 {
59 LRESULT lres;
60 PPREFERENCES_FILL_DEVICES FillContext = (PPREFERENCES_FILL_DEVICES)Context;
61
62 UNREFERENCED_PARAMETER(Mixer);
63
64 lres = SendMessage(FillContext->hComboBox,
65 CB_ADDSTRING,
66 0,
67 (LPARAM)ProductName);
68 if (lres != CB_ERR)
69 {
70 /* save the index so we don't screw stuff when the combobox is sorted... */
71 SendMessage(FillContext->hComboBox,
72 CB_SETITEMDATA,
73 (WPARAM)lres,
74 Id);
75
76 if (Id == FillContext->Selected)
77 {
78 SendMessage(FillContext->hComboBox,
79 CB_SETCURSEL,
80 (WPARAM)lres,
81 0);
82 }
83 }
84
85 return TRUE;
86 }
87
88 static BOOL CALLBACK
89 PrefDlgAddLine(PSND_MIXER Mixer,
90 LPMIXERLINE Line,
91 UINT DisplayControls,
92 PVOID Context)
93 {
94 PPREFERENCES_CONTEXT PrefContext = (PPREFERENCES_CONTEXT)Context;
95
96 UNREFERENCED_PARAMETER(Mixer);
97 UNREFERENCED_PARAMETER(DisplayControls);
98
99 switch (Line->dwComponentType)
100 {
101 case MIXERLINE_COMPONENTTYPE_DST_SPEAKERS:
102 if (PrefContext->PlaybackID == (DWORD)-1)
103 {
104 PrefContext->PlaybackID = Line->dwLineID;
105
106 if (PrefContext->SelectedLine == (DWORD)-1)
107 {
108 PrefContext->SelectedLine = Line->dwLineID;
109 }
110 }
111 else
112 goto AddToOthersLines;
113
114 break;
115
116 case MIXERLINE_COMPONENTTYPE_DST_WAVEIN:
117 if (PrefContext->RecordingID == (DWORD)-1)
118 {
119 PrefContext->RecordingID = Line->dwLineID;
120
121 if (PrefContext->SelectedLine == (DWORD)-1)
122 {
123 PrefContext->SelectedLine = Line->dwLineID;
124 }
125 }
126 else
127 goto AddToOthersLines;
128
129 break;
130
131 default:
132 {
133 LRESULT lres;
134 HWND hwndCbOthers;
135
136 if (PrefContext->SelectedLine == (DWORD)-1)
137 {
138 PrefContext->SelectedLine = Line->dwLineID;
139 }
140
141 AddToOthersLines:
142 hwndCbOthers = GetDlgItem(PrefContext->hwndDlg,
143 IDC_LINE);
144
145 lres = SendMessage(hwndCbOthers,
146 CB_ADDSTRING,
147 0,
148 (LPARAM)Line->szName);
149 if (lres != CB_ERR)
150 {
151 SendMessage(hwndCbOthers,
152 CB_SETITEMDATA,
153 (WPARAM)lres,
154 Line->dwLineID);
155
156 PrefContext->OtherLines++;
157 }
158 break;
159 }
160 }
161
162 return TRUE;
163 }
164
165 static BOOL CALLBACK
166 PrefDlgAddConnection(PSND_MIXER Mixer,
167 DWORD LineID,
168 LPMIXERLINE Line,
169 PVOID Context)
170 {
171 PPREFERENCES_CONTEXT PrefContext = (PPREFERENCES_CONTEXT)Context;
172 HWND hwndControls;
173 LVITEM lvi;
174 UINT i;
175
176 UNREFERENCED_PARAMETER(Mixer);
177 UNREFERENCED_PARAMETER(LineID);
178
179 if (Line->cControls != 0)
180 {
181 hwndControls = GetDlgItem(PrefContext->hwndDlg,
182 IDC_CONTROLS);
183
184 lvi.mask = LVIF_TEXT | LVIF_PARAM;
185 lvi.iItem = PrefContext->tmp++;
186 lvi.iSubItem = 0;
187 lvi.pszText = Line->szName;
188 lvi.lParam = (LPARAM)Line->dwSource;
189
190 i = SendMessage(hwndControls,
191 LVM_INSERTITEM,
192 0,
193 (LPARAM)&lvi);
194 if (i != (UINT)-1)
195 {
196 TCHAR LineName[MIXER_LONG_NAME_CHARS];
197 DWORD Flags;
198 BOOL SelLine = FALSE;
199
200 if (SndMixerGetLineName(PrefContext->Mixer,
201 PrefContext->SelectedLine,
202 LineName,
203 MIXER_LONG_NAME_CHARS,
204 TRUE) == -1)
205 {
206 LineName[0] = TEXT('\0');
207 }
208
209 if (ReadLineConfig(PrefContext->DeviceName,
210 LineName,
211 Line->szName,
212 &Flags))
213 {
214 if (Flags != 0x4)
215 {
216 SelLine = TRUE;
217 }
218 }
219
220 ListView_SetCheckState(hwndControls,
221 i,
222 SelLine);
223 }
224 }
225
226 return TRUE;
227 }
228
229 static VOID
230 UpdatePrefDlgControls(PPREFERENCES_CONTEXT Context,
231 DWORD LineID)
232 {
233 INT OldID, MixerID = 0;
234 INT DeviceCbIndex;
235
236 /* select the mixer */
237 DeviceCbIndex = SendDlgItemMessage(Context->hwndDlg,
238 IDC_MIXERDEVICE,
239 CB_GETCURSEL,
240 0,
241 0);
242 if (DeviceCbIndex != CB_ERR)
243 {
244 MixerID = SendDlgItemMessage(Context->hwndDlg,
245 IDC_MIXERDEVICE,
246 CB_GETITEMDATA,
247 DeviceCbIndex,
248 0);
249 if (MixerID == CB_ERR)
250 {
251 MixerID = 0;
252 }
253 }
254
255 OldID = Context->Selected;
256 if (MixerID != OldID &&
257 SndMixerSelect(Context->Mixer,
258 MixerID))
259 {
260 Context->Selected = SndMixerGetSelection(Context->Mixer);
261
262 /* update the controls */
263 Context->PlaybackID = (DWORD)-1;
264 Context->RecordingID = (DWORD)-1;
265 Context->OtherLines = 0;
266 Context->SelectedLine = (DWORD)-1;
267
268 SndMixerGetProductName(Context->Mixer,
269 Context->DeviceName,
270 sizeof(Context->DeviceName) / sizeof(Context->DeviceName[0]));
271
272 if (SndMixerEnumLines(Context->Mixer,
273 PrefDlgAddLine,
274 Context))
275 {
276 UINT SelBox = 0;
277
278 /* enable/disable controls and make default selection */
279 EnableWindow(GetDlgItem(Context->hwndDlg,
280 IDC_PLAYBACK),
281 Context->PlaybackID != (DWORD)-1);
282 CheckDlgButton(Context->hwndDlg,
283 IDC_PLAYBACK,
284 (Context->PlaybackID != (DWORD)-1 && SelBox++ == 0) ?
285 BST_CHECKED : BST_UNCHECKED);
286
287 EnableWindow(GetDlgItem(Context->hwndDlg,
288 IDC_RECORDING),
289 Context->RecordingID != (DWORD)-1);
290 CheckDlgButton(Context->hwndDlg,
291 IDC_RECORDING,
292 (Context->RecordingID != (DWORD)-1 && SelBox++ == 0) ?
293 BST_CHECKED : BST_UNCHECKED);
294
295 if (Context->OtherLines != 0)
296 {
297 /* select the first item in the other lines combo box by default */
298 SendDlgItemMessage(Context->hwndDlg,
299 IDC_LINE,
300 CB_SETCURSEL,
301 0,
302 0);
303 }
304 EnableWindow(GetDlgItem(Context->hwndDlg,
305 IDC_LINE),
306 FALSE);
307 EnableWindow(GetDlgItem(Context->hwndDlg,
308 IDC_OTHER),
309 Context->OtherLines != 0);
310 CheckDlgButton(Context->hwndDlg,
311 IDC_LINE,
312 (Context->OtherLines != 0 && SelBox++ == 0) ?
313 BST_CHECKED : BST_UNCHECKED);
314
315 /* disable the OK button if the device doesn't have any lines */
316 EnableWindow(GetDlgItem(Context->hwndDlg,
317 IDOK),
318 Context->PlaybackID != (DWORD)-1 ||
319 Context->RecordingID != (DWORD)-1 ||
320 Context->OtherLines != 0);
321
322 LineID = Context->SelectedLine;
323 }
324 }
325
326 /* update the line sources list */
327 if ((MixerID != OldID && Context->SelectedLine != (DWORD)-1) ||
328 (Context->SelectedLine != LineID && LineID != (DWORD)-1))
329 {
330 Context->SelectedLine = LineID;
331
332 (void)ListView_DeleteAllItems(GetDlgItem(Context->hwndDlg,
333 IDC_CONTROLS));
334
335 Context->tmp = 0;
336 SndMixerEnumConnections(Context->Mixer,
337 LineID,
338 PrefDlgAddConnection,
339 Context);
340 }
341 }
342
343 static
344 VOID
345 WriteLineSettings(PPREFERENCES_CONTEXT Context, HWND hwndDlg)
346 {
347 HWND hwndControls;
348 INT Count, Index;
349 WCHAR LineName[MIXER_LONG_NAME_CHARS];
350 WCHAR DestinationName[MIXER_LONG_NAME_CHARS];
351 DWORD Flags;
352 PSNDVOL_REG_LINESTATE LineStates;
353
354 /* get list view */
355 hwndControls = GetDlgItem(hwndDlg, IDC_CONTROLS);
356
357 /* get list item count */
358 Count = ListView_GetItemCount(hwndControls);
359
360 /* sanity check */
361 assert(Count);
362
363 if (SndMixerGetLineName(Context->Mixer, Context->SelectedLine, DestinationName, MIXER_LONG_NAME_CHARS, TRUE) == -1)
364 {
365 /* failed to get destination line name */
366 return;
367 }
368
369 /* allocate line states array */
370 LineStates = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SNDVOL_REG_LINESTATE) * Count);
371 if (LineStates == NULL)
372 {
373 /* failed to allocate line states array */
374 return;
375 }
376
377
378 for(Index = 0; Index < Count; Index++)
379 {
380 /* set to empty */
381 LineName[0] = L'\0';
382
383 /* get item text */
384 ListView_GetItemText(hwndControls, Index, 0, LineName, MIXER_LONG_NAME_CHARS);
385
386 /* make sure it is null terminated */
387 LineName[MIXER_LONG_NAME_CHARS-1] = L'\0';
388
389 /* get check state */
390 Flags = (ListView_GetCheckState(hwndControls, Index) == 0 ? 0x4 : 0);
391
392 /* copy line name */
393 wcscpy(LineStates[Index].LineName, LineName);
394
395 /* store flags */
396 LineStates[Index].Flags = Flags;
397 }
398
399 /* now write the line config */
400 WriteLineConfig(Context->DeviceName, DestinationName, LineStates, sizeof(SNDVOL_REG_LINESTATE) * Count);
401
402 /* free line states */
403 HeapFree(GetProcessHeap(), 0, LineStates);
404 }
405
406 static INT_PTR CALLBACK
407 DlgPreferencesProc(HWND hwndDlg,
408 UINT uMsg,
409 WPARAM wParam,
410 LPARAM lParam)
411 {
412 PPREFERENCES_CONTEXT Context;
413
414 switch (uMsg)
415 {
416 case WM_COMMAND:
417 {
418 Context = GetDialogData(hwndDlg,
419 PREFERENCES_CONTEXT);
420 switch (LOWORD(wParam))
421 {
422 case IDC_MIXERDEVICE:
423 {
424 if (HIWORD(wParam) == CBN_SELCHANGE)
425 {
426 UpdatePrefDlgControls(Context,
427 (DWORD)-1);
428 }
429 break;
430 }
431
432 case IDC_LINE:
433 {
434 if (HIWORD(wParam) == CBN_SELCHANGE)
435 {
436 INT LineID;
437 INT Index;
438
439 Index = SendDlgItemMessage(hwndDlg,
440 IDC_LINE,
441 CB_GETCURSEL,
442 0,
443 0);
444 if (Index != CB_ERR)
445 {
446 LineID = SendDlgItemMessage(hwndDlg,
447 IDC_LINE,
448 CB_GETITEMDATA,
449 Index,
450 0);
451 if (LineID != CB_ERR)
452 {
453 UpdatePrefDlgControls(Context,
454 LineID);
455 }
456 }
457 }
458 break;
459 }
460
461 case IDC_PLAYBACK:
462 {
463 UpdatePrefDlgControls(Context,
464 Context->PlaybackID);
465 EnableWindow(GetDlgItem(hwndDlg,
466 IDC_LINE),
467 FALSE);
468 break;
469 }
470
471 case IDC_RECORDING:
472 {
473 UpdatePrefDlgControls(Context,
474 Context->RecordingID);
475 EnableWindow(GetDlgItem(hwndDlg,
476 IDC_LINE),
477 FALSE);
478 break;
479 }
480
481 case IDC_OTHER:
482 {
483 INT LineCbIndex;
484 INT LineID;
485
486 EnableWindow(GetDlgItem(hwndDlg,
487 IDC_LINE),
488 TRUE);
489
490 LineCbIndex = SendDlgItemMessage(hwndDlg,
491 IDC_LINE,
492 CB_GETCURSEL,
493 0,
494 0);
495 if (LineCbIndex != CB_ERR)
496 {
497 LineID = SendDlgItemMessage(hwndDlg,
498 IDC_LINE,
499 CB_GETITEMDATA,
500 LineCbIndex,
501 0);
502 if (LineID != CB_ERR)
503 {
504 UpdatePrefDlgControls(Context,
505 LineID);
506 }
507 }
508 break;
509 }
510
511 case IDOK:
512 {
513 /* write line settings */
514 WriteLineSettings(Context, hwndDlg);
515
516 /* fall through */
517 }
518 case IDCANCEL:
519 {
520 EndDialog(hwndDlg,
521 LOWORD(wParam));
522 break;
523 }
524 }
525 break;
526 }
527
528 case WM_INITDIALOG:
529 {
530 PREFERENCES_FILL_DEVICES FillDevContext;
531 LVCOLUMN lvc;
532 RECT rcClient;
533 HWND hwndControls;
534
535 SetWindowLongPtr(hwndDlg,
536 DWLP_USER,
537 (LONG_PTR)lParam);
538 Context = (PPREFERENCES_CONTEXT)((LONG_PTR)lParam);
539 Context->hwndDlg = hwndDlg;
540 Context->Mixer = SndMixerCreate(hwndDlg, Context->MixerWindow->MixerId);
541 Context->Selected = (UINT)-1;
542
543 FillDevContext.PrefContext = Context;
544 FillDevContext.hComboBox = GetDlgItem(hwndDlg,
545 IDC_MIXERDEVICE);
546 FillDevContext.Selected = SndMixerGetSelection(Context->Mixer);
547 SndMixerEnumProducts(Context->Mixer,
548 FillDeviceComboBox,
549 &FillDevContext);
550
551 /* initialize the list view control */
552 hwndControls = GetDlgItem(hwndDlg,
553 IDC_CONTROLS);
554 (void)ListView_SetExtendedListViewStyle(hwndControls,
555 LVS_EX_CHECKBOXES);
556
557 GetClientRect(hwndControls,
558 &rcClient);
559 lvc.mask = LVCF_TEXT | LVCF_WIDTH;
560 lvc.pszText = TEXT("");
561 lvc.cx = rcClient.right;
562 SendMessage(hwndControls,
563 LVM_INSERTCOLUMN,
564 0,
565 (LPARAM)&lvc);
566
567 /* update all controls */
568 UpdatePrefDlgControls(Context,
569 (DWORD)Context->SelectedLine);
570 return TRUE;
571 }
572
573 case WM_CLOSE:
574 {
575 EndDialog(hwndDlg,
576 IDCANCEL);
577 break;
578 }
579
580 case WM_SYSCOLORCHANGE:
581 {
582 HWND hwndControls;
583
584 /* Forward WM_SYSCOLORCHANGE */
585 hwndControls = GetDlgItem(hwndDlg, IDC_CONTROLS);
586 SendMessage(hwndControls, WM_SYSCOLORCHANGE, 0, 0);
587 break;
588 }
589 }
590
591 return 0;
592 }
593
594
595 static
596 INT_PTR
597 CALLBACK
598 AdvancedDlgProc(
599 HWND hwndDlg,
600 UINT uMsg,
601 WPARAM wParam,
602 LPARAM lParam)
603 {
604 switch (uMsg)
605 {
606 case WM_INITDIALOG:
607 /* FIXME: Update the dialog title */
608
609 /* Disable the tone controls */
610 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV_BASS_LOW), FALSE);
611 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV_BASS_HIGH), FALSE);
612 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV_BASS_SLIDER), FALSE);
613 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV_TREBLE_LOW), FALSE);
614 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV_TREBLE_HIGH), FALSE);
615 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV_TREBLE_SLIDER), FALSE);
616
617 /* Hide the other controls */
618 ShowWindow(GetDlgItem(hwndDlg, IDC_ADV_OTHER_CONTROLS), SW_HIDE);
619 ShowWindow(GetDlgItem(hwndDlg, IDC_ADV_OTHER_TEXT), SW_HIDE);
620 ShowWindow(GetDlgItem(hwndDlg, IDC_ADV_OTHER_CHECK1), SW_HIDE);
621 ShowWindow(GetDlgItem(hwndDlg, IDC_ADV_OTHER_CHECK2), SW_HIDE);
622
623 /* FIXME */
624 return TRUE;
625
626 case WM_COMMAND:
627 switch (LOWORD(wParam))
628 {
629 case IDOK:
630 EndDialog(hwndDlg, IDOK);
631 break;
632 }
633 break;
634
635 case WM_CLOSE:
636 EndDialog(hwndDlg, IDCANCEL);
637 break;
638 }
639
640 return FALSE;
641 }
642
643
644 /******************************************************************************/
645
646 static VOID
647 DeleteMixerWindowControls(PMIXER_WINDOW MixerWindow)
648 {
649 DWORD Index;
650
651 for(Index = 0; Index < MixerWindow->WindowCount; Index++)
652 {
653 /* destroys the window */
654 DestroyWindow(MixerWindow->Window[Index]);
655 }
656
657 /* free memory */
658 HeapFree(GetProcessHeap(), 0, MixerWindow->Window);
659
660 /* set to null */
661 MixerWindow->Window = NULL;
662 MixerWindow->WindowCount = 0;
663 }
664
665 static BOOL
666 RebuildMixerWindowControls(PPREFERENCES_CONTEXT PrefContext)
667 {
668 /* delete existing mixer controls */
669 DeleteMixerWindowControls(PrefContext->MixerWindow);
670
671 /* load new mixer controls */
672 LoadDialogCtrls(PrefContext);
673
674 return TRUE;
675 }
676
677 static
678 BOOL
679 CALLBACK
680 SetVolumeCallback(PSND_MIXER Mixer, DWORD LineID, LPMIXERLINE Line, PVOID Ctx)
681 {
682 UINT ControlCount = 0, Index;
683 LPMIXERCONTROL Control = NULL;
684 PMIXERCONTROLDETAILS_UNSIGNED puDetails = NULL;
685 MIXERCONTROLDETAILS_BOOLEAN bDetails;
686 PSET_VOLUME_CONTEXT Context = (PSET_VOLUME_CONTEXT)Ctx;
687
688 /* check if the line name is equal */
689 if (wcsicmp(Line->szName, Context->LineName))
690 {
691 /* it is not */
692 return TRUE;
693 }
694
695 /* query controls */
696 if (SndMixerQueryControls(Mixer, &ControlCount, Line, &Control) == FALSE)
697 {
698 /* failed to query for controls */
699 return FALSE;
700 }
701
702 puDetails = HeapAlloc(GetProcessHeap(), 0, Line->cChannels * sizeof(MIXERCONTROLDETAILS_UNSIGNED));
703 if (puDetails == NULL)
704 return FALSE;
705
706 /* now go through all controls and compare control ids */
707 for (Index = 0; Index < ControlCount; Index++)
708 {
709 if (Context->bVertical)
710 {
711 if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_FADER)
712 {
713 DWORD LineOffset, volumePosition, balancePosition;
714 DWORD volumeStep, balanceStep;
715
716 LineOffset = Context->SliderPos;
717
718 volumePosition = (DWORD)SendDlgItemMessage(Preferences.MixerWindow->hWnd, LineOffset * IDC_LINE_SLIDER_VERT, TBM_GETPOS, 0, 0);
719 volumeStep = (Control[Index].Bounds.dwMaximum - Control[Index].Bounds.dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
720
721 if (Line->cChannels == 1)
722 {
723 /* set up details */
724 puDetails[0].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
725 }
726 else if (Line->cChannels == 2)
727 {
728 balancePosition = (DWORD)SendDlgItemMessage(Preferences.MixerWindow->hWnd, LineOffset * IDC_LINE_SLIDER_HORZ, TBM_GETPOS, 0, 0);
729 if (balancePosition == BALANCE_CENTER)
730 {
731 puDetails[0].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
732 puDetails[1].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
733 }
734 else if (balancePosition == BALANCE_LEFT)
735 {
736 puDetails[0].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
737 puDetails[1].dwValue = Control[Index].Bounds.dwMinimum;
738 }
739 else if (balancePosition == BALANCE_RIGHT)
740 {
741 puDetails[0].dwValue = Control[Index].Bounds.dwMinimum;
742 puDetails[1].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
743 }
744 else if (balancePosition < BALANCE_CENTER) // Left
745 {
746 puDetails[0].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
747
748 balanceStep = (puDetails[0].dwValue - Control[Index].Bounds.dwMinimum) / (BALANCE_STEPS / 2);
749
750 puDetails[1].dwValue = (balancePosition * balanceStep) + Control[Index].Bounds.dwMinimum;
751 }
752 else if (balancePosition > BALANCE_CENTER) // Right
753 {
754 puDetails[1].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
755
756 balanceStep = (puDetails[1].dwValue - Control[Index].Bounds.dwMinimum) / (BALANCE_STEPS / 2);
757
758 puDetails[0].dwValue = ((BALANCE_RIGHT - balancePosition) * balanceStep) + Control[Index].Bounds.dwMinimum;
759 }
760 }
761 else
762 {
763 SndMixerGetVolumeControlDetails(Preferences.MixerWindow->Mixer, Control[Index].dwControlID, Line->cChannels, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)puDetails);
764
765 /* FIXME */
766 }
767
768 /* set volume */
769 SndMixerSetVolumeControlDetails(Preferences.MixerWindow->Mixer, Control[Index].dwControlID, Line->cChannels, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)puDetails);
770
771 /* done */
772 break;
773 }
774 }
775 else if (Context->bSwitch)
776 {
777 if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_SWITCH)
778 {
779 /* set up details */
780 bDetails.fValue = Context->SliderPos;
781
782 /* set volume */
783 SndMixerSetVolumeControlDetails(Preferences.MixerWindow->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN), (LPVOID)&bDetails);
784
785 /* done */
786 break;
787 }
788 }
789 }
790
791 if (puDetails != NULL)
792 HeapFree(GetProcessHeap(), 0, puDetails);
793
794 /* free controls */
795 HeapFree(GetProcessHeap(), 0, Control);
796
797
798 /* done */
799 return TRUE;
800 }
801
802 static
803 BOOL
804 CALLBACK
805 MixerControlChangeCallback(PSND_MIXER Mixer, DWORD LineID, LPMIXERLINE Line, PVOID Context)
806 {
807 PMIXERCONTROLDETAILS_UNSIGNED pVolumeDetails = NULL;
808 UINT ControlCount = 0, Index;
809 LPMIXERCONTROL Control = NULL;
810
811 /* check if the line has controls */
812 if (Line->cControls == 0)
813 {
814 /* no controls */
815 return TRUE;
816 }
817
818 /* query controls */
819 if (SndMixerQueryControls(Mixer, &ControlCount, Line, &Control) == FALSE)
820 {
821 /* failed to query for controls */
822 return FALSE;
823 }
824
825 pVolumeDetails = HeapAlloc(GetProcessHeap(),
826 0,
827 Line->cChannels * sizeof(MIXERCONTROLDETAILS_UNSIGNED));
828 if (pVolumeDetails == NULL)
829 goto done;
830
831 /* now go through all controls and compare control ids */
832 for (Index = 0; Index < ControlCount; Index++)
833 {
834 if (Control[Index].dwControlID == PtrToUlong(Context))
835 {
836 if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_SWITCH)
837 {
838 MIXERCONTROLDETAILS_BOOLEAN Details;
839
840 /* get volume control details */
841 if (SndMixerGetVolumeControlDetails(Preferences.MixerWindow->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN), (LPVOID)&Details) != -1)
842 {
843 /* update dialog control */
844 UpdateDialogLineSwitchControl(&Preferences, Line, Details.fValue);
845 }
846 }
847 else if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_FADER)
848 {
849 /* get volume control details */
850 if (SndMixerGetVolumeControlDetails(Preferences.MixerWindow->Mixer, Control[Index].dwControlID, Line->cChannels, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)pVolumeDetails) != -1)
851 {
852 /* update dialog control */
853 DWORD volumePosition, volumeStep, maxVolume, i;
854 DWORD balancePosition, balanceStep;
855
856 volumeStep = (Control[Index].Bounds.dwMaximum - Control[Index].Bounds.dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
857
858 maxVolume = 0;
859 for (i = 0; i < Line->cChannels; i++)
860 {
861 if (pVolumeDetails[i].dwValue > maxVolume)
862 maxVolume = pVolumeDetails[i].dwValue;
863 }
864
865 volumePosition = (maxVolume - Control[Index].Bounds.dwMinimum) / volumeStep;
866
867 if (Line->cChannels == 1)
868 {
869 balancePosition = BALANCE_CENTER;
870 }
871 else if (Line->cChannels == 2)
872 {
873 if (pVolumeDetails[0].dwValue == pVolumeDetails[1].dwValue)
874 {
875 balancePosition = BALANCE_CENTER;
876 }
877 else if (pVolumeDetails[0].dwValue == Control[Index].Bounds.dwMinimum)
878 {
879 balancePosition = BALANCE_RIGHT;
880 }
881 else if (pVolumeDetails[1].dwValue == Control[Index].Bounds.dwMinimum)
882 {
883 balancePosition = BALANCE_LEFT;
884 }
885 else
886 {
887 balanceStep = (maxVolume - Control[Index].Bounds.dwMinimum) / (BALANCE_STEPS / 2);
888
889 if (pVolumeDetails[0].dwValue < pVolumeDetails[1].dwValue)
890 {
891 balancePosition = (pVolumeDetails[0].dwValue - Control[Index].Bounds.dwMinimum) / balanceStep;
892 balancePosition = BALANCE_RIGHT - balancePosition;
893 }
894 else if (pVolumeDetails[1].dwValue < pVolumeDetails[0].dwValue)
895 {
896 balancePosition = (pVolumeDetails[1].dwValue - Control[Index].Bounds.dwMinimum) / balanceStep;
897 balancePosition = BALANCE_LEFT + balancePosition;
898 }
899 }
900 }
901
902 /* Update the volume control slider */
903 UpdateDialogLineSliderControl(&Preferences, Line, IDC_LINE_SLIDER_VERT, VOLUME_MAX - volumePosition);
904
905 /* Update the balance control slider */
906 UpdateDialogLineSliderControl(&Preferences, Line, IDC_LINE_SLIDER_HORZ, balancePosition);
907 }
908 }
909 break;
910 }
911 }
912
913 done:
914 /* Free the volume details */
915 if (pVolumeDetails)
916 HeapFree(GetProcessHeap(), 0, pVolumeDetails);
917
918 /* free controls */
919 HeapFree(GetProcessHeap(), 0, Control);
920
921 /* done */
922 return TRUE;
923 }
924
925 static LRESULT CALLBACK
926 MainWindowProc(HWND hwnd,
927 UINT uMsg,
928 WPARAM wParam,
929 LPARAM lParam)
930 {
931 PMIXER_WINDOW MixerWindow;
932 DWORD CtrlID, LineOffset;
933 LRESULT Result = 0;
934 SET_VOLUME_CONTEXT Context;
935
936 switch (uMsg)
937 {
938 case WM_COMMAND:
939 {
940 MixerWindow = GetWindowData(hwnd,
941 MIXER_WINDOW);
942
943 switch (LOWORD(wParam))
944 {
945 case IDM_PROPERTIES:
946 {
947 PREFERENCES_CONTEXT Pref;
948
949 Pref.MixerWindow = MixerWindow;
950 Pref.Mixer = NULL;
951 Pref.SelectedLine = Preferences.SelectedLine;
952
953 if (DialogBoxParam(hAppInstance,
954 MAKEINTRESOURCE(IDD_PREFERENCES),
955 hwnd,
956 DlgPreferencesProc,
957 (LPARAM)&Pref) == IDOK)
958 {
959 /* update window */
960 TCHAR szProduct[MAXPNAMELEN];
961
962 /* get mixer product name */
963 if (SndMixerGetProductName(Pref.Mixer,
964 szProduct,
965 sizeof(szProduct) / sizeof(szProduct[0])) == -1)
966 {
967 /* failed to get name */
968 szProduct[0] = L'\0';
969 }
970 else
971 {
972 /* copy product */
973 wcscpy(Preferences.DeviceName, szProduct);
974 }
975
976 /* destroy old status bar */
977 if (MixerWindow->Mode == NORMAL_MODE)
978 DestroyWindow(MixerWindow->hStatusBar);
979
980 /* update details */
981 Preferences.SelectedLine = Pref.SelectedLine;
982
983 /* destroy old mixer */
984 SndMixerDestroy(Preferences.MixerWindow->Mixer);
985
986 /* use new selected mixer */
987 Preferences.MixerWindow->Mixer = Pref.Mixer;
988
989 /* create status window */
990 if (MixerWindow->Mode == NORMAL_MODE)
991 {
992 MixerWindow->hStatusBar = CreateStatusWindow(WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS,
993 NULL,
994 hwnd,
995 0);
996 if (MixerWindow->hStatusBar)
997 {
998 /* Set status bar */
999 SendMessage(MixerWindow->hStatusBar,
1000 WM_SETTEXT,
1001 0,
1002 (LPARAM)szProduct);
1003 }
1004 }
1005
1006 /* rebuild dialog controls */
1007 RebuildMixerWindowControls(&Preferences);
1008 }
1009 break;
1010 }
1011
1012 case IDM_ADVANCED_CONTROLS:
1013 MixerWindow->bShowExtendedControls = !MixerWindow->bShowExtendedControls;
1014 CheckMenuItem(GetMenu(hwnd),
1015 IDM_ADVANCED_CONTROLS,
1016 MF_BYCOMMAND | (MixerWindow->bShowExtendedControls ? MF_CHECKED : MF_UNCHECKED));
1017 RebuildMixerWindowControls(&Preferences);
1018 break;
1019
1020 case IDM_EXIT:
1021 {
1022 PostQuitMessage(0);
1023 break;
1024 }
1025
1026 case IDM_ABOUT:
1027 {
1028 HICON hAppIcon = (HICON)GetClassLongPtrW(hwnd,
1029 GCLP_HICON);
1030 ShellAbout(hwnd,
1031 lpAppTitle,
1032 NULL,
1033 hAppIcon);
1034 break;
1035 }
1036
1037 default:
1038 {
1039 /* get button id */
1040 CtrlID = LOWORD(wParam);
1041
1042 /* check if the message is from the line switch */
1043 if (HIWORD(wParam) == BN_CLICKED)
1044 {
1045 if (CtrlID % IDC_LINE_SWITCH == 0)
1046 {
1047 /* compute line offset */
1048 LineOffset = CtrlID / IDC_LINE_SWITCH;
1049
1050 /* compute window id of line name static control */
1051 CtrlID = LineOffset * IDC_LINE_NAME;
1052
1053 /* get line name */
1054 if (GetDlgItemTextW(hwnd, CtrlID, Context.LineName, MIXER_LONG_NAME_CHARS) != 0)
1055 {
1056 /* setup context */
1057 Context.SliderPos = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
1058 Context.bVertical = FALSE;
1059 Context.bSwitch = TRUE;
1060
1061 /* set volume */
1062 SndMixerEnumConnections(Preferences.MixerWindow->Mixer, Preferences.SelectedLine, SetVolumeCallback, (LPVOID)&Context);
1063 }
1064 }
1065 else if (CtrlID % IDC_LINE_ADVANCED == 0)
1066 {
1067 if (DialogBoxParam(hAppInstance,
1068 MAKEINTRESOURCE(IDD_ADVANCED),
1069 hwnd,
1070 AdvancedDlgProc,
1071 (LPARAM)NULL) == IDOK)
1072 {
1073
1074 }
1075 }
1076 }
1077 }
1078 }
1079 break;
1080 }
1081
1082 case MM_MIXM_LINE_CHANGE:
1083 {
1084 DPRINT("MM_MIXM_LINE_CHANGE\n");
1085 break;
1086 }
1087
1088 case MM_MIXM_CONTROL_CHANGE:
1089 {
1090 DPRINT("MM_MIXM_CONTROL_CHANGE\n");
1091
1092 /* get mixer window */
1093 MixerWindow = GetWindowData(hwnd,
1094 MIXER_WINDOW);
1095
1096 /* sanity checks */
1097 assert(MixerWindow);
1098 assert(MixerWindow->Mixer->hmx == (HMIXER)wParam);
1099
1100 SndMixerEnumConnections(MixerWindow->Mixer, Preferences.SelectedLine, MixerControlChangeCallback, (PVOID)lParam);
1101 break;
1102 }
1103
1104 case WM_VSCROLL:
1105 switch (LOWORD(wParam))
1106 {
1107 case TB_THUMBTRACK:
1108 /* get dialog item ctrl */
1109 CtrlID = GetDlgCtrlID((HWND)lParam);
1110
1111 /* get line index */
1112 LineOffset = CtrlID / IDC_LINE_SLIDER_VERT;
1113
1114 /* compute window id of line name static control */
1115 CtrlID = LineOffset * IDC_LINE_NAME;
1116
1117 /* get line name */
1118 if (GetDlgItemTextW(hwnd, CtrlID, Context.LineName, MIXER_LONG_NAME_CHARS) != 0)
1119 {
1120 /* setup context */
1121 Context.SliderPos = LineOffset;
1122 Context.bVertical = TRUE;
1123 Context.bSwitch = FALSE;
1124
1125 /* set volume */
1126 SndMixerEnumConnections(Preferences.MixerWindow->Mixer, Preferences.SelectedLine, SetVolumeCallback, (LPVOID)&Context);
1127 }
1128 break;
1129
1130 case TB_ENDTRACK:
1131 MixerWindow = GetWindowData(hwnd,
1132 MIXER_WINDOW);
1133
1134 /* get dialog item ctrl */
1135 CtrlID = GetDlgCtrlID((HWND)lParam);
1136
1137 /* get line index */
1138 LineOffset = CtrlID / IDC_LINE_SLIDER_VERT;
1139
1140 if (LineOffset == 1 && MixerWindow->Mixer->MixerId == 0)
1141 PlaySound((LPCTSTR)SND_ALIAS_SYSTEMDEFAULT, NULL, SND_ASYNC | SND_ALIAS_ID);
1142 break;
1143
1144 default:
1145 break;
1146 }
1147 break;
1148
1149 case WM_HSCROLL:
1150 switch (LOWORD(wParam))
1151 {
1152 case TB_THUMBTRACK:
1153 /* get dialog item ctrl */
1154 CtrlID = GetDlgCtrlID((HWND)lParam);
1155
1156 /* get line index */
1157 LineOffset = CtrlID / IDC_LINE_SLIDER_HORZ;
1158
1159 /* compute window id of line name static control */
1160 CtrlID = LineOffset * IDC_LINE_NAME;
1161
1162 /* get line name */
1163 if (GetDlgItemTextW(hwnd, CtrlID, Context.LineName, MIXER_LONG_NAME_CHARS) != 0)
1164 {
1165 /* setup context */
1166 Context.SliderPos = LineOffset;
1167 Context.bVertical = TRUE;
1168 Context.bSwitch = FALSE;
1169
1170 /* set volume */
1171 SndMixerEnumConnections(Preferences.MixerWindow->Mixer, Preferences.SelectedLine, SetVolumeCallback, (LPVOID)&Context);
1172 }
1173 break;
1174
1175 case TB_ENDTRACK:
1176 MixerWindow = GetWindowData(hwnd,
1177 MIXER_WINDOW);
1178
1179 /* get dialog item ctrl */
1180 CtrlID = GetDlgCtrlID((HWND)lParam);
1181
1182 /* get line index */
1183 LineOffset = CtrlID / IDC_LINE_SLIDER_HORZ;
1184
1185 if (LineOffset == 1 && MixerWindow->Mixer->MixerId == 0)
1186 PlaySound((LPCTSTR)SND_ALIAS_SYSTEMDEFAULT, NULL, SND_ASYNC | SND_ALIAS_ID);
1187 break;
1188
1189 default:
1190 break;
1191 }
1192 break;
1193
1194
1195 case WM_CREATE:
1196 {
1197 MixerWindow = ((LPCREATESTRUCT)lParam)->lpCreateParams;
1198 SetWindowLongPtr(hwnd,
1199 GWL_USERDATA,
1200 (LONG_PTR)MixerWindow);
1201 MixerWindow->hWnd = hwnd;
1202 MixerWindow->Mixer = SndMixerCreate(MixerWindow->hWnd, MixerWindow->MixerId);
1203 if (MixerWindow->Mixer != NULL)
1204 {
1205 TCHAR szProduct[MAXPNAMELEN];
1206
1207 /* get mixer product name */
1208 if (SndMixerGetProductName(MixerWindow->Mixer,
1209 szProduct,
1210 sizeof(szProduct) / sizeof(szProduct[0])) == -1)
1211 {
1212 /* failed to get name */
1213 szProduct[0] = L'\0';
1214 }
1215
1216
1217 /* initialize preferences */
1218 ZeroMemory(&Preferences, sizeof(Preferences));
1219
1220 /* store mixer */
1221 Preferences.Mixer = MixerWindow->Mixer;
1222
1223 /* store mixer window */
1224 Preferences.MixerWindow = MixerWindow;
1225
1226 /* first destination line id */
1227 Preferences.SelectedLine = 0xFFFF0000;
1228
1229 /* copy product */
1230 wcscpy(Preferences.DeviceName, szProduct);
1231
1232 /* Disable the 'Advanced Controls' menu item */
1233 EnableMenuItem(GetMenu(hwnd), IDM_ADVANCED_CONTROLS, MF_BYCOMMAND | MF_GRAYED);
1234
1235 /* create status window */
1236 if (MixerWindow->Mode == NORMAL_MODE)
1237 {
1238 MixerWindow->hStatusBar = CreateStatusWindow(WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS,
1239 NULL,
1240 hwnd,
1241 0);
1242 if (MixerWindow->hStatusBar)
1243 {
1244 SendMessage(MixerWindow->hStatusBar,
1245 WM_SETTEXT,
1246 0,
1247 (LPARAM)szProduct);
1248 }
1249 }
1250
1251 if (!RebuildMixerWindowControls(&Preferences))
1252 {
1253 DPRINT("Rebuilding mixer window controls failed!\n");
1254 SndMixerDestroy(MixerWindow->Mixer);
1255 MixerWindow->Mixer = NULL;
1256 Result = -1;
1257 }
1258 }
1259 break;
1260 }
1261
1262 case WM_DESTROY:
1263 {
1264 MixerWindow = GetWindowData(hwnd,
1265 MIXER_WINDOW);
1266 if (MixerWindow != NULL)
1267 {
1268 if (MixerWindow->Mixer != NULL)
1269 {
1270 SndMixerDestroy(MixerWindow->Mixer);
1271 }
1272 if (MixerWindow->hFont)
1273 DeleteObject(MixerWindow->hFont);
1274 HeapFree(hAppHeap, 0, MixerWindow);
1275 }
1276 break;
1277 }
1278
1279 case WM_CLOSE:
1280 {
1281 PostQuitMessage(0);
1282 break;
1283 }
1284
1285 default:
1286 {
1287 Result = DefWindowProc(hwnd,
1288 uMsg,
1289 wParam,
1290 lParam);
1291 break;
1292 }
1293 }
1294
1295 return Result;
1296 }
1297
1298 static BOOL
1299 RegisterApplicationClasses(VOID)
1300 {
1301 WNDCLASSEX wc;
1302
1303 wc.cbSize = sizeof(WNDCLASSEX);
1304 wc.style = CS_HREDRAW | CS_VREDRAW;
1305 wc.lpfnWndProc = MainWindowProc;
1306 wc.cbClsExtra = 0;
1307 wc.cbWndExtra = sizeof(PMIXER_WINDOW);
1308 wc.hInstance = hAppInstance;
1309 wc.hIcon = LoadIcon(hAppInstance,
1310 MAKEINTRESOURCE(IDI_MAINAPP));
1311 wc.hCursor = LoadCursor(NULL,
1312 IDC_ARROW);
1313 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1314 wc.lpszMenuName = NULL;
1315 wc.lpszClassName = SZ_APP_CLASS;
1316 wc.hIconSm = NULL;
1317 MainWindowClass = RegisterClassEx(&wc);
1318
1319 return MainWindowClass != 0;
1320 }
1321
1322 static VOID
1323 UnregisterApplicationClasses(VOID)
1324 {
1325 UnregisterClass(SZ_APP_CLASS,
1326 hAppInstance);
1327 }
1328
1329 static HWND
1330 CreateApplicationWindow(
1331 WINDOW_MODE WindowMode,
1332 UINT MixerId)
1333 {
1334 HWND hWnd;
1335
1336 PMIXER_WINDOW MixerWindow = HeapAlloc(hAppHeap,
1337 HEAP_ZERO_MEMORY,
1338 sizeof(MIXER_WINDOW));
1339 if (MixerWindow == NULL)
1340 {
1341 return NULL;
1342 }
1343
1344 MixerWindow->Mode = WindowMode;
1345 MixerWindow->MixerId = MixerId;
1346
1347 if (mixerGetNumDevs() > 0)
1348 {
1349 hWnd = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT,
1350 SZ_APP_CLASS,
1351 lpAppTitle,
1352 WS_DLGFRAME | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE,
1353 0, 0, 300, 315,
1354 NULL,
1355 LoadMenu(hAppInstance,
1356 MAKEINTRESOURCE(IDM_MAINMENU)),
1357 hAppInstance,
1358 MixerWindow);
1359 }
1360 else
1361 {
1362 LPTSTR lpErrMessage;
1363
1364 /*
1365 * no mixer devices are available!
1366 */
1367
1368 hWnd = NULL;
1369 if (AllocAndLoadString(&lpErrMessage,
1370 hAppInstance,
1371 IDS_NOMIXERDEVICES))
1372 {
1373 MessageBox(NULL,
1374 lpErrMessage,
1375 lpAppTitle,
1376 MB_ICONINFORMATION);
1377 LocalFree(lpErrMessage);
1378 }
1379 }
1380
1381 if (hWnd == NULL)
1382 {
1383 HeapFree(hAppHeap,
1384 0,
1385 MixerWindow);
1386 }
1387
1388 return hWnd;
1389 }
1390
1391 static
1392 BOOL
1393 HandleCommandLine(LPTSTR cmdline,
1394 DWORD dwStyle,
1395 PWINDOW_MODE pMode,
1396 PUINT pMixerId)
1397 {
1398 TCHAR option;
1399
1400 *pMixerId = PLAY_MIXER;
1401 *pMode = (dwStyle & 0x20) ? SMALL_MODE : NORMAL_MODE;
1402
1403 while (*cmdline == _T(' ') || *cmdline == _T('-') || *cmdline == _T('/'))
1404 {
1405 if (*cmdline++ == _T(' '))
1406 continue;
1407
1408 option = *cmdline;
1409 if (option)
1410 cmdline++;
1411 while (*cmdline == _T(' '))
1412 cmdline++;
1413
1414 switch (option)
1415 {
1416 case 'd': /* Device */
1417 case 'D':
1418 break;
1419
1420 case 'n': /* Small size */
1421 case 'N':
1422 *pMode = NORMAL_MODE;
1423 break;
1424
1425 case 's': /* Small size */
1426 case 'S':
1427 *pMode = SMALL_MODE;
1428 break;
1429
1430 case 't': /* Tray size */
1431 case 'T':
1432 *pMode = TRAY_MODE;
1433 break;
1434
1435 case 'p': /* Play mode */
1436 case 'P':
1437 *pMixerId = PLAY_MIXER;
1438 break;
1439
1440 case 'r': /* Record mode */
1441 case 'R':
1442 *pMixerId = RECORD_MIXER;
1443 break;
1444
1445 default:
1446 return FALSE;
1447 }
1448 }
1449
1450 return TRUE;
1451 }
1452
1453 int WINAPI
1454 _tWinMain(HINSTANCE hInstance,
1455 HINSTANCE hPrevInstance,
1456 LPTSTR lpszCmdLine,
1457 int nCmdShow)
1458 {
1459 MSG Msg;
1460 int Ret = 1;
1461 INITCOMMONCONTROLSEX Controls;
1462 WINDOW_MODE WindowMode = SMALL_MODE;
1463 UINT MixerId = 0;
1464 DWORD dwStyle;
1465
1466 UNREFERENCED_PARAMETER(hPrevInstance);
1467 UNREFERENCED_PARAMETER(nCmdShow);
1468
1469 hAppInstance = hInstance;
1470 hAppHeap = GetProcessHeap();
1471
1472 if (InitAppConfig())
1473 {
1474 dwStyle = GetStyleValue();
1475 HandleCommandLine(lpszCmdLine, dwStyle, &WindowMode, &MixerId);
1476
1477 /* load the application title */
1478 if (!AllocAndLoadString(&lpAppTitle,
1479 hAppInstance,
1480 IDS_SNDVOL32))
1481 {
1482 lpAppTitle = NULL;
1483 }
1484
1485 Controls.dwSize = sizeof(INITCOMMONCONTROLSEX);
1486 Controls.dwICC = ICC_BAR_CLASSES | ICC_STANDARD_CLASSES;
1487
1488 InitCommonControlsEx(&Controls);
1489
1490 if (WindowMode == TRAY_MODE)
1491 {
1492 DialogBoxParam(hAppInstance,
1493 MAKEINTRESOURCE(IDD_TRAY_MASTER),
1494 NULL,
1495 TrayDlgProc,
1496 0);
1497 }
1498 else
1499 {
1500 if (RegisterApplicationClasses())
1501 {
1502 hMainWnd = CreateApplicationWindow(WindowMode, MixerId);
1503 if (hMainWnd != NULL)
1504 {
1505 BOOL bRet;
1506 while ((bRet =GetMessage(&Msg,
1507 NULL,
1508 0,
1509 0)) != 0)
1510 {
1511 if (bRet != -1)
1512 {
1513 TranslateMessage(&Msg);
1514 DispatchMessage(&Msg);
1515 }
1516 }
1517
1518 DestroyWindow(hMainWnd);
1519 Ret = 0;
1520 }
1521 else
1522 {
1523 DPRINT("Failed to create application window (LastError: %d)!\n", GetLastError());
1524 }
1525
1526 UnregisterApplicationClasses();
1527 }
1528 else
1529 {
1530 DPRINT("Failed to register application classes (LastError: %d)!\n", GetLastError());
1531 }
1532 }
1533
1534 if (lpAppTitle != NULL)
1535 {
1536 LocalFree(lpAppTitle);
1537 }
1538
1539 CloseAppConfig();
1540 }
1541 else
1542 {
1543 DPRINT("Unable to open the Volume Control registry key!\n");
1544 }
1545
1546 return Ret;
1547 }