winecfg: Replace DirectSound settings with Driver Diagnostics.
[wine] / programs / winecfg / audio.c
1 /*
2  * Audio management UI code
3  *
4  * Copyright 2004 Chris Morgan
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  */
21
22 #define WIN32_LEAN_AND_MEAN
23 #define NONAMELESSSTRUCT
24 #define NONAMELESSUNION
25
26 #include "config.h"
27 #include "wine/port.h"
28
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33
34 #define COBJMACROS
35 #include <windows.h>
36 #include <wine/debug.h>
37 #include <shellapi.h>
38 #include <objbase.h>
39 #include <shlguid.h>
40 #include <shlwapi.h>
41 #include <shlobj.h>
42 #include <mmsystem.h>
43 #include <mmreg.h>
44 #include <mmddk.h>
45
46 #include "ole2.h"
47 #include "initguid.h"
48 #include "devpkey.h"
49 #include "mmdeviceapi.h"
50 #include "audioclient.h"
51 #include "audiopolicy.h"
52
53 #include "winecfg.h"
54 #include "resource.h"
55
56 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
57
58 static BOOL get_driver_name(PROPVARIANT *pv)
59 {
60     IMMDeviceEnumerator *devenum;
61     IMMDevice *device;
62     IPropertyStore *ps;
63     HRESULT hr;
64
65     static const WCHAR wine_info_deviceW[] = {'W','i','n','e',' ',
66         'i','n','f','o',' ','d','e','v','i','c','e',0};
67
68     hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
69             CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&devenum);
70     if(FAILED(hr))
71         return FALSE;
72
73     hr = IMMDeviceEnumerator_GetDevice(devenum, wine_info_deviceW, &device);
74     IMMDeviceEnumerator_Release(devenum);
75     if(FAILED(hr))
76         return FALSE;
77
78     hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
79     if(FAILED(hr)){
80         IMMDevice_Release(device);
81         return FALSE;
82     }
83
84     hr = IPropertyStore_GetValue(ps,
85             (const PROPERTYKEY *)&DEVPKEY_Device_Driver, pv);
86     IPropertyStore_Release(ps);
87     IMMDevice_Release(device);
88     if(FAILED(hr))
89         return FALSE;
90
91     return TRUE;
92 }
93
94 static void initAudioDlg (HWND hDlg)
95 {
96     WCHAR display_str[256], format_str[256], disabled_str[64];
97     PROPVARIANT pv;
98
99     WINE_TRACE("\n");
100
101     LoadStringW(GetModuleHandle(NULL), IDS_AUDIO_DRIVER,
102             format_str, sizeof(format_str) / sizeof(*format_str));
103     LoadStringW(GetModuleHandle(NULL), IDS_AUDIO_DRIVER_NONE,
104             disabled_str, sizeof(disabled_str) / sizeof(*disabled_str));
105
106     PropVariantInit(&pv);
107     if(get_driver_name(&pv) && pv.u.pwszVal[0] != '\0')
108         wnsprintfW(display_str, sizeof(display_str) / sizeof(*display_str),
109                 format_str, pv.u.pwszVal);
110     else
111         wnsprintfW(display_str, sizeof(display_str) / sizeof(*display_str),
112                 format_str, disabled_str);
113     PropVariantClear(&pv);
114
115     SetDlgItemTextW(hDlg, IDC_AUDIO_DRIVER, display_str);
116 }
117
118 INT_PTR CALLBACK
119 AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
120 {
121   switch (uMsg) {
122       case WM_COMMAND:
123         switch (LOWORD(wParam)) {
124           case IDC_AUDIO_TEST:
125               if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND), NULL, SND_RESOURCE | SND_SYNC))
126                   MessageBox(NULL, "Audio test failed!", "Error", MB_OK | MB_ICONERROR);
127               break;
128         }
129       case WM_SHOWWINDOW:
130         set_window_title(hDlg);
131         break;
132
133       case WM_NOTIFY:
134         switch(((LPNMHDR)lParam)->code) {
135             case PSN_KILLACTIVE:
136               SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
137               break;
138             case PSN_APPLY:
139               apply();
140               SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
141               break;
142             case PSN_SETACTIVE:
143               break;
144         }
145         break;
146       case WM_INITDIALOG:
147         initAudioDlg(hDlg);
148         break;
149   }
150
151   return FALSE;
152 }