2 * ReactOS Sound Volume Control
3 * Copyright (C) 2004-2005 Thomas Weidenmueller
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.
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.
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
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>
30 HINSTANCE hAppInstance
;
35 PREFERENCES_CONTEXT Preferences
;
37 #define GetDialogData(hwndDlg, type) \
38 ( P##type )GetWindowLongPtr((hwndDlg), DWLP_USER)
39 #define GetWindowData(hwnd, type) \
40 ( P##type )GetWindowLongPtr((hwnd), GWL_USERDATA)
42 /******************************************************************************/
46 typedef struct _PREFERENCES_FILL_DEVICES
48 PPREFERENCES_CONTEXT PrefContext
;
51 } PREFERENCES_FILL_DEVICES
, *PPREFERENCES_FILL_DEVICES
;
54 FillDeviceComboBox(PSND_MIXER Mixer
,
60 PPREFERENCES_FILL_DEVICES FillContext
= (PPREFERENCES_FILL_DEVICES
)Context
;
62 UNREFERENCED_PARAMETER(Mixer
);
64 lres
= SendMessage(FillContext
->hComboBox
,
70 /* save the index so we don't screw stuff when the combobox is sorted... */
71 SendMessage(FillContext
->hComboBox
,
76 if (Id
== FillContext
->Selected
)
78 SendMessage(FillContext
->hComboBox
,
89 PrefDlgAddLine(PSND_MIXER Mixer
,
94 PPREFERENCES_CONTEXT PrefContext
= (PPREFERENCES_CONTEXT
)Context
;
96 UNREFERENCED_PARAMETER(Mixer
);
97 UNREFERENCED_PARAMETER(DisplayControls
);
99 switch (Line
->dwComponentType
)
101 case MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
:
102 if (PrefContext
->PlaybackID
== (DWORD
)-1)
104 PrefContext
->PlaybackID
= Line
->dwLineID
;
106 if (PrefContext
->SelectedLine
== (DWORD
)-1)
108 PrefContext
->SelectedLine
= Line
->dwLineID
;
112 goto AddToOthersLines
;
116 case MIXERLINE_COMPONENTTYPE_DST_WAVEIN
:
117 if (PrefContext
->RecordingID
== (DWORD
)-1)
119 PrefContext
->RecordingID
= Line
->dwLineID
;
121 if (PrefContext
->SelectedLine
== (DWORD
)-1)
123 PrefContext
->SelectedLine
= Line
->dwLineID
;
127 goto AddToOthersLines
;
136 if (PrefContext
->SelectedLine
== (DWORD
)-1)
138 PrefContext
->SelectedLine
= Line
->dwLineID
;
142 hwndCbOthers
= GetDlgItem(PrefContext
->hwndDlg
,
145 lres
= SendMessage(hwndCbOthers
,
148 (LPARAM
)Line
->szName
);
151 SendMessage(hwndCbOthers
,
156 PrefContext
->OtherLines
++;
166 PrefDlgAddConnection(PSND_MIXER Mixer
,
171 PPREFERENCES_CONTEXT PrefContext
= (PPREFERENCES_CONTEXT
)Context
;
176 UNREFERENCED_PARAMETER(Mixer
);
177 UNREFERENCED_PARAMETER(LineID
);
179 if (Line
->cControls
!= 0)
181 hwndControls
= GetDlgItem(PrefContext
->hwndDlg
,
184 lvi
.mask
= LVIF_TEXT
| LVIF_PARAM
;
185 lvi
.iItem
= PrefContext
->tmp
++;
187 lvi
.pszText
= Line
->szName
;
188 lvi
.lParam
= (LPARAM
)Line
->dwSource
;
190 i
= SendMessage(hwndControls
,
196 TCHAR LineName
[MIXER_LONG_NAME_CHARS
];
198 BOOL SelLine
= FALSE
;
200 if (SndMixerGetLineName(PrefContext
->Mixer
,
201 PrefContext
->SelectedLine
,
203 MIXER_LONG_NAME_CHARS
,
206 LineName
[0] = TEXT('\0');
209 if (ReadLineConfig(PrefContext
->DeviceName
,
220 ListView_SetCheckState(hwndControls
,
230 UpdatePrefDlgControls(PPREFERENCES_CONTEXT Context
,
233 INT OldID
, MixerID
= 0;
236 /* select the mixer */
237 DeviceCbIndex
= SendDlgItemMessage(Context
->hwndDlg
,
242 if (DeviceCbIndex
!= CB_ERR
)
244 MixerID
= SendDlgItemMessage(Context
->hwndDlg
,
249 if (MixerID
== CB_ERR
)
255 OldID
= Context
->Selected
;
256 if (MixerID
!= OldID
&&
257 SndMixerSelect(Context
->Mixer
,
260 Context
->Selected
= SndMixerGetSelection(Context
->Mixer
);
262 /* update the controls */
263 Context
->PlaybackID
= (DWORD
)-1;
264 Context
->RecordingID
= (DWORD
)-1;
265 Context
->OtherLines
= 0;
266 Context
->SelectedLine
= (DWORD
)-1;
268 SndMixerGetProductName(Context
->Mixer
,
270 sizeof(Context
->DeviceName
) / sizeof(Context
->DeviceName
[0]));
272 if (SndMixerEnumLines(Context
->Mixer
,
278 /* enable/disable controls and make default selection */
279 EnableWindow(GetDlgItem(Context
->hwndDlg
,
281 Context
->PlaybackID
!= (DWORD
)-1);
282 CheckDlgButton(Context
->hwndDlg
,
284 (Context
->PlaybackID
!= (DWORD
)-1 && SelBox
++ == 0) ?
285 BST_CHECKED
: BST_UNCHECKED
);
287 EnableWindow(GetDlgItem(Context
->hwndDlg
,
289 Context
->RecordingID
!= (DWORD
)-1);
290 CheckDlgButton(Context
->hwndDlg
,
292 (Context
->RecordingID
!= (DWORD
)-1 && SelBox
++ == 0) ?
293 BST_CHECKED
: BST_UNCHECKED
);
295 if (Context
->OtherLines
!= 0)
297 /* select the first item in the other lines combo box by default */
298 SendDlgItemMessage(Context
->hwndDlg
,
304 EnableWindow(GetDlgItem(Context
->hwndDlg
,
307 EnableWindow(GetDlgItem(Context
->hwndDlg
,
309 Context
->OtherLines
!= 0);
310 CheckDlgButton(Context
->hwndDlg
,
312 (Context
->OtherLines
!= 0 && SelBox
++ == 0) ?
313 BST_CHECKED
: BST_UNCHECKED
);
315 /* disable the OK button if the device doesn't have any lines */
316 EnableWindow(GetDlgItem(Context
->hwndDlg
,
318 Context
->PlaybackID
!= (DWORD
)-1 ||
319 Context
->RecordingID
!= (DWORD
)-1 ||
320 Context
->OtherLines
!= 0);
322 LineID
= Context
->SelectedLine
;
326 /* update the line sources list */
327 if ((MixerID
!= OldID
&& Context
->SelectedLine
!= (DWORD
)-1) ||
328 (Context
->SelectedLine
!= LineID
&& LineID
!= (DWORD
)-1))
330 Context
->SelectedLine
= LineID
;
332 (void)ListView_DeleteAllItems(GetDlgItem(Context
->hwndDlg
,
336 SndMixerEnumConnections(Context
->Mixer
,
338 PrefDlgAddConnection
,
345 WriteLineSettings(PPREFERENCES_CONTEXT Context
, HWND hwndDlg
)
349 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
350 WCHAR DestinationName
[MIXER_LONG_NAME_CHARS
];
352 PSNDVOL_REG_LINESTATE LineStates
;
355 hwndControls
= GetDlgItem(hwndDlg
, IDC_CONTROLS
);
357 /* get list item count */
358 Count
= ListView_GetItemCount(hwndControls
);
363 if (SndMixerGetLineName(Context
->Mixer
, Context
->SelectedLine
, DestinationName
, MIXER_LONG_NAME_CHARS
, TRUE
) == -1)
365 /* failed to get destination line name */
369 /* allocate line states array */
370 LineStates
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SNDVOL_REG_LINESTATE
) * Count
);
371 if (LineStates
== NULL
)
373 /* failed to allocate line states array */
378 for(Index
= 0; Index
< Count
; Index
++)
384 ListView_GetItemText(hwndControls
, Index
, 0, LineName
, MIXER_LONG_NAME_CHARS
);
386 /* make sure it is null terminated */
387 LineName
[MIXER_LONG_NAME_CHARS
-1] = L
'\0';
389 /* get check state */
390 Flags
= (ListView_GetCheckState(hwndControls
, Index
) == 0 ? 0x4 : 0);
393 wcscpy(LineStates
[Index
].LineName
, LineName
);
396 LineStates
[Index
].Flags
= Flags
;
399 /* now write the line config */
400 WriteLineConfig(Context
->DeviceName
, DestinationName
, LineStates
, sizeof(SNDVOL_REG_LINESTATE
) * Count
);
402 /* free line states */
403 HeapFree(GetProcessHeap(), 0, LineStates
);
406 static INT_PTR CALLBACK
407 DlgPreferencesProc(HWND hwndDlg
,
412 PPREFERENCES_CONTEXT Context
;
418 Context
= GetDialogData(hwndDlg
,
419 PREFERENCES_CONTEXT
);
420 switch (LOWORD(wParam
))
422 case IDC_MIXERDEVICE
:
424 if (HIWORD(wParam
) == CBN_SELCHANGE
)
426 UpdatePrefDlgControls(Context
,
434 if (HIWORD(wParam
) == CBN_SELCHANGE
)
439 Index
= SendDlgItemMessage(hwndDlg
,
446 LineID
= SendDlgItemMessage(hwndDlg
,
451 if (LineID
!= CB_ERR
)
453 UpdatePrefDlgControls(Context
,
463 UpdatePrefDlgControls(Context
,
464 Context
->PlaybackID
);
465 EnableWindow(GetDlgItem(hwndDlg
,
473 UpdatePrefDlgControls(Context
,
474 Context
->RecordingID
);
475 EnableWindow(GetDlgItem(hwndDlg
,
486 EnableWindow(GetDlgItem(hwndDlg
,
490 LineCbIndex
= SendDlgItemMessage(hwndDlg
,
495 if (LineCbIndex
!= CB_ERR
)
497 LineID
= SendDlgItemMessage(hwndDlg
,
502 if (LineID
!= CB_ERR
)
504 UpdatePrefDlgControls(Context
,
513 /* write line settings */
514 WriteLineSettings(Context
, hwndDlg
);
530 PREFERENCES_FILL_DEVICES FillDevContext
;
535 SetWindowLongPtr(hwndDlg
,
538 Context
= (PPREFERENCES_CONTEXT
)((LONG_PTR
)lParam
);
539 Context
->hwndDlg
= hwndDlg
;
540 Context
->Mixer
= SndMixerCreate(hwndDlg
, Context
->MixerWindow
->MixerId
);
541 Context
->Selected
= (UINT
)-1;
543 FillDevContext
.PrefContext
= Context
;
544 FillDevContext
.hComboBox
= GetDlgItem(hwndDlg
,
546 FillDevContext
.Selected
= SndMixerGetSelection(Context
->Mixer
);
547 SndMixerEnumProducts(Context
->Mixer
,
551 /* initialize the list view control */
552 hwndControls
= GetDlgItem(hwndDlg
,
554 (void)ListView_SetExtendedListViewStyle(hwndControls
,
557 GetClientRect(hwndControls
,
559 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
;
560 lvc
.pszText
= TEXT("");
561 lvc
.cx
= rcClient
.right
;
562 SendMessage(hwndControls
,
567 /* update all controls */
568 UpdatePrefDlgControls(Context
,
569 (DWORD
)Context
->SelectedLine
);
580 case WM_SYSCOLORCHANGE
:
584 /* Forward WM_SYSCOLORCHANGE */
585 hwndControls
= GetDlgItem(hwndDlg
, IDC_CONTROLS
);
586 SendMessage(hwndControls
, WM_SYSCOLORCHANGE
, 0, 0);
594 /******************************************************************************/
597 DeleteMixerWindowControls(PMIXER_WINDOW MixerWindow
)
601 for(Index
= 0; Index
< MixerWindow
->WindowCount
; Index
++)
603 /* destroys the window */
604 DestroyWindow(MixerWindow
->Window
[Index
]);
608 HeapFree(GetProcessHeap(), 0, MixerWindow
->Window
);
611 MixerWindow
->Window
= NULL
;
612 MixerWindow
->WindowCount
= 0;
616 RebuildMixerWindowControls(PPREFERENCES_CONTEXT PrefContext
)
618 /* delete existing mixer controls */
619 DeleteMixerWindowControls(PrefContext
->MixerWindow
);
621 /* load new mixer controls */
622 LoadDialogCtrls(PrefContext
);
630 SetVolumeCallback(PSND_MIXER Mixer
, DWORD LineID
, LPMIXERLINE Line
, PVOID Ctx
)
632 UINT ControlCount
= 0, Index
;
633 LPMIXERCONTROL Control
= NULL
;
634 PMIXERCONTROLDETAILS_UNSIGNED puDetails
= NULL
;
635 MIXERCONTROLDETAILS_BOOLEAN bDetails
;
636 PSET_VOLUME_CONTEXT Context
= (PSET_VOLUME_CONTEXT
)Ctx
;
638 /* check if the line name is equal */
639 if (wcsicmp(Line
->szName
, Context
->LineName
))
646 if (SndMixerQueryControls(Mixer
, &ControlCount
, Line
, &Control
) == FALSE
)
648 /* failed to query for controls */
652 puDetails
= HeapAlloc(GetProcessHeap(), 0, Line
->cChannels
* sizeof(MIXERCONTROLDETAILS_UNSIGNED
));
653 if (puDetails
== NULL
)
656 /* now go through all controls and compare control ids */
657 for (Index
= 0; Index
< ControlCount
; Index
++)
659 if (Context
->bVertical
)
661 if (Control
[Index
].dwControlType
== MIXERCONTROL_CONTROLTYPE_VOLUME
)
663 DWORD LineOffset
, volumePosition
, balancePosition
;
664 DWORD volumeStep
, balanceStep
;
666 LineOffset
= Context
->SliderPos
;
668 volumePosition
= (DWORD
)SendDlgItemMessage(Preferences
.MixerWindow
->hWnd
, LineOffset
* IDC_LINE_SLIDER_VERT
, TBM_GETPOS
, 0, 0);
669 volumeStep
= (Control
[Index
].Bounds
.dwMaximum
- Control
[Index
].Bounds
.dwMinimum
) / (VOLUME_MAX
- VOLUME_MIN
);
671 if (Line
->cChannels
== 1)
674 puDetails
[0].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
676 else if (Line
->cChannels
== 2)
678 balancePosition
= (DWORD
)SendDlgItemMessage(Preferences
.MixerWindow
->hWnd
, LineOffset
* IDC_LINE_SLIDER_HORZ
, TBM_GETPOS
, 0, 0);
679 if (balancePosition
== BALANCE_CENTER
)
681 puDetails
[0].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
682 puDetails
[1].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
684 else if (balancePosition
== BALANCE_LEFT
)
686 puDetails
[0].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
687 puDetails
[1].dwValue
= Control
[Index
].Bounds
.dwMinimum
;
689 else if (balancePosition
== BALANCE_RIGHT
)
691 puDetails
[0].dwValue
= Control
[Index
].Bounds
.dwMinimum
;
692 puDetails
[1].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
694 else if (balancePosition
< BALANCE_CENTER
) // Left
696 puDetails
[0].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
698 balanceStep
= (puDetails
[0].dwValue
- Control
[Index
].Bounds
.dwMinimum
) / (BALANCE_STEPS
/ 2);
700 puDetails
[1].dwValue
= (balancePosition
* balanceStep
) + Control
[Index
].Bounds
.dwMinimum
;
702 else if (balancePosition
> BALANCE_CENTER
) // Right
704 puDetails
[1].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
706 balanceStep
= (puDetails
[1].dwValue
- Control
[Index
].Bounds
.dwMinimum
) / (BALANCE_STEPS
/ 2);
708 puDetails
[0].dwValue
= ((BALANCE_RIGHT
- balancePosition
) * balanceStep
) + Control
[Index
].Bounds
.dwMinimum
;
713 SndMixerGetVolumeControlDetails(Preferences
.MixerWindow
->Mixer
, Control
[Index
].dwControlID
, Line
->cChannels
, sizeof(MIXERCONTROLDETAILS_UNSIGNED
), (LPVOID
)puDetails
);
719 SndMixerSetVolumeControlDetails(Preferences
.MixerWindow
->Mixer
, Control
[Index
].dwControlID
, Line
->cChannels
, sizeof(MIXERCONTROLDETAILS_UNSIGNED
), (LPVOID
)puDetails
);
725 else if (Context
->bSwitch
)
727 if (Control
[Index
].dwControlType
== MIXERCONTROL_CONTROLTYPE_MUTE
)
730 bDetails
.fValue
= Context
->SliderPos
;
733 SndMixerSetVolumeControlDetails(Preferences
.MixerWindow
->Mixer
, Control
[Index
].dwControlID
, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN
), (LPVOID
)&bDetails
);
741 if (puDetails
!= NULL
)
742 HeapFree(GetProcessHeap(), 0, puDetails
);
745 HeapFree(GetProcessHeap(), 0, Control
);
755 MixerControlChangeCallback(PSND_MIXER Mixer
, DWORD LineID
, LPMIXERLINE Line
, PVOID Context
)
757 PMIXERCONTROLDETAILS_UNSIGNED pVolumeDetails
= NULL
;
758 UINT ControlCount
= 0, Index
;
759 LPMIXERCONTROL Control
= NULL
;
761 /* check if the line has controls */
762 if (Line
->cControls
== 0)
769 if (SndMixerQueryControls(Mixer
, &ControlCount
, Line
, &Control
) == FALSE
)
771 /* failed to query for controls */
775 pVolumeDetails
= HeapAlloc(GetProcessHeap(),
777 Line
->cChannels
* sizeof(MIXERCONTROLDETAILS_UNSIGNED
));
778 if (pVolumeDetails
== NULL
)
781 /* now go through all controls and compare control ids */
782 for (Index
= 0; Index
< ControlCount
; Index
++)
784 if (Control
[Index
].dwControlID
== PtrToUlong(Context
))
786 if (Control
[Index
].dwControlType
== MIXERCONTROL_CONTROLTYPE_MUTE
)
788 MIXERCONTROLDETAILS_BOOLEAN Details
;
790 /* get volume control details */
791 if (SndMixerGetVolumeControlDetails(Preferences
.MixerWindow
->Mixer
, Control
[Index
].dwControlID
, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN
), (LPVOID
)&Details
) != -1)
793 /* update dialog control */
794 UpdateDialogLineSwitchControl(&Preferences
, Line
, Details
.fValue
);
797 else if (Control
[Index
].dwControlType
== MIXERCONTROL_CONTROLTYPE_VOLUME
)
799 /* get volume control details */
800 if (SndMixerGetVolumeControlDetails(Preferences
.MixerWindow
->Mixer
, Control
[Index
].dwControlID
, Line
->cChannels
, sizeof(MIXERCONTROLDETAILS_UNSIGNED
), (LPVOID
)pVolumeDetails
) != -1)
802 /* update dialog control */
803 DWORD volumePosition
, volumeStep
, maxVolume
, i
;
804 DWORD balancePosition
, balanceStep
;
806 volumeStep
= (Control
[Index
].Bounds
.dwMaximum
- Control
[Index
].Bounds
.dwMinimum
) / (VOLUME_MAX
- VOLUME_MIN
);
809 for (i
= 0; i
< Line
->cChannels
; i
++)
811 if (pVolumeDetails
[i
].dwValue
> maxVolume
)
812 maxVolume
= pVolumeDetails
[i
].dwValue
;
815 volumePosition
= (maxVolume
- Control
[Index
].Bounds
.dwMinimum
) / volumeStep
;
817 if (Line
->cChannels
== 1)
819 balancePosition
= BALANCE_CENTER
;
821 else if (Line
->cChannels
== 2)
823 if (pVolumeDetails
[0].dwValue
== pVolumeDetails
[1].dwValue
)
825 balancePosition
= BALANCE_CENTER
;
827 else if (pVolumeDetails
[0].dwValue
== Control
[Index
].Bounds
.dwMinimum
)
829 balancePosition
= BALANCE_RIGHT
;
831 else if (pVolumeDetails
[1].dwValue
== Control
[Index
].Bounds
.dwMinimum
)
833 balancePosition
= BALANCE_LEFT
;
837 balanceStep
= (maxVolume
- Control
[Index
].Bounds
.dwMinimum
) / (BALANCE_STEPS
/ 2);
839 if (pVolumeDetails
[0].dwValue
< pVolumeDetails
[1].dwValue
)
841 balancePosition
= (pVolumeDetails
[0].dwValue
- Control
[Index
].Bounds
.dwMinimum
) / balanceStep
;
842 balancePosition
= BALANCE_RIGHT
- balancePosition
;
844 else if (pVolumeDetails
[1].dwValue
< pVolumeDetails
[0].dwValue
)
846 balancePosition
= (pVolumeDetails
[1].dwValue
- Control
[Index
].Bounds
.dwMinimum
) / balanceStep
;
847 balancePosition
= BALANCE_LEFT
+ balancePosition
;
852 /* Update the volume control slider */
853 UpdateDialogLineSliderControl(&Preferences
, Line
, IDC_LINE_SLIDER_VERT
, VOLUME_MAX
- volumePosition
);
855 /* Update the balance control slider */
856 UpdateDialogLineSliderControl(&Preferences
, Line
, IDC_LINE_SLIDER_HORZ
, balancePosition
);
864 /* Free the volume details */
866 HeapFree(GetProcessHeap(), 0, pVolumeDetails
);
869 HeapFree(GetProcessHeap(), 0, Control
);
875 static LRESULT CALLBACK
876 MainWindowProc(HWND hwnd
,
881 PMIXER_WINDOW MixerWindow
;
882 DWORD CtrlID
, LineOffset
;
884 SET_VOLUME_CONTEXT Context
;
890 MixerWindow
= GetWindowData(hwnd
,
893 switch (LOWORD(wParam
))
897 PREFERENCES_CONTEXT Pref
;
899 Pref
.MixerWindow
= MixerWindow
;
901 Pref
.SelectedLine
= Preferences
.SelectedLine
;
903 if (DialogBoxParam(hAppInstance
,
904 MAKEINTRESOURCE(IDD_PREFERENCES
),
907 (LPARAM
)&Pref
) == IDOK
)
910 TCHAR szProduct
[MAXPNAMELEN
];
912 /* get mixer product name */
913 if (SndMixerGetProductName(Pref
.Mixer
,
915 sizeof(szProduct
) / sizeof(szProduct
[0])) == -1)
917 /* failed to get name */
918 szProduct
[0] = L
'\0';
923 wcscpy(Preferences
.DeviceName
, szProduct
);
926 /* destroy old status bar */
927 if (MixerWindow
->Mode
== NORMAL_MODE
)
928 DestroyWindow(MixerWindow
->hStatusBar
);
931 Preferences
.SelectedLine
= Pref
.SelectedLine
;
933 /* destroy old mixer */
934 SndMixerDestroy(Preferences
.MixerWindow
->Mixer
);
936 /* use new selected mixer */
937 Preferences
.MixerWindow
->Mixer
= Pref
.Mixer
;
939 /* create status window */
940 if (MixerWindow
->Mode
== NORMAL_MODE
)
942 MixerWindow
->hStatusBar
= CreateStatusWindow(WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
,
946 if (MixerWindow
->hStatusBar
)
949 SendMessage(MixerWindow
->hStatusBar
,
956 /* rebuild dialog controls */
957 RebuildMixerWindowControls(&Preferences
);
962 case IDM_ADVANCED_CONTROLS
:
963 MixerWindow
->bShowExtendedControls
= !MixerWindow
->bShowExtendedControls
;
964 CheckMenuItem(GetMenu(hwnd
),
965 IDM_ADVANCED_CONTROLS
,
966 MF_BYCOMMAND
| (MixerWindow
->bShowExtendedControls
? MF_CHECKED
: MF_UNCHECKED
));
967 RebuildMixerWindowControls(&Preferences
);
978 HICON hAppIcon
= (HICON
)GetClassLongPtrW(hwnd
,
990 CtrlID
= LOWORD(wParam
);
992 /* check if the message is from the line switch */
993 if (HIWORD(wParam
) == BN_CLICKED
)
995 if (CtrlID
% IDC_LINE_SWITCH
== 0)
997 /* compute line offset */
998 LineOffset
= CtrlID
/ IDC_LINE_SWITCH
;
1000 /* compute window id of line name static control */
1001 CtrlID
= LineOffset
* IDC_LINE_NAME
;
1003 if (Preferences
.MixerWindow
->Mixer
->MixerId
== PLAY_MIXER
)
1006 if (GetDlgItemTextW(hwnd
, CtrlID
, Context
.LineName
, MIXER_LONG_NAME_CHARS
) != 0)
1009 Context
.SliderPos
= SendMessage((HWND
)lParam
, BM_GETCHECK
, 0, 0);
1010 Context
.bVertical
= FALSE
;
1011 Context
.bSwitch
= TRUE
;
1014 SndMixerEnumConnections(Preferences
.MixerWindow
->Mixer
, Preferences
.SelectedLine
, SetVolumeCallback
, (LPVOID
)&Context
);
1017 else if (Preferences
.MixerWindow
->Mixer
->MixerId
== RECORD_MIXER
)
1021 for (i
= 0; i
< Preferences
.MixerWindow
->DialogCount
; i
++)
1023 SendDlgItemMessageW(hwnd
, (i
+ 1) * IDC_LINE_SWITCH
, BM_SETCHECK
, (WPARAM
)((i
+ 1) == LineOffset
), 0);
1027 else if (CtrlID
% IDC_LINE_ADVANCED
== 0)
1029 ADVANCED_CONTEXT AdvancedContext
;
1031 /* compute line offset */
1032 LineOffset
= CtrlID
/ IDC_LINE_ADVANCED
;
1034 /* compute window id of line name static control */
1035 CtrlID
= LineOffset
* IDC_LINE_NAME
;
1038 if (GetDlgItemTextW(hwnd
, CtrlID
, AdvancedContext
.LineName
, MIXER_LONG_NAME_CHARS
) != 0)
1040 AdvancedContext
.MixerWindow
= Preferences
.MixerWindow
;
1041 AdvancedContext
.Mixer
= Preferences
.MixerWindow
->Mixer
;
1042 AdvancedContext
.Line
= SndMixerGetLineByName(Preferences
.MixerWindow
->Mixer
,
1043 Preferences
.SelectedLine
,
1044 AdvancedContext
.LineName
);
1045 if (AdvancedContext
.Line
)
1047 DialogBoxParam(hAppInstance
,
1048 MAKEINTRESOURCE(IDD_ADVANCED
),
1051 (LPARAM
)&AdvancedContext
);
1061 case MM_MIXM_LINE_CHANGE
:
1063 DPRINT("MM_MIXM_LINE_CHANGE\n");
1067 case MM_MIXM_CONTROL_CHANGE
:
1069 DPRINT("MM_MIXM_CONTROL_CHANGE\n");
1071 /* get mixer window */
1072 MixerWindow
= GetWindowData(hwnd
,
1076 assert(MixerWindow
);
1077 assert(MixerWindow
->Mixer
->hmx
== (HMIXER
)wParam
);
1079 SndMixerEnumConnections(MixerWindow
->Mixer
, Preferences
.SelectedLine
, MixerControlChangeCallback
, (PVOID
)lParam
);
1084 switch (LOWORD(wParam
))
1087 /* get dialog item ctrl */
1088 CtrlID
= GetDlgCtrlID((HWND
)lParam
);
1090 /* get line index */
1091 LineOffset
= CtrlID
/ IDC_LINE_SLIDER_VERT
;
1093 /* compute window id of line name static control */
1094 CtrlID
= LineOffset
* IDC_LINE_NAME
;
1097 if (GetDlgItemTextW(hwnd
, CtrlID
, Context
.LineName
, MIXER_LONG_NAME_CHARS
) != 0)
1100 Context
.SliderPos
= LineOffset
;
1101 Context
.bVertical
= TRUE
;
1102 Context
.bSwitch
= FALSE
;
1105 SndMixerEnumConnections(Preferences
.MixerWindow
->Mixer
, Preferences
.SelectedLine
, SetVolumeCallback
, (LPVOID
)&Context
);
1110 MixerWindow
= GetWindowData(hwnd
,
1113 /* get dialog item ctrl */
1114 CtrlID
= GetDlgCtrlID((HWND
)lParam
);
1116 /* get line index */
1117 LineOffset
= CtrlID
/ IDC_LINE_SLIDER_VERT
;
1119 if (LineOffset
== 1 && MixerWindow
->Mixer
->MixerId
== 0)
1120 PlaySound((LPCTSTR
)SND_ALIAS_SYSTEMDEFAULT
, NULL
, SND_ASYNC
| SND_ALIAS_ID
);
1129 switch (LOWORD(wParam
))
1132 /* get dialog item ctrl */
1133 CtrlID
= GetDlgCtrlID((HWND
)lParam
);
1135 /* get line index */
1136 LineOffset
= CtrlID
/ IDC_LINE_SLIDER_HORZ
;
1138 /* compute window id of line name static control */
1139 CtrlID
= LineOffset
* IDC_LINE_NAME
;
1142 if (GetDlgItemTextW(hwnd
, CtrlID
, Context
.LineName
, MIXER_LONG_NAME_CHARS
) != 0)
1145 Context
.SliderPos
= LineOffset
;
1146 Context
.bVertical
= TRUE
;
1147 Context
.bSwitch
= FALSE
;
1150 SndMixerEnumConnections(Preferences
.MixerWindow
->Mixer
, Preferences
.SelectedLine
, SetVolumeCallback
, (LPVOID
)&Context
);
1155 MixerWindow
= GetWindowData(hwnd
,
1158 /* get dialog item ctrl */
1159 CtrlID
= GetDlgCtrlID((HWND
)lParam
);
1161 /* get line index */
1162 LineOffset
= CtrlID
/ IDC_LINE_SLIDER_HORZ
;
1164 if (LineOffset
== 1 && MixerWindow
->Mixer
->MixerId
== 0)
1165 PlaySound((LPCTSTR
)SND_ALIAS_SYSTEMDEFAULT
, NULL
, SND_ASYNC
| SND_ALIAS_ID
);
1176 MixerWindow
= ((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
1177 SetWindowLongPtr(hwnd
,
1179 (LONG_PTR
)MixerWindow
);
1180 MixerWindow
->hWnd
= hwnd
;
1181 MixerWindow
->Mixer
= SndMixerCreate(MixerWindow
->hWnd
, MixerWindow
->MixerId
);
1182 if (MixerWindow
->Mixer
!= NULL
)
1184 TCHAR szProduct
[MAXPNAMELEN
];
1186 /* get mixer product name */
1187 if (SndMixerGetProductName(MixerWindow
->Mixer
,
1189 sizeof(szProduct
) / sizeof(szProduct
[0])) == -1)
1191 /* failed to get name */
1192 szProduct
[0] = L
'\0';
1196 /* initialize preferences */
1197 ZeroMemory(&Preferences
, sizeof(Preferences
));
1200 Preferences
.Mixer
= MixerWindow
->Mixer
;
1202 /* store mixer window */
1203 Preferences
.MixerWindow
= MixerWindow
;
1205 /* first destination line id */
1206 Preferences
.SelectedLine
= 0xFFFF0000;
1209 wcscpy(Preferences
.DeviceName
, szProduct
);
1211 /* Disable the 'Advanced Controls' menu item */
1212 EnableMenuItem(GetMenu(hwnd
), IDM_ADVANCED_CONTROLS
, MF_BYCOMMAND
| MF_GRAYED
);
1214 /* create status window */
1215 if (MixerWindow
->Mode
== NORMAL_MODE
)
1217 MixerWindow
->hStatusBar
= CreateStatusWindow(WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
,
1221 if (MixerWindow
->hStatusBar
)
1223 SendMessage(MixerWindow
->hStatusBar
,
1230 if (!RebuildMixerWindowControls(&Preferences
))
1232 DPRINT("Rebuilding mixer window controls failed!\n");
1233 SndMixerDestroy(MixerWindow
->Mixer
);
1234 MixerWindow
->Mixer
= NULL
;
1243 MixerWindow
= GetWindowData(hwnd
,
1245 if (MixerWindow
!= NULL
)
1247 if (MixerWindow
->Mixer
!= NULL
)
1249 SndMixerDestroy(MixerWindow
->Mixer
);
1251 if (MixerWindow
->hFont
)
1252 DeleteObject(MixerWindow
->hFont
);
1253 HeapFree(hAppHeap
, 0, MixerWindow
);
1266 Result
= DefWindowProc(hwnd
,
1278 RegisterApplicationClasses(VOID
)
1282 wc
.cbSize
= sizeof(WNDCLASSEX
);
1283 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1284 wc
.lpfnWndProc
= MainWindowProc
;
1286 wc
.cbWndExtra
= sizeof(PMIXER_WINDOW
);
1287 wc
.hInstance
= hAppInstance
;
1288 wc
.hIcon
= LoadIcon(hAppInstance
,
1289 MAKEINTRESOURCE(IDI_MAINAPP
));
1290 wc
.hCursor
= LoadCursor(NULL
,
1292 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1293 wc
.lpszMenuName
= NULL
;
1294 wc
.lpszClassName
= SZ_APP_CLASS
;
1296 MainWindowClass
= RegisterClassEx(&wc
);
1298 return MainWindowClass
!= 0;
1302 UnregisterApplicationClasses(VOID
)
1304 UnregisterClass(SZ_APP_CLASS
,
1309 CreateApplicationWindow(
1310 WINDOW_MODE WindowMode
,
1315 PMIXER_WINDOW MixerWindow
= HeapAlloc(hAppHeap
,
1317 sizeof(MIXER_WINDOW
));
1318 if (MixerWindow
== NULL
)
1323 MixerWindow
->Mode
= WindowMode
;
1324 MixerWindow
->MixerId
= MixerId
;
1326 if (mixerGetNumDevs() > 0)
1328 hWnd
= CreateWindowEx(WS_EX_WINDOWEDGE
| WS_EX_CONTROLPARENT
,
1331 WS_DLGFRAME
| WS_CAPTION
| WS_MINIMIZEBOX
| WS_SYSMENU
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
| WS_VISIBLE
,
1334 LoadMenu(hAppInstance
,
1335 MAKEINTRESOURCE(IDM_MAINMENU
)),
1341 LPTSTR lpErrMessage
;
1344 * no mixer devices are available!
1348 if (AllocAndLoadString(&lpErrMessage
,
1350 IDS_NOMIXERDEVICES
))
1355 MB_ICONINFORMATION
);
1356 LocalFree(lpErrMessage
);
1372 HandleCommandLine(LPTSTR cmdline
,
1379 *pMixerId
= PLAY_MIXER
;
1380 *pMode
= (dwStyle
& 0x20) ? SMALL_MODE
: NORMAL_MODE
;
1382 while (*cmdline
== _T(' ') || *cmdline
== _T('-') || *cmdline
== _T('/'))
1384 if (*cmdline
++ == _T(' '))
1390 while (*cmdline
== _T(' '))
1395 case 'd': /* Device */
1399 case 'n': /* Small size */
1401 *pMode
= NORMAL_MODE
;
1404 case 's': /* Small size */
1406 *pMode
= SMALL_MODE
;
1409 case 't': /* Tray size */
1414 case 'p': /* Play mode */
1416 *pMixerId
= PLAY_MIXER
;
1419 case 'r': /* Record mode */
1421 *pMixerId
= RECORD_MIXER
;
1433 _tWinMain(HINSTANCE hInstance
,
1434 HINSTANCE hPrevInstance
,
1440 INITCOMMONCONTROLSEX Controls
;
1441 WINDOW_MODE WindowMode
= SMALL_MODE
;
1445 UNREFERENCED_PARAMETER(hPrevInstance
);
1446 UNREFERENCED_PARAMETER(nCmdShow
);
1448 hAppInstance
= hInstance
;
1449 hAppHeap
= GetProcessHeap();
1451 if (InitAppConfig())
1453 dwStyle
= GetStyleValue();
1454 HandleCommandLine(lpszCmdLine
, dwStyle
, &WindowMode
, &MixerId
);
1456 /* load the application title */
1457 if (!AllocAndLoadString(&lpAppTitle
,
1464 Controls
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
1465 Controls
.dwICC
= ICC_BAR_CLASSES
| ICC_STANDARD_CLASSES
;
1467 InitCommonControlsEx(&Controls
);
1469 if (WindowMode
== TRAY_MODE
)
1471 DialogBoxParam(hAppInstance
,
1472 MAKEINTRESOURCE(IDD_TRAY_MASTER
),
1479 if (RegisterApplicationClasses())
1481 hMainWnd
= CreateApplicationWindow(WindowMode
, MixerId
);
1482 if (hMainWnd
!= NULL
)
1485 while ((bRet
=GetMessage(&Msg
,
1492 TranslateMessage(&Msg
);
1493 DispatchMessage(&Msg
);
1497 DestroyWindow(hMainWnd
);
1502 DPRINT("Failed to create application window (LastError: %d)!\n", GetLastError());
1505 UnregisterApplicationClasses();
1509 DPRINT("Failed to register application classes (LastError: %d)!\n", GetLastError());
1513 if (lpAppTitle
!= NULL
)
1515 LocalFree(lpAppTitle
);
1522 DPRINT("Unable to open the Volume Control registry key!\n");