ole32: Avoid uninitialized value to be potentialy passed to UnhookWindowsHookEx.
[wine/multimedia.git] / programs / winecfg / audio.c
blob9f8a0a2b010853ac6b534ada6e2175b756bf69bf
1 /*
2 * Audio management UI code
4 * Copyright 2004 Chris Morgan
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.
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.
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
22 #define WIN32_LEAN_AND_MEAN
23 #define NONAMELESSSTRUCT
24 #define NONAMELESSUNION
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
34 #include <windows.h>
35 #include <wine/debug.h>
36 #include <shellapi.h>
37 #include <objbase.h>
38 #include <shlguid.h>
39 #include <shlwapi.h>
40 #include <shlobj.h>
41 #include <mmsystem.h>
42 #include <mmreg.h>
43 #include <mmddk.h>
45 #include "winecfg.h"
46 #include "resource.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
50 #define DRIVER_MASK 0x80000000
51 #define DEVICE_MASK 0x40000000
52 #define MAX_NAME_LENGTH 64
54 typedef DWORD (WINAPI * MessagePtr)(UINT, UINT, DWORD, DWORD, DWORD);
56 static struct DSOUNDACCEL
58 UINT displayID;
59 UINT visible;
60 const char* settingStr;
61 } DSound_HW_Accels[] = {
62 {IDS_ACCEL_FULL, 1, "Full"},
63 {IDS_ACCEL_STANDARD, 0, "Standard"},
64 {IDS_ACCEL_BASIC, 0, "Basic"},
65 {IDS_ACCEL_EMULATION, 1, "Emulation"},
66 {0, 0, 0}
69 static const char* DSound_Rates[] = {
70 "48000",
71 "44100",
72 "22050",
73 "16000",
74 "11025",
75 "8000",
76 NULL
79 static const char* DSound_Bits[] = {
80 "8",
81 "16",
82 NULL
85 typedef struct
87 UINT nameID;
88 const char *szDriver;
89 } AUDIO_DRIVER;
91 static const AUDIO_DRIVER sAudioDrivers[] = {
92 {IDS_DRIVER_ALSA, "alsa"},
93 {IDS_DRIVER_OSS, "oss"},
94 {IDS_DRIVER_COREAUDIO, "coreaudio"},
95 {IDS_DRIVER_JACK, "jack"},
96 {IDS_DRIVER_NAS, "nas"},
97 {IDS_DRIVER_ESOUND, "esd"},
98 {IDS_DRIVER_AUDIOIO, "audioio"},
99 {0, ""}
102 /* list of available drivers */
103 static AUDIO_DRIVER * loadedAudioDrv;
105 /* local copy of registry setting */
106 static char curAudioDriver[1024];
108 /* driver index to configure */
109 static int toConfigure;
111 /* display a driver specific configuration dialog */
112 static void configureAudioDriver(HWND hDlg)
114 const AUDIO_DRIVER *pAudioDrv = &loadedAudioDrv[toConfigure];
116 if (strlen(pAudioDrv->szDriver) != 0)
118 HDRVR hdrvr;
119 char wine_driver[MAX_NAME_LENGTH + 9];
120 sprintf(wine_driver, "wine%s.drv", pAudioDrv->szDriver);
121 hdrvr = OpenDriverA(wine_driver, 0, 0);
122 if (hdrvr != 0)
124 if (SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
126 DRVCONFIGINFO dci;
127 LONG lRes;
128 dci.dwDCISize = sizeof (dci);
129 dci.lpszDCISectionName = NULL;
130 dci.lpszDCIAliasName = NULL;
131 lRes = SendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LONG_PTR)&dci);
133 CloseDriver(hdrvr, 0, 0);
135 else
137 WCHAR wine_driverW[MAX_NAME_LENGTH+9];
138 WCHAR messageStr[256];
139 WCHAR str[1024];
141 MultiByteToWideChar (CP_ACP, 0, wine_driver, -1, wine_driverW,
142 sizeof (wine_driverW)/sizeof(wine_driverW[0]));
144 LoadStringW (GetModuleHandle (NULL), IDS_OPEN_DRIVER_ERROR, messageStr,
145 sizeof(messageStr)/sizeof(messageStr[0]));
146 wsprintfW (str, messageStr, wine_driverW);
147 MessageBoxW (hDlg, str, NULL, MB_OK | MB_ICONERROR);
152 /* is driver in local copy of driver registry string */
153 static BOOL isDriverSet(const char * driver)
155 WINE_TRACE("driver = %s, curAudioDriver = %s\n", driver, curAudioDriver);
157 if (strstr(curAudioDriver, driver))
158 return TRUE;
160 return FALSE;
163 /* add driver to local copy of driver registry string */
164 static void addDriver(const char * driver)
166 if (!isDriverSet(driver))
168 if (strlen(curAudioDriver))
169 strcat(curAudioDriver, ",");
170 strcat(curAudioDriver, driver);
174 /* remove driver from local copy of driver registry string */
175 static void removeDriver(const char * driver)
177 char pattern[32], *p;
178 int drvlen, listlen;
180 strcpy(pattern, ",");
181 strcat(pattern, driver);
182 strcat(pattern, ",");
183 drvlen = strlen(driver);
184 listlen = strlen(curAudioDriver);
186 p = strstr(curAudioDriver, pattern);
187 if (p) /* somewhere in the middle */
188 memmove(p, p+drvlen+1, strlen(p+drvlen+1)+1);
189 else if (!strncmp(curAudioDriver, pattern+1, drvlen+1)) /* the head */
190 memmove(curAudioDriver, curAudioDriver+drvlen+1, listlen-drvlen);
191 else if (!strncmp(curAudioDriver+listlen-drvlen-1, pattern, drvlen+1)) /* the tail */
192 curAudioDriver[listlen-drvlen-1] = 0;
193 else if (!strcmp(curAudioDriver, driver)) /* only one entry (head&tail) */
194 curAudioDriver[0] = 0;
195 else
196 WINE_FIXME("driver '%s' is not in the list, please report!\n", driver);
199 static void initAudioDeviceTree(HWND hDlg)
201 const AUDIO_DRIVER *pAudioDrv = NULL;
202 int i, j;
203 TVINSERTSTRUCTW insert;
204 HTREEITEM root, driver[10];
205 HWND tree = NULL;
206 HIMAGELIST hImageList;
207 HBITMAP hBitMap;
208 HCURSOR old_cursor;
209 WCHAR driver_type[64], dev_type[64];
211 tree = GetDlgItem(hDlg, IDC_AUDIO_TREE);
213 if (!tree)
214 return;
216 /* set tree view style */
217 SetWindowLong(tree, GWL_STYLE, GetWindowLong(tree, GWL_STYLE) | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
219 /* state checkbox */
220 hImageList = ImageList_Create(16, 16, FALSE, 3, 0);
221 hBitMap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_CHECKBOX));
222 ImageList_Add(hImageList, hBitMap, NULL);
223 DeleteObject(hBitMap);
224 SendMessageW( tree, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)hImageList );
226 /* root item */
227 LoadStringW (GetModuleHandle (NULL), IDS_SOUNDDRIVERS, driver_type,
228 sizeof(driver_type)/sizeof(driver_type[0]));
229 insert.hParent = TVI_ROOT;
230 insert.hInsertAfter = TVI_LAST;
231 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
232 insert.u.item.pszText = driver_type;
233 insert.u.item.cChildren = 1;
234 root = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
236 /* change to the wait cursor because this can take a while if there is a
237 * misbehaving driver that takes a long time to open
239 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
241 /* iterate over list of loaded drivers */
242 for (pAudioDrv = loadedAudioDrv, i = 0; pAudioDrv->nameID; i++, pAudioDrv++) {
243 HDRVR hdrv;
244 char name[MAX_PATH];
245 WCHAR text[MAX_PATH];
247 sprintf(name, "wine%s.drv", pAudioDrv->szDriver);
248 LoadStringW (GetModuleHandle (NULL), pAudioDrv->nameID, text,
249 sizeof(text)/sizeof(text[0]));
251 if ((hdrv = OpenDriverA(name, 0, 0)))
253 HMODULE lib;
254 if ((lib = GetDriverModuleHandle(hdrv)))
256 int num_wod = 0, num_wid = 0, num_mod = 0, num_mid = 0, num_aux = 0, num_mxd = 0;
257 MessagePtr wodMessagePtr = (MessagePtr)GetProcAddress(lib, "wodMessage");
258 MessagePtr widMessagePtr = (MessagePtr)GetProcAddress(lib, "widMessage");
259 MessagePtr modMessagePtr = (MessagePtr)GetProcAddress(lib, "modMessage");
260 MessagePtr midMessagePtr = (MessagePtr)GetProcAddress(lib, "midMessage");
261 MessagePtr auxMessagePtr = (MessagePtr)GetProcAddress(lib, "auxMessage");
262 MessagePtr mxdMessagePtr = (MessagePtr)GetProcAddress(lib, "mxdMessage");
264 if (wodMessagePtr)
265 num_wod = wodMessagePtr(0, WODM_GETNUMDEVS, 0, 0, 0);
267 if (widMessagePtr)
268 num_wid = widMessagePtr(0, WIDM_GETNUMDEVS, 0, 0, 0);
270 if (modMessagePtr)
271 num_mod = modMessagePtr(0, MODM_GETNUMDEVS, 0, 0, 0);
273 if (midMessagePtr)
274 num_mid = midMessagePtr(0, MIDM_GETNUMDEVS, 0, 0, 0);
276 if (auxMessagePtr)
277 num_aux = auxMessagePtr(0, AUXDM_GETNUMDEVS, 0, 0, 0);
279 if (mxdMessagePtr)
280 num_mxd = mxdMessagePtr(0, MXDM_GETNUMDEVS, 0, 0, 0);
282 if (num_wod == 0 && num_wid == 0 && num_mod == 0 && num_mid == 0 && num_aux == 0 && num_mxd == 0)
284 insert.hParent = root;
285 insert.u.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
286 insert.u.item.pszText = text;
287 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
288 insert.u.item.lParam = i + DRIVER_MASK;
289 if (isDriverSet(pAudioDrv->szDriver))
290 insert.u.item.state = INDEXTOSTATEIMAGEMASK(2);
291 else
292 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
294 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
296 else
298 HTREEITEM type;
300 insert.hParent = root;
301 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN | TVIF_STATE | TVIF_PARAM;
302 insert.u.item.pszText = text;
303 insert.u.item.cChildren = 1;
304 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
305 insert.u.item.lParam = i + DRIVER_MASK;
307 if (isDriverSet(pAudioDrv->szDriver))
308 insert.u.item.state = INDEXTOSTATEIMAGEMASK(2);
309 else
310 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
312 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
314 if (num_wod)
316 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_WAVEOUT, dev_type,
317 sizeof(dev_type)/sizeof(dev_type[0]));
319 insert.hParent = driver[i];
320 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
321 insert.u.item.pszText = dev_type;
322 insert.u.item.cChildren = 1;
324 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
326 for (j = 0; j < num_wod; j++)
328 WAVEOUTCAPSW caps;
330 wodMessagePtr(j, WODM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
332 insert.hParent = type;
333 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
334 insert.u.item.pszText = caps.szPname;
335 insert.u.item.lParam = j + DEVICE_MASK;
337 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
341 if (num_wid)
343 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_WAVEIN, dev_type,
344 sizeof(dev_type)/sizeof(dev_type[0]));
346 insert.hParent = driver[i];
347 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
348 insert.u.item.pszText = dev_type;
349 insert.u.item.cChildren = 1;
351 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
353 for (j = 0; j < num_wid; j++)
355 WAVEINCAPSW caps;
357 widMessagePtr(j, WIDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
359 insert.hParent = type;
360 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
361 insert.u.item.pszText = caps.szPname;
362 insert.u.item.lParam = j + DEVICE_MASK;
364 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
368 if (num_mod)
370 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIDIOUT, dev_type,
371 sizeof(dev_type)/sizeof(dev_type[0]));
373 insert.hParent = driver[i];
374 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
375 insert.u.item.pszText = dev_type;
376 insert.u.item.cChildren = 1;
378 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
380 for (j = 0; j < num_mod; j++)
382 MIDIOUTCAPSW caps;
384 modMessagePtr(j, MODM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
386 insert.hParent = type;
387 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
388 insert.u.item.pszText = caps.szPname;
389 insert.u.item.lParam = j + DEVICE_MASK;
391 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
395 if (num_mid)
397 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIDIIN, dev_type,
398 sizeof(dev_type)/sizeof(dev_type[0]));
400 insert.hParent = driver[i];
401 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
402 insert.u.item.pszText = dev_type;
403 insert.u.item.cChildren = 1;
405 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
407 for (j = 0; j < num_mid; j++)
409 MIDIINCAPSW caps;
411 midMessagePtr(j, MIDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
413 insert.hParent = type;
414 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
415 insert.u.item.pszText = caps.szPname;
416 insert.u.item.lParam = j + DEVICE_MASK;
418 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
422 if (num_aux)
424 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_AUX, dev_type,
425 sizeof(dev_type)/sizeof(dev_type[0]));
427 insert.hParent = driver[i];
428 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
429 insert.u.item.pszText = dev_type;
430 insert.u.item.cChildren = 1;
432 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
434 for (j = 0; j < num_aux; j++)
436 AUXCAPSW caps;
438 auxMessagePtr(j, AUXDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
440 insert.hParent = type;
441 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
442 insert.u.item.pszText = caps.szPname;
443 insert.u.item.lParam = j + DEVICE_MASK;
445 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
449 if (num_mxd)
451 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIXER, dev_type,
452 sizeof(dev_type)/sizeof(dev_type[0]));
454 insert.hParent = driver[i];
455 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
456 insert.u.item.pszText = dev_type;
457 insert.u.item.cChildren = 1;
459 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
461 for (j = 0; j < num_mxd; j++)
463 MIXERCAPSW caps;
465 mxdMessagePtr(j, MXDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
467 insert.hParent = type;
468 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
469 insert.u.item.pszText = caps.szPname;
470 insert.u.item.lParam = j + DEVICE_MASK;
472 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
477 CloseDriver(hdrv, 0, 0);
481 /* restore the original cursor */
482 SetCursor(old_cursor);
484 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_SELECTITEM, 0, 0);
485 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)root);
486 for (j = 0; j < i; j++)
487 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)driver[j]);
490 /* find all drivers that can be loaded */
491 static void findAudioDrivers(void)
493 int numFound = 0;
494 const AUDIO_DRIVER *pAudioDrv = NULL;
495 HCURSOR old_cursor;
497 /* delete an existing list */
498 HeapFree(GetProcessHeap(), 0, loadedAudioDrv);
499 loadedAudioDrv = 0;
501 /* change to the wait cursor because this can take a while if there is a
502 * misbehaving driver that takes a long time to open
504 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
506 for (pAudioDrv = sAudioDrivers; pAudioDrv->nameID; pAudioDrv++)
508 if (strlen(pAudioDrv->szDriver))
510 HDRVR hdrv;
511 char driver[MAX_PATH];
513 sprintf(driver, "wine%s.drv", pAudioDrv->szDriver);
515 if ((hdrv = OpenDriverA(driver, 0, 0)))
517 CloseDriver(hdrv, 0, 0);
519 if (loadedAudioDrv)
520 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
521 else
522 loadedAudioDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER));
524 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
525 numFound++;
530 /* restore the original cursor */
531 SetCursor(old_cursor);
533 /* terminate list with empty driver */
534 if (numFound) {
535 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
536 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
537 } else {
538 loadedAudioDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER));
539 CopyMemory(&loadedAudioDrv[0], pAudioDrv, sizeof(AUDIO_DRIVER));
543 /* check local copy of registry string for unloadable drivers */
544 static void checkRegistrySetting(HWND hDlg)
546 const AUDIO_DRIVER *pAudioDrv;
547 char * token, * tokens;
549 tokens = HeapAlloc(GetProcessHeap(), 0, strlen(curAudioDriver)+1);
550 strcpy(tokens, curAudioDriver);
552 start_over:
553 token = strtok(tokens, ",");
554 while (token != NULL)
556 BOOL found = FALSE;
557 for (pAudioDrv = loadedAudioDrv; pAudioDrv->nameID; pAudioDrv++)
559 if (strcmp(token, pAudioDrv->szDriver) == 0)
561 found = TRUE;
562 break;
565 if (found == FALSE)
567 WCHAR tokenW[MAX_NAME_LENGTH+1];
568 WCHAR messageStr[256];
569 WCHAR str[1024];
570 WCHAR caption[64];
572 MultiByteToWideChar (CP_ACP, 0, token, -1, tokenW, sizeof(tokenW)/sizeof(tokenW[0]));
574 LoadStringW (GetModuleHandle (NULL), IDS_UNAVAILABLE_DRIVER, messageStr,
575 sizeof(messageStr)/sizeof(messageStr[0]));
576 wsprintfW (str, messageStr, tokenW);
577 LoadStringW (GetModuleHandle (NULL), IDS_WARNING, caption,
578 sizeof(caption)/sizeof(caption[0]));
579 if (MessageBoxW (hDlg, str, caption, MB_ICONWARNING | MB_YESNOCANCEL) == IDYES)
581 removeDriver(token);
582 strcpy(tokens, curAudioDriver);
583 goto start_over;
586 token = strtok(NULL, ",");
588 HeapFree(GetProcessHeap(), 0, tokens);
591 static void selectDriver(HWND hDlg, const char * driver)
593 WCHAR text[1024];
594 WCHAR caption[64];
596 strcpy(curAudioDriver, driver);
597 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
599 if (LoadStringW(GetModuleHandle(NULL), IDS_AUDIO_MISSING, text, sizeof(text)/sizeof(text[0])))
601 if (LoadStringW(GetModuleHandle(NULL), IDS_WINECFG_TITLE, caption, sizeof(caption)/sizeof(caption[0])))
602 MessageBoxW(hDlg, text, caption, MB_OK | MB_ICONINFORMATION);
605 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
608 static void initAudioDlg (HWND hDlg)
610 int i, j, found;
611 char* buf = NULL;
613 WINE_TRACE("\n");
615 /* make a list of all drivers that can be loaded */
616 findAudioDrivers();
618 /* get current registry setting if available */
619 buf = get_reg_key(config_key, "Drivers", "Audio", NULL);
621 /* check for first time install and set a default driver
622 * select first available driver, and if that fails: none
624 if (buf == NULL)
626 /* select first available driver */
627 if (*loadedAudioDrv->szDriver)
628 selectDriver(hDlg, loadedAudioDrv->szDriver);
630 else /* make a local copy of the current registry setting */
631 strcpy(curAudioDriver, buf);
633 WINE_TRACE("curAudioDriver = %s\n", curAudioDriver);
635 /* check for drivers that can't be loaded */
636 checkRegistrySetting(hDlg);
638 initAudioDeviceTree(hDlg);
640 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_RESETCONTENT, 0, 0);
641 buf = get_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration", "Full");
643 j = found = 0;
644 for (i = 0; 0 != DSound_HW_Accels[i].displayID; ++i) {
645 WCHAR accelStr[64];
646 int match;
648 match = (strcmp(buf, DSound_HW_Accels[i].settingStr) == 0);
649 if (match)
651 DSound_HW_Accels[i].visible = 1;
652 found = 1;
655 if (DSound_HW_Accels[i].visible)
657 LoadStringW (GetModuleHandle (NULL), DSound_HW_Accels[i].displayID,
658 accelStr, sizeof(accelStr)/sizeof(accelStr[0]));
659 SendDlgItemMessageW (hDlg, IDC_DSOUND_HW_ACCEL, CB_ADDSTRING, 0, (LPARAM)accelStr);
660 if (match)
661 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_SETCURSEL, j, 0);
662 j++;
665 if (!found) {
666 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf);
668 HeapFree(GetProcessHeap(), 0, buf);
670 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_RESETCONTENT, 0, 0);
671 for (i = 0; NULL != DSound_Rates[i]; ++i) {
672 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_ADDSTRING, 0, (LPARAM) DSound_Rates[i]);
674 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", "44100");
675 for (i = 0; NULL != DSound_Rates[i]; ++i) {
676 if (strcmp(buf, DSound_Rates[i]) == 0) {
677 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_SETCURSEL, i, 0);
678 break ;
682 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_RESETCONTENT, 0, 0);
683 for (i = 0; NULL != DSound_Bits[i]; ++i) {
684 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_ADDSTRING, 0, (LPARAM) DSound_Bits[i]);
686 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", "16");
687 for (i = 0; NULL != DSound_Bits[i]; ++i) {
688 if (strcmp(buf, DSound_Bits[i]) == 0) {
689 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_SETCURSEL, i, 0);
690 break ;
693 HeapFree(GetProcessHeap(), 0, buf);
696 INT_PTR CALLBACK
697 AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
699 switch (uMsg) {
700 case WM_COMMAND:
701 switch (LOWORD(wParam)) {
702 case IDC_AUDIO_CONFIGURE:
703 configureAudioDriver(hDlg);
704 break;
705 case IDC_AUDIO_TEST:
706 if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND), NULL, SND_RESOURCE | SND_SYNC))
707 MessageBox(NULL, "Audio test failed!", "Error", MB_OK | MB_ICONERROR);
708 break;
709 case IDC_AUDIO_CONTROL_PANEL:
710 MessageBox(NULL, "Launching audio control panel not implemented yet!", "Fixme", MB_OK | MB_ICONERROR);
711 break;
712 case IDC_DSOUND_HW_ACCEL:
713 if (HIWORD(wParam) == CBN_SELCHANGE) {
714 int selected_dsound_accel;
715 int i, j = 0;
717 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
718 selected_dsound_accel = SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_GETCURSEL, 0, 0);
719 for (i = 0; DSound_HW_Accels[i].settingStr; ++i)
721 if (DSound_HW_Accels[i].visible)
723 if (j == selected_dsound_accel)
725 set_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration",
726 DSound_HW_Accels[i].settingStr);
727 break;
729 j++;
733 break;
734 case IDC_DSOUND_RATES:
735 if (HIWORD(wParam) == CBN_SELCHANGE) {
736 int selected_dsound_rate;
737 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
738 selected_dsound_rate = SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_GETCURSEL, 0, 0);
739 set_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", DSound_Rates[selected_dsound_rate]);
741 break;
742 case IDC_DSOUND_BITS:
743 if (HIWORD(wParam) == CBN_SELCHANGE) {
744 int selected_dsound_bits;
745 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
746 selected_dsound_bits = SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_GETCURSEL, 0, 0);
747 set_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", DSound_Bits[selected_dsound_bits]);
749 break;
751 break;
753 case WM_SHOWWINDOW:
754 set_window_title(hDlg);
755 break;
757 case WM_NOTIFY:
758 switch(((LPNMHDR)lParam)->code) {
759 case PSN_KILLACTIVE:
760 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
761 break;
762 case PSN_APPLY:
763 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
764 apply();
765 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
766 break;
767 case PSN_SETACTIVE:
768 break;
769 case NM_CLICK:
770 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
772 TVHITTESTINFO ht;
773 DWORD dwPos = GetMessagePos();
774 HWND tree = ((LPNMHDR)lParam)->hwndFrom;
775 ZeroMemory(&ht, sizeof(ht));
776 ht.pt.x = (short)LOWORD(dwPos);
777 ht.pt.y = (short)HIWORD(dwPos);
778 MapWindowPoints(HWND_DESKTOP, tree, &ht.pt, 1);
779 SendMessageW( tree, TVM_HITTEST, 0, (LPARAM)&ht );
780 if (TVHT_ONITEMSTATEICON & ht.flags)
782 TVITEM tvItem;
783 int index;
784 ZeroMemory(&tvItem, sizeof(tvItem));
785 tvItem.hItem = ht.hItem;
786 SendMessageW( tree, TVM_GETITEMW, 0, (LPARAM) &tvItem );
788 index = TreeView_GetItemState(tree, ht.hItem, TVIS_STATEIMAGEMASK);
789 if (index == INDEXTOSTATEIMAGEMASK(1))
791 TreeView_SetItemState(tree, ht.hItem, INDEXTOSTATEIMAGEMASK(2), TVIS_STATEIMAGEMASK);
792 addDriver(loadedAudioDrv[tvItem.lParam & 0xff].szDriver);
793 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
795 else if (index == INDEXTOSTATEIMAGEMASK(2))
797 TreeView_SetItemState(tree, ht.hItem, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK);
798 removeDriver(loadedAudioDrv[tvItem.lParam & 0xff].szDriver);
799 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
803 break;
804 case NM_RCLICK:
805 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
807 TVHITTESTINFO ht;
808 DWORD dwPos = GetMessagePos();
809 HWND tree = ((LPNMHDR)lParam)->hwndFrom;
810 POINT pt;
811 ZeroMemory(&ht, sizeof(ht));
812 pt.x = (short)LOWORD(dwPos);
813 pt.y = (short)HIWORD(dwPos);
814 ht.pt = pt;
815 MapWindowPoints(HWND_DESKTOP, tree, &ht.pt, 1);
816 SendMessageW( tree, TVM_HITTEST, 0, (LPARAM)&ht );
817 if (TVHT_ONITEMLABEL & ht.flags)
819 TVITEM tvItem;
820 ZeroMemory(&tvItem, sizeof(tvItem));
821 tvItem.hItem = ht.hItem;
822 tvItem.mask = TVIF_PARAM;
823 tvItem.lParam = -1;
824 if (TreeView_GetItem(tree, &tvItem))
826 if (tvItem.lParam & DRIVER_MASK)
828 if (hPopupMenus)
830 TrackPopupMenu(GetSubMenu(hPopupMenus, 0), TPM_RIGHTBUTTON, pt.x, pt.y, 0, tree, NULL);
831 toConfigure = tvItem.lParam & ~DRIVER_MASK;
834 else if (tvItem.lParam & DEVICE_MASK)
836 /* FIXME TBD */
843 break;
845 case WM_INITDIALOG:
846 initAudioDlg(hDlg);
847 break;
850 return FALSE;