[SNDVOL32] Fix the window height issue when the line selection changes and implement...
[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 /******************************************************************************/
596
597 static VOID
598 DeleteMixerWindowControls(PMIXER_WINDOW MixerWindow)
599 {
600 DWORD Index;
601
602 for(Index = 0; Index < MixerWindow->WindowCount; Index++)
603 {
604 /* destroys the window */
605 DestroyWindow(MixerWindow->Window[Index]);
606 }
607
608 /* free memory */
609 HeapFree(GetProcessHeap(), 0, MixerWindow->Window);
610
611 /* set to null */
612 MixerWindow->Window = NULL;
613 MixerWindow->WindowCount = 0;
614 }
615
616 static BOOL
617 RebuildMixerWindowControls(PPREFERENCES_CONTEXT PrefContext)
618 {
619 /* delete existing mixer controls */
620 DeleteMixerWindowControls(PrefContext->MixerWindow);
621
622 /* load new mixer controls */
623 LoadDialogCtrls(PrefContext);
624
625 return TRUE;
626 }
627
628 static
629 BOOL
630 CALLBACK
631 SetVolumeCallback(PSND_MIXER Mixer, DWORD LineID, LPMIXERLINE Line, PVOID Ctx)
632 {
633 UINT ControlCount = 0, Index;
634 LPMIXERCONTROL Control = NULL;
635 PMIXERCONTROLDETAILS_UNSIGNED puDetails = NULL;
636 MIXERCONTROLDETAILS_BOOLEAN bDetails;
637 PSET_VOLUME_CONTEXT Context = (PSET_VOLUME_CONTEXT)Ctx;
638
639 /* check if the line name is equal */
640 if (wcsicmp(Line->szName, Context->LineName))
641 {
642 /* it is not */
643 return TRUE;
644 }
645
646 /* query controls */
647 if (SndMixerQueryControls(Mixer, &ControlCount, Line, &Control) == FALSE)
648 {
649 /* failed to query for controls */
650 return FALSE;
651 }
652
653 puDetails = HeapAlloc(GetProcessHeap(), 0, Line->cChannels * sizeof(MIXERCONTROLDETAILS_UNSIGNED));
654 if (puDetails == NULL)
655 return FALSE;
656
657 /* now go through all controls and compare control ids */
658 for (Index = 0; Index < ControlCount; Index++)
659 {
660 if (Context->bVertical)
661 {
662 if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_FADER)
663 {
664 DWORD LineOffset, volumePosition, balancePosition;
665 DWORD volumeStep, balanceStep;
666
667 LineOffset = Context->SliderPos;
668
669 volumePosition = (DWORD)SendDlgItemMessage(Preferences.MixerWindow->hWnd, LineOffset * IDC_LINE_SLIDER_VERT, TBM_GETPOS, 0, 0);
670 volumeStep = (Control[Index].Bounds.dwMaximum - Control[Index].Bounds.dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
671
672 if (Line->cChannels == 1)
673 {
674 /* set up details */
675 puDetails[0].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
676 }
677 else if (Line->cChannels == 2)
678 {
679 balancePosition = (DWORD)SendDlgItemMessage(Preferences.MixerWindow->hWnd, LineOffset * IDC_LINE_SLIDER_HORZ, TBM_GETPOS, 0, 0);
680 if (balancePosition == BALANCE_CENTER)
681 {
682 puDetails[0].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
683 puDetails[1].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
684 }
685 else if (balancePosition == BALANCE_LEFT)
686 {
687 puDetails[0].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
688 puDetails[1].dwValue = Control[Index].Bounds.dwMinimum;
689 }
690 else if (balancePosition == BALANCE_RIGHT)
691 {
692 puDetails[0].dwValue = Control[Index].Bounds.dwMinimum;
693 puDetails[1].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
694 }
695 else if (balancePosition < BALANCE_CENTER) // Left
696 {
697 puDetails[0].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
698
699 balanceStep = (puDetails[0].dwValue - Control[Index].Bounds.dwMinimum) / (BALANCE_STEPS / 2);
700
701 puDetails[1].dwValue = (balancePosition * balanceStep) + Control[Index].Bounds.dwMinimum;
702 }
703 else if (balancePosition > BALANCE_CENTER) // Right
704 {
705 puDetails[1].dwValue = ((VOLUME_MAX - volumePosition) * volumeStep) + Control[Index].Bounds.dwMinimum;
706
707 balanceStep = (puDetails[1].dwValue - Control[Index].Bounds.dwMinimum) / (BALANCE_STEPS / 2);
708
709 puDetails[0].dwValue = ((BALANCE_RIGHT - balancePosition) * balanceStep) + Control[Index].Bounds.dwMinimum;
710 }
711 }
712 else
713 {
714 SndMixerGetVolumeControlDetails(Preferences.MixerWindow->Mixer, Control[Index].dwControlID, Line->cChannels, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)puDetails);
715
716 /* FIXME */
717 }
718
719 /* set volume */
720 SndMixerSetVolumeControlDetails(Preferences.MixerWindow->Mixer, Control[Index].dwControlID, Line->cChannels, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)puDetails);
721
722 /* done */
723 break;
724 }
725 }
726 else if (Context->bSwitch)
727 {
728 if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_SWITCH)
729 {
730 /* set up details */
731 bDetails.fValue = Context->SliderPos;
732
733 /* set volume */
734 SndMixerSetVolumeControlDetails(Preferences.MixerWindow->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN), (LPVOID)&bDetails);
735
736 /* done */
737 break;
738 }
739 }
740 }
741
742 if (puDetails != NULL)
743 HeapFree(GetProcessHeap(), 0, puDetails);
744
745 /* free controls */
746 HeapFree(GetProcessHeap(), 0, Control);
747
748
749 /* done */
750 return TRUE;
751 }
752
753 static
754 BOOL
755 CALLBACK
756 MixerControlChangeCallback(PSND_MIXER Mixer, DWORD LineID, LPMIXERLINE Line, PVOID Context)
757 {
758 PMIXERCONTROLDETAILS_UNSIGNED pVolumeDetails = NULL;
759 UINT ControlCount = 0, Index;
760 LPMIXERCONTROL Control = NULL;
761
762 /* check if the line has controls */
763 if (Line->cControls == 0)
764 {
765 /* no controls */
766 return TRUE;
767 }
768
769 /* query controls */
770 if (SndMixerQueryControls(Mixer, &ControlCount, Line, &Control) == FALSE)
771 {
772 /* failed to query for controls */
773 return FALSE;
774 }
775
776 pVolumeDetails = HeapAlloc(GetProcessHeap(),
777 0,
778 Line->cChannels * sizeof(MIXERCONTROLDETAILS_UNSIGNED));
779 if (pVolumeDetails == NULL)
780 goto done;
781
782 /* now go through all controls and compare control ids */
783 for (Index = 0; Index < ControlCount; Index++)
784 {
785 if (Control[Index].dwControlID == PtrToUlong(Context))
786 {
787 if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_SWITCH)
788 {
789 MIXERCONTROLDETAILS_BOOLEAN Details;
790
791 /* get volume control details */
792 if (SndMixerGetVolumeControlDetails(Preferences.MixerWindow->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN), (LPVOID)&Details) != -1)
793 {
794 /* update dialog control */
795 UpdateDialogLineSwitchControl(&Preferences, Line, Details.fValue);
796 }
797 }
798 else if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_FADER)
799 {
800 /* get volume control details */
801 if (SndMixerGetVolumeControlDetails(Preferences.MixerWindow->Mixer, Control[Index].dwControlID, Line->cChannels, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)pVolumeDetails) != -1)
802 {
803 /* update dialog control */
804 DWORD volumePosition, volumeStep, maxVolume, i;
805 DWORD balancePosition, balanceStep;
806
807 volumeStep = (Control[Index].Bounds.dwMaximum - Control[Index].Bounds.dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
808
809 maxVolume = 0;
810 for (i = 0; i < Line->cChannels; i++)
811 {
812 if (pVolumeDetails[i].dwValue > maxVolume)
813 maxVolume = pVolumeDetails[i].dwValue;
814 }
815
816 volumePosition = (maxVolume - Control[Index].Bounds.dwMinimum) / volumeStep;
817
818 if (Line->cChannels == 1)
819 {
820 balancePosition = BALANCE_CENTER;
821 }
822 else if (Line->cChannels == 2)
823 {
824 if (pVolumeDetails[0].dwValue == pVolumeDetails[1].dwValue)
825 {
826 balancePosition = BALANCE_CENTER;
827 }
828 else if (pVolumeDetails[0].dwValue == Control[Index].Bounds.dwMinimum)
829 {
830 balancePosition = BALANCE_RIGHT;
831 }
832 else if (pVolumeDetails[1].dwValue == Control[Index].Bounds.dwMinimum)
833 {
834 balancePosition = BALANCE_LEFT;
835 }
836 else
837 {
838 balanceStep = (maxVolume - Control[Index].Bounds.dwMinimum) / (BALANCE_STEPS / 2);
839
840 if (pVolumeDetails[0].dwValue < pVolumeDetails[1].dwValue)
841 {
842 balancePosition = (pVolumeDetails[0].dwValue - Control[Index].Bounds.dwMinimum) / balanceStep;
843 balancePosition = BALANCE_RIGHT - balancePosition;
844 }
845 else if (pVolumeDetails[1].dwValue < pVolumeDetails[0].dwValue)
846 {
847 balancePosition = (pVolumeDetails[1].dwValue - Control[Index].Bounds.dwMinimum) / balanceStep;
848 balancePosition = BALANCE_LEFT + balancePosition;
849 }
850 }
851 }
852
853 /* Update the volume control slider */
854 UpdateDialogLineSliderControl(&Preferences, Line, IDC_LINE_SLIDER_VERT, VOLUME_MAX - volumePosition);
855
856 /* Update the balance control slider */
857 UpdateDialogLineSliderControl(&Preferences, Line, IDC_LINE_SLIDER_HORZ, balancePosition);
858 }
859 }
860 break;
861 }
862 }
863
864 done:
865 /* Free the volume details */
866 if (pVolumeDetails)
867 HeapFree(GetProcessHeap(), 0, pVolumeDetails);
868
869 /* free controls */
870 HeapFree(GetProcessHeap(), 0, Control);
871
872 /* done */
873 return TRUE;
874 }
875
876
877 static VOID
878 ResizeMixerWindow(
879 PMIXER_WINDOW MixerWindow)
880 {
881 RECT statusRect;
882 HWND hDlgCtrl;
883 UINT i;
884 LONG dy;
885
886 if (MixerWindow->Mode != NORMAL_MODE)
887 return;
888
889 if (MixerWindow->bHasExtendedControls == FALSE)
890 return;
891
892 if (MixerWindow->hStatusBar)
893 {
894 GetWindowRect(MixerWindow->hStatusBar, &statusRect);
895 }
896
897 /* Height of the 'Advanced' button in dialog units plus 2 units bottom space */
898 #define BUTTON_HEIGHT 16
899 dy = MulDiv(BUTTON_HEIGHT, MixerWindow->baseUnit.cy, 8);
900
901 if (MixerWindow->bShowExtendedControls)
902 MixerWindow->rect.bottom += dy;
903 else
904 MixerWindow->rect.bottom -= dy;
905
906 SetWindowPos(MixerWindow->hWnd,
907 HWND_TOP,
908 MixerWindow->rect.left,
909 MixerWindow->rect.top,
910 MixerWindow->rect.right - MixerWindow->rect.left,
911 MixerWindow->rect.bottom - MixerWindow->rect.top,
912 SWP_NOMOVE | SWP_NOZORDER);
913
914 if (MixerWindow->hStatusBar)
915 {
916 SetWindowPos(MixerWindow->hStatusBar,
917 HWND_TOP,
918 statusRect.left,
919 MixerWindow->rect.bottom - (statusRect.bottom - statusRect.top),
920 MixerWindow->rect.right - MixerWindow->rect.left,
921 statusRect.bottom - statusRect.top,
922 SWP_NOZORDER);
923 }
924
925 for (i = 0; i < MixerWindow->DialogCount; i++)
926 {
927 hDlgCtrl = GetDlgItem(MixerWindow->hWnd, IDC_LINE_SEP * i);
928 if (hDlgCtrl != NULL)
929 {
930 GetWindowRect(hDlgCtrl, &statusRect);
931 if (MixerWindow->bShowExtendedControls)
932 statusRect.bottom += dy;
933 else
934 statusRect.bottom -= dy;
935
936 SetWindowPos(hDlgCtrl,
937 HWND_TOP,
938 0,
939 0,
940 statusRect.right - statusRect.left,
941 statusRect.bottom - statusRect.top,
942 SWP_NOMOVE | SWP_NOZORDER);
943 }
944 }
945 }
946
947
948 static LRESULT CALLBACK
949 MainWindowProc(HWND hwnd,
950 UINT uMsg,
951 WPARAM wParam,
952 LPARAM lParam)
953 {
954 PMIXER_WINDOW MixerWindow;
955 DWORD CtrlID, LineOffset;
956 LRESULT Result = 0;
957 SET_VOLUME_CONTEXT Context;
958
959 switch (uMsg)
960 {
961 case WM_COMMAND:
962 {
963 MixerWindow = GetWindowData(hwnd,
964 MIXER_WINDOW);
965
966 switch (LOWORD(wParam))
967 {
968 case IDM_PROPERTIES:
969 {
970 PREFERENCES_CONTEXT Pref;
971
972 Pref.MixerWindow = MixerWindow;
973 Pref.Mixer = NULL;
974 Pref.SelectedLine = Preferences.SelectedLine;
975
976 if (DialogBoxParam(hAppInstance,
977 MAKEINTRESOURCE(IDD_PREFERENCES),
978 hwnd,
979 DlgPreferencesProc,
980 (LPARAM)&Pref) == IDOK)
981 {
982 /* update window */
983 TCHAR szProduct[MAXPNAMELEN];
984
985 /* get mixer product name */
986 if (SndMixerGetProductName(Pref.Mixer,
987 szProduct,
988 sizeof(szProduct) / sizeof(szProduct[0])) == -1)
989 {
990 /* failed to get name */
991 szProduct[0] = L'\0';
992 }
993 else
994 {
995 /* copy product */
996 wcscpy(Preferences.DeviceName, szProduct);
997 }
998
999 /* destroy old status bar */
1000 if (MixerWindow->Mode == NORMAL_MODE)
1001 DestroyWindow(MixerWindow->hStatusBar);
1002
1003 /* update details */
1004 Preferences.SelectedLine = Pref.SelectedLine;
1005
1006 /* destroy old mixer */
1007 SndMixerDestroy(Preferences.MixerWindow->Mixer);
1008
1009 /* use new selected mixer */
1010 Preferences.MixerWindow->Mixer = Pref.Mixer;
1011
1012 /* create status window */
1013 if (MixerWindow->Mode == NORMAL_MODE)
1014 {
1015 MixerWindow->hStatusBar = CreateStatusWindow(WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS,
1016 NULL,
1017 hwnd,
1018 0);
1019 if (MixerWindow->hStatusBar)
1020 {
1021 /* Set status bar */
1022 SendMessage(MixerWindow->hStatusBar,
1023 WM_SETTEXT,
1024 0,
1025 (LPARAM)szProduct);
1026 }
1027 }
1028
1029 /* rebuild dialog controls */
1030 RebuildMixerWindowControls(&Preferences);
1031 }
1032 break;
1033 }
1034
1035 case IDM_ADVANCED_CONTROLS:
1036 MixerWindow->bShowExtendedControls = !MixerWindow->bShowExtendedControls;
1037 CheckMenuItem(GetMenu(hwnd),
1038 IDM_ADVANCED_CONTROLS,
1039 MF_BYCOMMAND | (MixerWindow->bShowExtendedControls ? MF_CHECKED : MF_UNCHECKED));
1040 ResizeMixerWindow(MixerWindow);
1041 break;
1042
1043 case IDM_EXIT:
1044 {
1045 PostQuitMessage(0);
1046 break;
1047 }
1048
1049 case IDM_ABOUT:
1050 {
1051 HICON hAppIcon = (HICON)GetClassLongPtrW(hwnd,
1052 GCLP_HICON);
1053 ShellAbout(hwnd,
1054 lpAppTitle,
1055 NULL,
1056 hAppIcon);
1057 break;
1058 }
1059
1060 default:
1061 {
1062 /* get button id */
1063 CtrlID = LOWORD(wParam);
1064
1065 /* check if the message is from the line switch */
1066 if (HIWORD(wParam) == BN_CLICKED && (CtrlID % IDC_LINE_SWITCH == 0))
1067 {
1068 /* compute line offset */
1069 LineOffset = CtrlID / IDC_LINE_SWITCH;
1070
1071 /* compute window id of line name static control */
1072 CtrlID = LineOffset * IDC_LINE_NAME;
1073
1074 /* get line name */
1075 if (GetDlgItemTextW(hwnd, CtrlID, Context.LineName, MIXER_LONG_NAME_CHARS) != 0)
1076 {
1077 /* setup context */
1078 Context.SliderPos = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
1079 Context.bVertical = FALSE;
1080 Context.bSwitch = TRUE;
1081
1082 /* set volume */
1083 SndMixerEnumConnections(Preferences.MixerWindow->Mixer, Preferences.SelectedLine, SetVolumeCallback, (LPVOID)&Context);
1084 }
1085 }
1086 }
1087
1088 }
1089 break;
1090 }
1091
1092 case MM_MIXM_LINE_CHANGE:
1093 {
1094 DPRINT("MM_MIXM_LINE_CHANGE\n");
1095 break;
1096 }
1097
1098 case MM_MIXM_CONTROL_CHANGE:
1099 {
1100 DPRINT("MM_MIXM_CONTROL_CHANGE\n");
1101
1102 /* get mixer window */
1103 MixerWindow = GetWindowData(hwnd,
1104 MIXER_WINDOW);
1105
1106 /* sanity checks */
1107 assert(MixerWindow);
1108 assert(MixerWindow->Mixer->hmx == (HMIXER)wParam);
1109
1110 SndMixerEnumConnections(MixerWindow->Mixer, Preferences.SelectedLine, MixerControlChangeCallback, (PVOID)lParam);
1111 break;
1112 }
1113
1114 case WM_VSCROLL:
1115 switch (LOWORD(wParam))
1116 {
1117 case TB_THUMBTRACK:
1118 /* get dialog item ctrl */
1119 CtrlID = GetDlgCtrlID((HWND)lParam);
1120
1121 /* get line index */
1122 LineOffset = CtrlID / IDC_LINE_SLIDER_VERT;
1123
1124 /* compute window id of line name static control */
1125 CtrlID = LineOffset * IDC_LINE_NAME;
1126
1127 /* get line name */
1128 if (GetDlgItemTextW(hwnd, CtrlID, Context.LineName, MIXER_LONG_NAME_CHARS) != 0)
1129 {
1130 /* setup context */
1131 Context.SliderPos = LineOffset;
1132 Context.bVertical = TRUE;
1133 Context.bSwitch = FALSE;
1134
1135 /* set volume */
1136 SndMixerEnumConnections(Preferences.MixerWindow->Mixer, Preferences.SelectedLine, SetVolumeCallback, (LPVOID)&Context);
1137 }
1138 break;
1139
1140 case TB_ENDTRACK:
1141 MixerWindow = GetWindowData(hwnd,
1142 MIXER_WINDOW);
1143
1144 /* get dialog item ctrl */
1145 CtrlID = GetDlgCtrlID((HWND)lParam);
1146
1147 /* get line index */
1148 LineOffset = CtrlID / IDC_LINE_SLIDER_VERT;
1149
1150 if (LineOffset == 1 && MixerWindow->Mixer->MixerId == 0)
1151 PlaySound((LPCTSTR)SND_ALIAS_SYSTEMDEFAULT, NULL, SND_ASYNC | SND_ALIAS_ID);
1152 break;
1153
1154 default:
1155 break;
1156 }
1157 break;
1158
1159 case WM_HSCROLL:
1160 switch (LOWORD(wParam))
1161 {
1162 case TB_THUMBTRACK:
1163 /* get dialog item ctrl */
1164 CtrlID = GetDlgCtrlID((HWND)lParam);
1165
1166 /* get line index */
1167 LineOffset = CtrlID / IDC_LINE_SLIDER_HORZ;
1168
1169 /* compute window id of line name static control */
1170 CtrlID = LineOffset * IDC_LINE_NAME;
1171
1172 /* get line name */
1173 if (GetDlgItemTextW(hwnd, CtrlID, Context.LineName, MIXER_LONG_NAME_CHARS) != 0)
1174 {
1175 /* setup context */
1176 Context.SliderPos = LineOffset;
1177 Context.bVertical = TRUE;
1178 Context.bSwitch = FALSE;
1179
1180 /* set volume */
1181 SndMixerEnumConnections(Preferences.MixerWindow->Mixer, Preferences.SelectedLine, SetVolumeCallback, (LPVOID)&Context);
1182 }
1183 break;
1184
1185 case TB_ENDTRACK:
1186 MixerWindow = GetWindowData(hwnd,
1187 MIXER_WINDOW);
1188
1189 /* get dialog item ctrl */
1190 CtrlID = GetDlgCtrlID((HWND)lParam);
1191
1192 /* get line index */
1193 LineOffset = CtrlID / IDC_LINE_SLIDER_HORZ;
1194
1195 if (LineOffset == 1 && MixerWindow->Mixer->MixerId == 0)
1196 PlaySound((LPCTSTR)SND_ALIAS_SYSTEMDEFAULT, NULL, SND_ASYNC | SND_ALIAS_ID);
1197 break;
1198
1199 default:
1200 break;
1201 }
1202 break;
1203
1204
1205 case WM_CREATE:
1206 {
1207 MixerWindow = ((LPCREATESTRUCT)lParam)->lpCreateParams;
1208 SetWindowLongPtr(hwnd,
1209 GWL_USERDATA,
1210 (LONG_PTR)MixerWindow);
1211 MixerWindow->hWnd = hwnd;
1212 MixerWindow->Mixer = SndMixerCreate(MixerWindow->hWnd, MixerWindow->MixerId);
1213 if (MixerWindow->Mixer != NULL)
1214 {
1215 TCHAR szProduct[MAXPNAMELEN];
1216
1217 /* get mixer product name */
1218 if (SndMixerGetProductName(MixerWindow->Mixer,
1219 szProduct,
1220 sizeof(szProduct) / sizeof(szProduct[0])) == -1)
1221 {
1222 /* failed to get name */
1223 szProduct[0] = L'\0';
1224 }
1225
1226
1227 /* initialize preferences */
1228 ZeroMemory(&Preferences, sizeof(Preferences));
1229
1230 /* store mixer */
1231 Preferences.Mixer = MixerWindow->Mixer;
1232
1233 /* store mixer window */
1234 Preferences.MixerWindow = MixerWindow;
1235
1236 /* first destination line id */
1237 Preferences.SelectedLine = 0xFFFF0000;
1238
1239 /* copy product */
1240 wcscpy(Preferences.DeviceName, szProduct);
1241
1242 /* Disable the 'Advanced Controls' menu item */
1243 EnableMenuItem(GetMenu(hwnd), IDM_ADVANCED_CONTROLS, MF_BYCOMMAND | MF_GRAYED);
1244
1245 /* create status window */
1246 if (MixerWindow->Mode == NORMAL_MODE)
1247 {
1248 MixerWindow->hStatusBar = CreateStatusWindow(WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS,
1249 NULL,
1250 hwnd,
1251 0);
1252 if (MixerWindow->hStatusBar)
1253 {
1254 SendMessage(MixerWindow->hStatusBar,
1255 WM_SETTEXT,
1256 0,
1257 (LPARAM)szProduct);
1258 }
1259 }
1260
1261 if (!RebuildMixerWindowControls(&Preferences))
1262 {
1263 DPRINT("Rebuilding mixer window controls failed!\n");
1264 SndMixerDestroy(MixerWindow->Mixer);
1265 MixerWindow->Mixer = NULL;
1266 Result = -1;
1267 }
1268 }
1269 break;
1270 }
1271
1272 case WM_DESTROY:
1273 {
1274 MixerWindow = GetWindowData(hwnd,
1275 MIXER_WINDOW);
1276 if (MixerWindow != NULL)
1277 {
1278 if (MixerWindow->Mixer != NULL)
1279 {
1280 SndMixerDestroy(MixerWindow->Mixer);
1281 }
1282 if (MixerWindow->hFont)
1283 DeleteObject(MixerWindow->hFont);
1284 HeapFree(hAppHeap, 0, MixerWindow);
1285 }
1286 break;
1287 }
1288
1289 case WM_CLOSE:
1290 {
1291 PostQuitMessage(0);
1292 break;
1293 }
1294
1295 default:
1296 {
1297 Result = DefWindowProc(hwnd,
1298 uMsg,
1299 wParam,
1300 lParam);
1301 break;
1302 }
1303 }
1304
1305 return Result;
1306 }
1307
1308 static BOOL
1309 RegisterApplicationClasses(VOID)
1310 {
1311 WNDCLASSEX wc;
1312
1313 wc.cbSize = sizeof(WNDCLASSEX);
1314 wc.style = CS_HREDRAW | CS_VREDRAW;
1315 wc.lpfnWndProc = MainWindowProc;
1316 wc.cbClsExtra = 0;
1317 wc.cbWndExtra = sizeof(PMIXER_WINDOW);
1318 wc.hInstance = hAppInstance;
1319 wc.hIcon = LoadIcon(hAppInstance,
1320 MAKEINTRESOURCE(IDI_MAINAPP));
1321 wc.hCursor = LoadCursor(NULL,
1322 IDC_ARROW);
1323 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1324 wc.lpszMenuName = NULL;
1325 wc.lpszClassName = SZ_APP_CLASS;
1326 wc.hIconSm = NULL;
1327 MainWindowClass = RegisterClassEx(&wc);
1328
1329 return MainWindowClass != 0;
1330 }
1331
1332 static VOID
1333 UnregisterApplicationClasses(VOID)
1334 {
1335 UnregisterClass(SZ_APP_CLASS,
1336 hAppInstance);
1337 }
1338
1339 static HWND
1340 CreateApplicationWindow(
1341 WINDOW_MODE WindowMode,
1342 UINT MixerId)
1343 {
1344 HWND hWnd;
1345
1346 PMIXER_WINDOW MixerWindow = HeapAlloc(hAppHeap,
1347 HEAP_ZERO_MEMORY,
1348 sizeof(MIXER_WINDOW));
1349 if (MixerWindow == NULL)
1350 {
1351 return NULL;
1352 }
1353
1354 MixerWindow->Mode = WindowMode;
1355 MixerWindow->MixerId = MixerId;
1356
1357 if (mixerGetNumDevs() > 0)
1358 {
1359 hWnd = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT,
1360 SZ_APP_CLASS,
1361 lpAppTitle,
1362 WS_DLGFRAME | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE,
1363 0, 0, 300, 315,
1364 NULL,
1365 LoadMenu(hAppInstance,
1366 MAKEINTRESOURCE(IDM_MAINMENU)),
1367 hAppInstance,
1368 MixerWindow);
1369 }
1370 else
1371 {
1372 LPTSTR lpErrMessage;
1373
1374 /*
1375 * no mixer devices are available!
1376 */
1377
1378 hWnd = NULL;
1379 if (AllocAndLoadString(&lpErrMessage,
1380 hAppInstance,
1381 IDS_NOMIXERDEVICES))
1382 {
1383 MessageBox(NULL,
1384 lpErrMessage,
1385 lpAppTitle,
1386 MB_ICONINFORMATION);
1387 LocalFree(lpErrMessage);
1388 }
1389 }
1390
1391 if (hWnd == NULL)
1392 {
1393 HeapFree(hAppHeap,
1394 0,
1395 MixerWindow);
1396 }
1397
1398 return hWnd;
1399 }
1400
1401 static
1402 BOOL
1403 HandleCommandLine(LPTSTR cmdline,
1404 DWORD dwStyle,
1405 PWINDOW_MODE pMode,
1406 PUINT pMixerId)
1407 {
1408 TCHAR option;
1409
1410 *pMixerId = PLAY_MIXER;
1411 *pMode = (dwStyle & 0x20) ? SMALL_MODE : NORMAL_MODE;
1412
1413 while (*cmdline == _T(' ') || *cmdline == _T('-') || *cmdline == _T('/'))
1414 {
1415 if (*cmdline++ == _T(' '))
1416 continue;
1417
1418 option = *cmdline;
1419 if (option)
1420 cmdline++;
1421 while (*cmdline == _T(' '))
1422 cmdline++;
1423
1424 switch (option)
1425 {
1426 case 'd': /* Device */
1427 case 'D':
1428 break;
1429
1430 case 'n': /* Small size */
1431 case 'N':
1432 *pMode = NORMAL_MODE;
1433 break;
1434
1435 case 's': /* Small size */
1436 case 'S':
1437 *pMode = SMALL_MODE;
1438 break;
1439
1440 case 't': /* Tray size */
1441 case 'T':
1442 *pMode = TRAY_MODE;
1443 break;
1444
1445 case 'p': /* Play mode */
1446 case 'P':
1447 *pMixerId = PLAY_MIXER;
1448 break;
1449
1450 case 'r': /* Record mode */
1451 case 'R':
1452 *pMixerId = RECORD_MIXER;
1453 break;
1454
1455 default:
1456 return FALSE;
1457 }
1458 }
1459
1460 return TRUE;
1461 }
1462
1463 int WINAPI
1464 _tWinMain(HINSTANCE hInstance,
1465 HINSTANCE hPrevInstance,
1466 LPTSTR lpszCmdLine,
1467 int nCmdShow)
1468 {
1469 MSG Msg;
1470 int Ret = 1;
1471 INITCOMMONCONTROLSEX Controls;
1472 WINDOW_MODE WindowMode = SMALL_MODE;
1473 UINT MixerId = 0;
1474 DWORD dwStyle;
1475
1476 UNREFERENCED_PARAMETER(hPrevInstance);
1477 UNREFERENCED_PARAMETER(nCmdShow);
1478
1479 hAppInstance = hInstance;
1480 hAppHeap = GetProcessHeap();
1481
1482 if (InitAppConfig())
1483 {
1484 dwStyle = GetStyleValue();
1485 HandleCommandLine(lpszCmdLine, dwStyle, &WindowMode, &MixerId);
1486
1487 /* load the application title */
1488 if (!AllocAndLoadString(&lpAppTitle,
1489 hAppInstance,
1490 IDS_SNDVOL32))
1491 {
1492 lpAppTitle = NULL;
1493 }
1494
1495 Controls.dwSize = sizeof(INITCOMMONCONTROLSEX);
1496 Controls.dwICC = ICC_BAR_CLASSES | ICC_STANDARD_CLASSES;
1497
1498 InitCommonControlsEx(&Controls);
1499
1500 if (WindowMode == TRAY_MODE)
1501 {
1502 DialogBoxParam(hAppInstance,
1503 MAKEINTRESOURCE(IDD_TRAY_MASTER),
1504 NULL,
1505 TrayDlgProc,
1506 0);
1507 }
1508 else
1509 {
1510 if (RegisterApplicationClasses())
1511 {
1512 hMainWnd = CreateApplicationWindow(WindowMode, MixerId);
1513 if (hMainWnd != NULL)
1514 {
1515 BOOL bRet;
1516 while ((bRet =GetMessage(&Msg,
1517 NULL,
1518 0,
1519 0)) != 0)
1520 {
1521 if (bRet != -1)
1522 {
1523 TranslateMessage(&Msg);
1524 DispatchMessage(&Msg);
1525 }
1526 }
1527
1528 DestroyWindow(hMainWnd);
1529 Ret = 0;
1530 }
1531 else
1532 {
1533 DPRINT("Failed to create application window (LastError: %d)!\n", GetLastError());
1534 }
1535
1536 UnregisterApplicationClasses();
1537 }
1538 else
1539 {
1540 DPRINT("Failed to register application classes (LastError: %d)!\n", GetLastError());
1541 }
1542 }
1543
1544 if (lpAppTitle != NULL)
1545 {
1546 LocalFree(lpAppTitle);
1547 }
1548
1549 CloseAppConfig();
1550 }
1551 else
1552 {
1553 DPRINT("Unable to open the Volume Control registry key!\n");
1554 }
1555
1556 return Ret;
1557 }