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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * VMware is a registered trademark of VMware, Inc.
23 * COPYRIGHT: See COPYING in the top level directory
24 * PROJECT: ReactOS Sound Volume Control
25 * FILE: subsys/system/sndvol32/sndvol32.c
26 * PROGRAMMERS: Thomas Weidenmueller <w3seek@reactos.com>
30 HINSTANCE hAppInstance
;
35 #define GetDialogData(hwndDlg, type) \
36 ( P##type )GetWindowLongPtr((hwndDlg), DWLP_USER)
37 #define GetWindowData(hwnd, type) \
38 ( P##type )GetWindowLongPtr((hwnd), GWL_USERDATA)
40 /******************************************************************************/
42 typedef struct _PREFERENCES_CONTEXT
44 PMIXER_WINDOW MixerWindow
;
47 } PREFERENCES_CONTEXT
, *PPREFERENCES_CONTEXT
;
49 typedef struct _PREFERENCES_FILL_DEVICES
51 PPREFERENCES_CONTEXT PrefContext
;
54 } PREFERENCES_FILL_DEVICES
, *PPREFERENCES_FILL_DEVICES
;
57 FillDeviceComboBox(PSND_MIXER Mixer
,
63 PPREFERENCES_FILL_DEVICES FillContext
= (PPREFERENCES_FILL_DEVICES
)Context
;
65 lres
= SendMessage(FillContext
->hComboBox
,
71 /* save the index so we don't screw stuff when the combobox is sorted... */
72 SendMessage(FillContext
->hComboBox
,
77 if (Id
== FillContext
->Selected
)
79 SendMessage(FillContext
->hComboBox
,
89 static INT_PTR CALLBACK
90 DlgPreferencesProc(HWND hwndDlg
,
95 PPREFERENCES_CONTEXT Context
;
101 switch (LOWORD(wParam
))
114 case MM_MIXM_LINE_CHANGE
:
116 DPRINT("MM_MIXM_LINE_CHANGE\n");
120 case MM_MIXM_CONTROL_CHANGE
:
122 DPRINT("MM_MIXM_CONTROL_CHANGE\n");
128 PREFERENCES_FILL_DEVICES FillDevContext
;
130 SetWindowLongPtr(hwndDlg
,
133 Context
= (PPREFERENCES_CONTEXT
)((LONG_PTR
)lParam
);
134 Context
->hwndDlg
= hwndDlg
;
135 Context
->Mixer
= SndMixerCreate(hwndDlg
);
137 FillDevContext
.PrefContext
= Context
;
138 FillDevContext
.hComboBox
= GetDlgItem(hwndDlg
,
140 FillDevContext
.Selected
= SndMixerGetSelection(Context
->Mixer
);
141 SndMixerEnumProducts(Context
->Mixer
,
149 Context
= GetDialogData(hwndDlg
,
150 PREFERENCES_CONTEXT
);
151 if (Context
->Mixer
!= NULL
)
153 SndMixerDestroy(Context
->Mixer
);
169 /******************************************************************************/
172 DeleteMixerWindowControls(PMIXER_WINDOW MixerWindow
)
177 RebuildMixerWindowControls(PMIXER_WINDOW MixerWindow
)
179 DeleteMixerWindowControls(MixerWindow
);
185 MainWindowProc(HWND hwnd
,
190 PMIXER_WINDOW MixerWindow
;
197 MixerWindow
= GetWindowData(hwnd
,
200 switch (LOWORD(wParam
))
204 PREFERENCES_CONTEXT Preferences
;
206 Preferences
.MixerWindow
= MixerWindow
;
207 Preferences
.Mixer
= NULL
;
209 if (DialogBoxParam(hAppInstance
,
210 MAKEINTRESOURCE(IDD_PREFERENCES
),
213 (LPARAM
)&Preferences
) == IDOK
)
215 /* FIXME - update window */
229 case MM_MIXM_LINE_CHANGE
:
231 DPRINT("MM_MIXM_LINE_CHANGE\n");
235 case MM_MIXM_CONTROL_CHANGE
:
237 DPRINT("MM_MIXM_CONTROL_CHANGE\n");
243 MixerWindow
= ((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
244 SetWindowLongPtr(hwnd
,
246 (LONG_PTR
)MixerWindow
);
247 MixerWindow
->hWnd
= hwnd
;
248 MixerWindow
->hStatusBar
= CreateStatusWindow(WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
,
252 if (MixerWindow
->hStatusBar
!= NULL
)
254 MixerWindow
->Mixer
= SndMixerCreate(MixerWindow
->hWnd
);
255 if (MixerWindow
->Mixer
!= NULL
)
257 TCHAR szProduct
[MAXPNAMELEN
];
259 if (SndMixerGetProductName(MixerWindow
->Mixer
,
261 sizeof(szProduct
) / sizeof(szProduct
[0])) > 0)
263 SendMessage(MixerWindow
->hStatusBar
,
269 if (!RebuildMixerWindowControls(MixerWindow
))
271 DPRINT("Rebuilding mixer window controls failed!\n");
272 SndMixerDestroy(MixerWindow
->Mixer
);
283 DPRINT("Failed to create status window!\n");
291 MixerWindow
= GetWindowData(hwnd
,
293 if (MixerWindow
->Mixer
!= NULL
)
295 SndMixerDestroy(MixerWindow
->Mixer
);
308 Result
= DefWindowProc(hwnd
,
320 RegisterApplicationClasses(VOID
)
324 wc
.cbSize
= sizeof(WNDCLASSEX
);
325 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
326 wc
.lpfnWndProc
= MainWindowProc
;
328 wc
.cbWndExtra
= sizeof(PMIXER_WINDOW
);
329 wc
.hInstance
= hAppInstance
;
330 wc
.hIcon
= LoadIcon(hAppInstance
,
331 MAKEINTRESOURCE(IDI_MAINAPP
));
332 wc
.hCursor
= LoadCursor(NULL
,
334 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
335 wc
.lpszMenuName
= NULL
;
336 wc
.lpszClassName
= SZ_APP_CLASS
;
338 MainWindowClass
= RegisterClassEx(&wc
);
340 return MainWindowClass
!= 0;
344 UnregisterApplicationClasses(VOID
)
346 UnregisterClass(SZ_APP_CLASS
,
351 CreateApplicationWindow(VOID
)
356 PMIXER_WINDOW MixerWindow
= HeapAlloc(hAppHeap
,
358 sizeof(MIXER_WINDOW
));
359 if (MixerWindow
== NULL
)
364 /* load the application title */
365 if (AllocAndLoadString(&lpAppTitle
,
372 if (mixerGetNumDevs() > 0)
374 hWnd
= CreateWindowEx(WS_EX_WINDOWEDGE
| WS_EX_CONTROLPARENT
,
377 WS_DLGFRAME
| WS_CAPTION
| WS_MINIMIZEBOX
| WS_SYSMENU
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
| WS_VISIBLE
,
378 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
380 LoadMenu(hAppInstance
,
381 MAKEINTRESOURCE(IDM_MAINMENU
)),
390 * no mixer devices are available!
394 AllocAndLoadString(&lpErrMessage
,
401 LocalFree(lpErrMessage
);
404 if (lpAppTitle
!= NULL
)
406 LocalFree(lpAppTitle
);
420 WinMain(HINSTANCE hInstance
,
421 HINSTANCE hPrevInstance
,
427 hAppInstance
= hInstance
;
428 hAppHeap
= GetProcessHeap();
430 InitCommonControls();
432 if (!RegisterApplicationClasses())
434 DPRINT("Failed to register application classes (LastError: %d)!\n", GetLastError());
438 hMainWnd
= CreateApplicationWindow();
439 if (hMainWnd
== NULL
)
441 DPRINT("Failed to creat application window (LastError: %d)!\n", GetLastError());
445 while (GetMessage(&Msg
,
450 TranslateMessage(&Msg
);
451 DispatchMessage(&Msg
);
454 DestroyWindow(hMainWnd
);
456 UnregisterApplicationClasses();