netapi32/tests: Fix a failing test on localized Windows.
[wine/hramrach.git] / programs / winecfg / audio.c
blob3ce0e25f4b6c4c2ef5d00dcd0c0cd9b587c36f32
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 const char* settingStr;
60 } const DSound_HW_Accels[] = {
61 {IDS_ACCEL_FULL, "Full"},
62 {IDS_ACCEL_STANDARD, "Standard"},
63 {IDS_ACCEL_BASIC, "Basic"},
64 {IDS_ACCEL_EMULATION, "Emulation"},
65 {0, 0}
68 static const char* DSound_Rates[] = {
69 "48000",
70 "44100",
71 "22050",
72 "16000",
73 "11025",
74 "8000",
75 NULL
78 static const char* DSound_Bits[] = {
79 "8",
80 "16",
81 NULL
84 typedef struct
86 UINT nameID;
87 const char *szDriver;
88 } AUDIO_DRIVER;
90 static const AUDIO_DRIVER sAudioDrivers[] = {
91 {IDS_DRIVER_ALSA, "alsa"},
92 {IDS_DRIVER_OSS, "oss"},
93 {IDS_DRIVER_COREAUDIO, "coreaudio"},
94 {IDS_DRIVER_JACK, "jack"},
95 {IDS_DRIVER_NAS, "nas"},
96 {IDS_DRIVER_ESOUND, "esd"},
97 {IDS_DRIVER_AUDIOIO, "audioio"},
98 {0, ""}
101 /* list of available drivers */
102 static AUDIO_DRIVER * loadedAudioDrv;
104 /* local copy of registry setting */
105 static char curAudioDriver[1024];
107 /* driver index to configure */
108 static int toConfigure;
110 /* display a driver specific configuration dialog */
111 static void configureAudioDriver(HWND hDlg)
113 const AUDIO_DRIVER *pAudioDrv = &loadedAudioDrv[toConfigure];
115 if (strlen(pAudioDrv->szDriver) != 0)
117 HDRVR hdrvr;
118 char wine_driver[MAX_NAME_LENGTH + 9];
119 sprintf(wine_driver, "wine%s.drv", pAudioDrv->szDriver);
120 hdrvr = OpenDriverA(wine_driver, 0, 0);
121 if (hdrvr != 0)
123 if (SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
125 DRVCONFIGINFO dci;
126 LONG lRes;
127 dci.dwDCISize = sizeof (dci);
128 dci.lpszDCISectionName = NULL;
129 dci.lpszDCIAliasName = NULL;
130 lRes = SendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LONG_PTR)&dci);
132 CloseDriver(hdrvr, 0, 0);
134 else
136 WCHAR wine_driverW[MAX_NAME_LENGTH+9];
137 WCHAR messageStr[256];
138 WCHAR str[1024];
140 MultiByteToWideChar (CP_ACP, 0, wine_driver, -1, wine_driverW,
141 sizeof (wine_driverW)/sizeof(wine_driverW[0]));
143 LoadStringW (GetModuleHandle (NULL), IDS_OPEN_DRIVER_ERROR, messageStr,
144 sizeof(messageStr)/sizeof(messageStr[0]));
145 wsprintfW (str, messageStr, wine_driverW);
146 MessageBoxW (hDlg, str, NULL, MB_OK | MB_ICONERROR);
151 /* is driver in local copy of driver registry string */
152 static BOOL isDriverSet(const char * driver)
154 WINE_TRACE("driver = %s, curAudioDriver = %s\n", driver, curAudioDriver);
156 if (strstr(curAudioDriver, driver))
157 return TRUE;
159 return FALSE;
162 /* add driver to local copy of driver registry string */
163 static void addDriver(const char * driver)
165 if (!isDriverSet(driver))
167 if (strlen(curAudioDriver))
168 strcat(curAudioDriver, ",");
169 strcat(curAudioDriver, driver);
173 /* remove driver from local copy of driver registry string */
174 static void removeDriver(const char * driver)
176 char before[32], after[32], * start;
178 strcpy(before, ",");
179 strcat(before, driver);
180 strcpy(after, driver);
181 strcat(after, ",");
183 if ((start = strstr(curAudioDriver, after)))
185 int len = strlen(after);
186 char * end = curAudioDriver + strlen(curAudioDriver);
187 int i, count = end - start + len;
188 for (i = 0; i < count; i++)
190 if (start + len >= end)
191 *start = 0;
192 else
193 *start = start[len];
194 start++;
197 else if ((start = strstr(curAudioDriver, before)))
199 int len = strlen(before);
200 char * end = curAudioDriver + strlen(curAudioDriver);
201 int i, count = end - start + len;
202 for (i = 0; i < count; i++)
204 if (start + len >= end)
205 *start = 0;
206 else
207 *start = start[len];
208 start++;
211 else if (strcmp(curAudioDriver, driver) == 0)
213 strcpy(curAudioDriver, "");
217 static void initAudioDeviceTree(HWND hDlg)
219 const AUDIO_DRIVER *pAudioDrv = NULL;
220 int i, j;
221 TVINSERTSTRUCTW insert;
222 HTREEITEM root, driver[10];
223 HWND tree = NULL;
224 HIMAGELIST hImageList;
225 HBITMAP hBitMap;
226 HCURSOR old_cursor;
227 WCHAR driver_type[64], dev_type[64];
229 tree = GetDlgItem(hDlg, IDC_AUDIO_TREE);
231 if (!tree)
232 return;
234 /* set tree view style */
235 SetWindowLong(tree, GWL_STYLE, GetWindowLong(tree, GWL_STYLE) | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
237 /* state checkbox */
238 hImageList = ImageList_Create(16, 16, FALSE, 3, 0);
239 hBitMap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_CHECKBOX));
240 ImageList_Add(hImageList, hBitMap, NULL);
241 DeleteObject(hBitMap);
242 SendMessageW( tree, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)hImageList );
244 /* root item */
245 LoadStringW (GetModuleHandle (NULL), IDS_SOUNDDRIVERS, driver_type,
246 sizeof(driver_type)/sizeof(driver_type[0]));
247 insert.hParent = TVI_ROOT;
248 insert.hInsertAfter = TVI_LAST;
249 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
250 insert.u.item.pszText = driver_type;
251 insert.u.item.cChildren = 1;
252 root = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
254 /* change to the wait cursor because this can take a while if there is a
255 * misbehaving driver that takes a long time to open
257 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
259 /* iterate over list of loaded drivers */
260 for (pAudioDrv = loadedAudioDrv, i = 0; pAudioDrv->nameID; i++, pAudioDrv++) {
261 HDRVR hdrv;
262 char name[MAX_PATH];
263 WCHAR text[MAX_PATH];
265 sprintf(name, "wine%s.drv", pAudioDrv->szDriver);
266 LoadStringW (GetModuleHandle (NULL), pAudioDrv->nameID, text,
267 sizeof(text)/sizeof(text[0]));
269 if ((hdrv = OpenDriverA(name, 0, 0)))
271 HMODULE lib;
272 if ((lib = GetDriverModuleHandle(hdrv)))
274 int num_wod = 0, num_wid = 0, num_mod = 0, num_mid = 0, num_aux = 0, num_mxd = 0;
275 MessagePtr wodMessagePtr = (MessagePtr)GetProcAddress(lib, "wodMessage");
276 MessagePtr widMessagePtr = (MessagePtr)GetProcAddress(lib, "widMessage");
277 MessagePtr modMessagePtr = (MessagePtr)GetProcAddress(lib, "modMessage");
278 MessagePtr midMessagePtr = (MessagePtr)GetProcAddress(lib, "midMessage");
279 MessagePtr auxMessagePtr = (MessagePtr)GetProcAddress(lib, "auxMessage");
280 MessagePtr mxdMessagePtr = (MessagePtr)GetProcAddress(lib, "mxdMessage");
282 if (wodMessagePtr)
283 num_wod = wodMessagePtr(0, WODM_GETNUMDEVS, 0, 0, 0);
285 if (widMessagePtr)
286 num_wid = widMessagePtr(0, WIDM_GETNUMDEVS, 0, 0, 0);
288 if (modMessagePtr)
289 num_mod = modMessagePtr(0, MODM_GETNUMDEVS, 0, 0, 0);
291 if (midMessagePtr)
292 num_mid = midMessagePtr(0, MIDM_GETNUMDEVS, 0, 0, 0);
294 if (auxMessagePtr)
295 num_aux = auxMessagePtr(0, AUXDM_GETNUMDEVS, 0, 0, 0);
297 if (mxdMessagePtr)
298 num_mxd = mxdMessagePtr(0, MXDM_GETNUMDEVS, 0, 0, 0);
300 if (num_wod == 0 && num_wid == 0 && num_mod == 0 && num_mid == 0 && num_aux == 0 && num_mxd == 0)
302 insert.hParent = root;
303 insert.u.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
304 insert.u.item.pszText = text;
305 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
306 insert.u.item.lParam = i + DRIVER_MASK;
308 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
310 else
312 HTREEITEM type;
314 insert.hParent = root;
315 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN | TVIF_STATE | TVIF_PARAM;
316 insert.u.item.pszText = text;
317 insert.u.item.cChildren = 1;
318 insert.u.item.stateMask = TVIS_STATEIMAGEMASK;
319 insert.u.item.lParam = i + DRIVER_MASK;
321 if (isDriverSet(pAudioDrv->szDriver))
322 insert.u.item.state = INDEXTOSTATEIMAGEMASK(2);
323 else
324 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
326 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
328 if (num_wod)
330 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_WAVEOUT, dev_type,
331 sizeof(dev_type)/sizeof(dev_type[0]));
333 insert.hParent = driver[i];
334 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
335 insert.u.item.pszText = dev_type;
336 insert.u.item.cChildren = 1;
338 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
340 for (j = 0; j < num_wod; j++)
342 WAVEOUTCAPSW caps;
344 wodMessagePtr(j, WODM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
346 insert.hParent = type;
347 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
348 insert.u.item.pszText = caps.szPname;
349 insert.u.item.lParam = j + DEVICE_MASK;
351 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
355 if (num_wid)
357 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_WAVEIN, dev_type,
358 sizeof(dev_type)/sizeof(dev_type[0]));
360 insert.hParent = driver[i];
361 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
362 insert.u.item.pszText = dev_type;
363 insert.u.item.cChildren = 1;
365 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
367 for (j = 0; j < num_wid; j++)
369 WAVEINCAPSW caps;
371 widMessagePtr(j, WIDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
373 insert.hParent = type;
374 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
375 insert.u.item.pszText = caps.szPname;
376 insert.u.item.lParam = j + DEVICE_MASK;
378 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
382 if (num_mod)
384 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIDIOUT, dev_type,
385 sizeof(dev_type)/sizeof(dev_type[0]));
387 insert.hParent = driver[i];
388 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
389 insert.u.item.pszText = dev_type;
390 insert.u.item.cChildren = 1;
392 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
394 for (j = 0; j < num_mod; j++)
396 MIDIOUTCAPSW caps;
398 modMessagePtr(j, MODM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
400 insert.hParent = type;
401 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
402 insert.u.item.pszText = caps.szPname;
403 insert.u.item.lParam = j + DEVICE_MASK;
405 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
409 if (num_mid)
411 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIDIIN, dev_type,
412 sizeof(dev_type)/sizeof(dev_type[0]));
414 insert.hParent = driver[i];
415 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
416 insert.u.item.pszText = dev_type;
417 insert.u.item.cChildren = 1;
419 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
421 for (j = 0; j < num_mid; j++)
423 MIDIINCAPSW caps;
425 midMessagePtr(j, MIDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
427 insert.hParent = type;
428 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
429 insert.u.item.pszText = caps.szPname;
430 insert.u.item.lParam = j + DEVICE_MASK;
432 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
436 if (num_aux)
438 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_AUX, dev_type,
439 sizeof(dev_type)/sizeof(dev_type[0]));
441 insert.hParent = driver[i];
442 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
443 insert.u.item.pszText = dev_type;
444 insert.u.item.cChildren = 1;
446 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
448 for (j = 0; j < num_aux; j++)
450 AUXCAPSW caps;
452 auxMessagePtr(j, AUXDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
454 insert.hParent = type;
455 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
456 insert.u.item.pszText = caps.szPname;
457 insert.u.item.lParam = j + DEVICE_MASK;
459 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
463 if (num_mxd)
465 LoadStringW (GetModuleHandle (NULL), IDS_DEVICES_MIXER, dev_type,
466 sizeof(dev_type)/sizeof(dev_type[0]));
468 insert.hParent = driver[i];
469 insert.u.item.mask = TVIF_TEXT | TVIF_CHILDREN;
470 insert.u.item.pszText = dev_type;
471 insert.u.item.cChildren = 1;
473 type = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
475 for (j = 0; j < num_mxd; j++)
477 MIXERCAPSW caps;
479 mxdMessagePtr(j, MXDM_GETDEVCAPS, 0, (DWORD_PTR)&caps, sizeof(caps));
481 insert.hParent = type;
482 insert.u.item.mask = TVIF_TEXT | TVIF_PARAM;
483 insert.u.item.pszText = caps.szPname;
484 insert.u.item.lParam = j + DEVICE_MASK;
486 SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
491 CloseDriver(hdrv, 0, 0);
495 /* restore the original cursor */
496 SetCursor(old_cursor);
498 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_SELECTITEM, 0, 0);
499 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)root);
500 for (j = 0; j < i; j++)
501 SendDlgItemMessage(hDlg, IDC_AUDIO_TREE, TVM_EXPAND, TVE_EXPAND, (LPARAM)driver[j]);
504 /* find all drivers that can be loaded */
505 static void findAudioDrivers(void)
507 int numFound = 0;
508 const AUDIO_DRIVER *pAudioDrv = NULL;
509 HCURSOR old_cursor;
511 /* delete an existing list */
512 HeapFree(GetProcessHeap(), 0, loadedAudioDrv);
513 loadedAudioDrv = 0;
515 /* change to the wait cursor because this can take a while if there is a
516 * misbehaving driver that takes a long time to open
518 old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
520 for (pAudioDrv = sAudioDrivers; pAudioDrv->nameID; pAudioDrv++)
522 if (strlen(pAudioDrv->szDriver))
524 HDRVR hdrv;
525 char driver[MAX_PATH];
527 sprintf(driver, "wine%s.drv", pAudioDrv->szDriver);
529 if ((hdrv = OpenDriverA(driver, 0, 0)))
531 CloseDriver(hdrv, 0, 0);
533 if (loadedAudioDrv)
534 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
535 else
536 loadedAudioDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER));
538 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
539 numFound++;
544 /* restore the original cursor */
545 SetCursor(old_cursor);
547 /* terminate list with empty driver */
548 if (numFound) {
549 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
550 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
551 } else
552 loadedAudioDrv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(AUDIO_DRIVER));
555 /* check local copy of registry string for unloadable drivers */
556 static void checkRegistrySetting(HWND hDlg)
558 const AUDIO_DRIVER *pAudioDrv;
559 char * token, * tokens = strdup(curAudioDriver);
561 start_over:
562 token = strtok(tokens, ",");
563 while (token != NULL)
565 BOOL found = FALSE;
566 for (pAudioDrv = loadedAudioDrv; pAudioDrv->nameID; pAudioDrv++)
568 if (strcmp(token, pAudioDrv->szDriver) == 0)
570 found = TRUE;
571 break;
574 if (found == FALSE)
576 WCHAR tokenW[MAX_NAME_LENGTH+1];
577 WCHAR messageStr[256];
578 WCHAR str[1024];
579 WCHAR caption[64];
581 MultiByteToWideChar (CP_ACP, 0, token, -1, tokenW, sizeof(tokenW)/sizeof(tokenW[0]));
583 LoadStringW (GetModuleHandle (NULL), IDS_UNAVAILABLE_DRIVER, messageStr,
584 sizeof(messageStr)/sizeof(messageStr[0]));
585 wsprintfW (str, messageStr, tokenW);
586 LoadStringW (GetModuleHandle (NULL), IDS_WARNING, caption,
587 sizeof(caption)/sizeof(caption[0]));
588 if (MessageBoxW (hDlg, str, caption, MB_ICONWARNING | MB_YESNOCANCEL) == IDYES)
590 removeDriver(token);
591 strcpy(tokens, curAudioDriver);
592 goto start_over;
595 token = strtok(NULL, ",");
597 free(tokens);
600 static void selectDriver(HWND hDlg, const char * driver)
602 WCHAR text[1024];
603 WCHAR caption[64];
605 strcpy(curAudioDriver, driver);
606 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
608 if (LoadStringW(GetModuleHandle(NULL), IDS_AUDIO_MISSING, text, sizeof(text)/sizeof(text[0])))
610 if (LoadStringW(GetModuleHandle(NULL), IDS_WINECFG_TITLE, caption, sizeof(caption)/sizeof(caption[0])))
611 MessageBoxW(hDlg, text, caption, MB_OK | MB_ICONINFORMATION);
614 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
617 static void initAudioDlg (HWND hDlg)
619 int i;
620 char* buf = NULL;
622 WINE_TRACE("\n");
624 /* make a list of all drivers that can be loaded */
625 findAudioDrivers();
627 /* get current registry setting if available */
628 buf = get_reg_key(config_key, "Drivers", "Audio", NULL);
630 /* check for first time install and set a default driver
631 * select first available driver, and if that fails: none
633 if (buf == NULL)
635 /* select first available driver */
636 if (*loadedAudioDrv->szDriver)
637 selectDriver(hDlg, loadedAudioDrv->szDriver);
639 else /* make a local copy of the current registry setting */
640 strcpy(curAudioDriver, buf);
642 WINE_TRACE("curAudioDriver = %s\n", curAudioDriver);
644 /* check for drivers that can't be loaded */
645 checkRegistrySetting(hDlg);
647 initAudioDeviceTree(hDlg);
649 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_RESETCONTENT, 0, 0);
650 for (i = 0; 0 != DSound_HW_Accels[i].displayID; ++i) {
651 WCHAR accelStr[64];
652 LoadStringW (GetModuleHandle (NULL), DSound_HW_Accels[i].displayID, accelStr,
653 sizeof(accelStr)/sizeof(accelStr[0]));
654 SendDlgItemMessageW (hDlg, IDC_DSOUND_HW_ACCEL, CB_ADDSTRING, 0, (LPARAM)accelStr);
656 buf = get_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration", "Full");
657 for (i = 0; NULL != DSound_HW_Accels[i].settingStr; ++i) {
658 if (strcmp(buf, DSound_HW_Accels[i].settingStr) == 0) {
659 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_SETCURSEL, i, 0);
660 break ;
663 if (NULL == DSound_HW_Accels[i].settingStr) {
664 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf);
666 HeapFree(GetProcessHeap(), 0, buf);
668 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_RESETCONTENT, 0, 0);
669 for (i = 0; NULL != DSound_Rates[i]; ++i) {
670 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_ADDSTRING, 0, (LPARAM) DSound_Rates[i]);
672 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", "44100");
673 for (i = 0; NULL != DSound_Rates[i]; ++i) {
674 if (strcmp(buf, DSound_Rates[i]) == 0) {
675 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_SETCURSEL, i, 0);
676 break ;
680 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_RESETCONTENT, 0, 0);
681 for (i = 0; NULL != DSound_Bits[i]; ++i) {
682 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_ADDSTRING, 0, (LPARAM) DSound_Bits[i]);
684 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", "16");
685 for (i = 0; NULL != DSound_Bits[i]; ++i) {
686 if (strcmp(buf, DSound_Bits[i]) == 0) {
687 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_SETCURSEL, i, 0);
688 break ;
692 buf = get_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "N");
693 if (IS_OPTION_TRUE(*buf))
694 CheckDlgButton(hDlg, IDC_DSOUND_DRV_EMUL, BST_CHECKED);
695 else
696 CheckDlgButton(hDlg, IDC_DSOUND_DRV_EMUL, BST_UNCHECKED);
697 HeapFree(GetProcessHeap(), 0, buf);
700 INT_PTR CALLBACK
701 AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
703 switch (uMsg) {
704 case WM_COMMAND:
705 switch (LOWORD(wParam)) {
706 case IDC_AUDIO_CONFIGURE:
707 configureAudioDriver(hDlg);
708 break;
709 case IDC_AUDIO_TEST:
710 if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND), NULL, SND_RESOURCE | SND_SYNC))
711 MessageBox(NULL, "Audio test failed!", "Error", MB_OK | MB_ICONERROR);
712 break;
713 case IDC_AUDIO_CONTROL_PANEL:
714 MessageBox(NULL, "Launching audio control panel not implemented yet!", "Fixme", MB_OK | MB_ICONERROR);
715 break;
716 case IDC_DSOUND_HW_ACCEL:
717 if (HIWORD(wParam) == CBN_SELCHANGE) {
718 int selected_dsound_accel;
719 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
720 selected_dsound_accel = SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_GETCURSEL, 0, 0);
721 set_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration",
722 DSound_HW_Accels[selected_dsound_accel].settingStr);
724 break;
725 case IDC_DSOUND_RATES:
726 if (HIWORD(wParam) == CBN_SELCHANGE) {
727 int selected_dsound_rate;
728 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
729 selected_dsound_rate = SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_GETCURSEL, 0, 0);
730 set_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", DSound_Rates[selected_dsound_rate]);
732 break;
733 case IDC_DSOUND_BITS:
734 if (HIWORD(wParam) == CBN_SELCHANGE) {
735 int selected_dsound_bits;
736 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
737 selected_dsound_bits = SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_GETCURSEL, 0, 0);
738 set_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", DSound_Bits[selected_dsound_bits]);
740 break;
741 case IDC_DSOUND_DRV_EMUL:
742 if (HIWORD(wParam) == BN_CLICKED) {
743 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
744 if (IsDlgButtonChecked(hDlg, IDC_DSOUND_DRV_EMUL) == BST_CHECKED)
745 set_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "Y");
746 else
747 set_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "N");
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;