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
27 #include "wine/port.h"
35 #include <wine/debug.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_PTR
, DWORD_PTR
, DWORD_PTR
);
56 static struct DSOUNDACCEL
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"},
69 static const char* DSound_Rates
[] = {
79 static const char* DSound_Bits
[] = {
92 static AUDIO_DRIVER sAudioDrivers
[] = {
93 {IDS_DRIVER_ALSA
, "alsa"},
94 {IDS_DRIVER_OSS
, "oss"},
95 {IDS_DRIVER_COREAUDIO
, "coreaudio"},
99 /* list of available drivers */
100 static AUDIO_DRIVER
* loadedAudioDrv
;
102 /* local copy of registry setting */
103 static char curAudioDriver
[1024];
105 /* driver index to configure */
106 static int toConfigure
;
108 /* display a driver specific configuration dialog */
109 static void configureAudioDriver(HWND hDlg
)
111 const AUDIO_DRIVER
*pAudioDrv
= &loadedAudioDrv
[toConfigure
];
113 if (strlen(pAudioDrv
->szDriver
) != 0)
116 char wine_driver
[MAX_NAME_LENGTH
+ 9];
117 sprintf(wine_driver
, "wine%s.drv", pAudioDrv
->szDriver
);
118 hdrvr
= pAudioDrv
->hDriver
;
121 if (SendDriverMessage(hdrvr
, DRV_QUERYCONFIGURE
, 0, 0) != 0)
124 dci
.dwDCISize
= sizeof (dci
);
125 dci
.lpszDCISectionName
= NULL
;
126 dci
.lpszDCIAliasName
= NULL
;
127 SendDriverMessage(hdrvr
, DRV_CONFIGURE
, 0, (LONG_PTR
)&dci
);
132 WCHAR wine_driverW
[MAX_NAME_LENGTH
+9];
133 WCHAR messageStr
[256];
136 MultiByteToWideChar (CP_ACP
, 0, wine_driver
, -1, wine_driverW
,
137 sizeof (wine_driverW
)/sizeof(wine_driverW
[0]));
139 LoadStringW (GetModuleHandle (NULL
), IDS_OPEN_DRIVER_ERROR
, messageStr
,
140 sizeof(messageStr
)/sizeof(messageStr
[0]));
141 wsprintfW (str
, messageStr
, wine_driverW
);
142 MessageBoxW (hDlg
, str
, NULL
, MB_OK
| MB_ICONERROR
);
147 /* is driver in local copy of driver registry string */
148 static BOOL
isDriverSet(const char * driver
)
150 WINE_TRACE("driver = %s, curAudioDriver = %s\n", driver
, curAudioDriver
);
152 if (strstr(curAudioDriver
, driver
))
158 /* add driver to local copy of driver registry string */
159 static void addDriver(const char * driver
)
161 if (!isDriverSet(driver
))
163 if (strlen(curAudioDriver
))
164 strcat(curAudioDriver
, ",");
165 strcat(curAudioDriver
, driver
);
169 /* remove driver from local copy of driver registry string */
170 static void removeDriver(const char * driver
)
172 char pattern
[32], *p
;
175 strcpy(pattern
, ",");
176 strcat(pattern
, driver
);
177 strcat(pattern
, ",");
178 drvlen
= strlen(driver
);
179 listlen
= strlen(curAudioDriver
);
181 p
= strstr(curAudioDriver
, pattern
);
182 if (p
) /* somewhere in the middle */
183 memmove(p
, p
+drvlen
+1, strlen(p
+drvlen
+1)+1);
184 else if (!strncmp(curAudioDriver
, pattern
+1, drvlen
+1)) /* the head */
185 memmove(curAudioDriver
, curAudioDriver
+drvlen
+1, listlen
-drvlen
);
186 else if (!strncmp(curAudioDriver
+listlen
-drvlen
-1, pattern
, drvlen
+1)) /* the tail */
187 curAudioDriver
[listlen
-drvlen
-1] = 0;
188 else if (!strcmp(curAudioDriver
, driver
)) /* only one entry (head&tail) */
189 curAudioDriver
[0] = 0;
191 WINE_FIXME("driver '%s' is not in the list, please report!\n", driver
);
194 static void initAudioDeviceTree(HWND hDlg
)
196 AUDIO_DRIVER
*pAudioDrv
= NULL
;
198 TVINSERTSTRUCTW insert
;
199 HTREEITEM root
, driver
[10];
201 HIMAGELIST hImageList
;
204 WCHAR driver_type
[64], dev_type
[64];
206 tree
= GetDlgItem(hDlg
, IDC_AUDIO_TREE
);
211 /* set tree view style */
212 SetWindowLong(tree
, GWL_STYLE
, GetWindowLong(tree
, GWL_STYLE
) | TVS_HASBUTTONS
| TVS_HASLINES
| TVS_LINESATROOT
);
215 hImageList
= ImageList_Create(16, 16, FALSE
, 3, 0);
216 hBitMap
= LoadBitmap(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_CHECKBOX
));
217 ImageList_Add(hImageList
, hBitMap
, NULL
);
218 DeleteObject(hBitMap
);
219 SendMessageW( tree
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)hImageList
);
222 LoadStringW (GetModuleHandle (NULL
), IDS_SOUNDDRIVERS
, driver_type
,
223 sizeof(driver_type
)/sizeof(driver_type
[0]));
224 insert
.hParent
= TVI_ROOT
;
225 insert
.hInsertAfter
= TVI_LAST
;
226 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
227 insert
.u
.item
.pszText
= driver_type
;
228 insert
.u
.item
.cChildren
= 1;
229 root
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
231 /* change to the wait cursor because this can take a while if there is a
232 * misbehaving driver that takes a long time to open
234 old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
236 /* iterate over list of loaded drivers */
237 for (pAudioDrv
= loadedAudioDrv
, i
= 0; pAudioDrv
->nameID
; i
++, pAudioDrv
++) {
240 WCHAR text
[MAX_PATH
];
242 sprintf(name
, "wine%s.drv", pAudioDrv
->szDriver
);
243 LoadStringW (GetModuleHandle (NULL
), pAudioDrv
->nameID
, text
,
244 sizeof(text
)/sizeof(text
[0]));
246 if ((hdrv
= pAudioDrv
->hDriver
))
249 if ((lib
= GetDriverModuleHandle(hdrv
)))
251 int num_wod
= 0, num_wid
= 0, num_mod
= 0, num_mid
= 0, num_aux
= 0, num_mxd
= 0;
252 MessagePtr wodMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "wodMessage");
253 MessagePtr widMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "widMessage");
254 MessagePtr modMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "modMessage");
255 MessagePtr midMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "midMessage");
256 MessagePtr auxMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "auxMessage");
257 MessagePtr mxdMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "mxdMessage");
260 num_wod
= wodMessagePtr(0, WODM_GETNUMDEVS
, 0, 0, 0);
263 num_wid
= widMessagePtr(0, WIDM_GETNUMDEVS
, 0, 0, 0);
266 num_mod
= modMessagePtr(0, MODM_GETNUMDEVS
, 0, 0, 0);
269 num_mid
= midMessagePtr(0, MIDM_GETNUMDEVS
, 0, 0, 0);
272 num_aux
= auxMessagePtr(0, AUXDM_GETNUMDEVS
, 0, 0, 0);
275 num_mxd
= mxdMessagePtr(0, MXDM_GETNUMDEVS
, 0, 0, 0);
277 if (num_wod
== 0 && num_wid
== 0 && num_mod
== 0 && num_mid
== 0 && num_aux
== 0 && num_mxd
== 0)
279 insert
.hParent
= root
;
280 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_STATE
| TVIF_PARAM
;
281 insert
.u
.item
.pszText
= text
;
282 insert
.u
.item
.stateMask
= TVIS_STATEIMAGEMASK
;
283 insert
.u
.item
.lParam
= i
+ DRIVER_MASK
;
284 if (isDriverSet(pAudioDrv
->szDriver
))
285 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(2);
287 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(1);
289 driver
[i
] = (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
295 insert
.hParent
= root
;
296 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
| TVIF_STATE
| TVIF_PARAM
;
297 insert
.u
.item
.pszText
= text
;
298 insert
.u
.item
.cChildren
= 1;
299 insert
.u
.item
.stateMask
= TVIS_STATEIMAGEMASK
;
300 insert
.u
.item
.lParam
= i
+ DRIVER_MASK
;
302 if (isDriverSet(pAudioDrv
->szDriver
))
303 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(2);
305 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(1);
307 driver
[i
] = (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
311 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_WAVEOUT
, dev_type
,
312 sizeof(dev_type
)/sizeof(dev_type
[0]));
314 insert
.hParent
= driver
[i
];
315 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
316 insert
.u
.item
.pszText
= dev_type
;
317 insert
.u
.item
.cChildren
= 1;
319 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
321 for (j
= 0; j
< num_wod
; j
++)
325 wodMessagePtr(j
, WODM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
327 insert
.hParent
= type
;
328 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
329 insert
.u
.item
.pszText
= caps
.szPname
;
330 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
332 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
338 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_WAVEIN
, dev_type
,
339 sizeof(dev_type
)/sizeof(dev_type
[0]));
341 insert
.hParent
= driver
[i
];
342 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
343 insert
.u
.item
.pszText
= dev_type
;
344 insert
.u
.item
.cChildren
= 1;
346 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
348 for (j
= 0; j
< num_wid
; j
++)
352 widMessagePtr(j
, WIDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
354 insert
.hParent
= type
;
355 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
356 insert
.u
.item
.pszText
= caps
.szPname
;
357 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
359 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
365 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIDIOUT
, dev_type
,
366 sizeof(dev_type
)/sizeof(dev_type
[0]));
368 insert
.hParent
= driver
[i
];
369 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
370 insert
.u
.item
.pszText
= dev_type
;
371 insert
.u
.item
.cChildren
= 1;
373 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
375 for (j
= 0; j
< num_mod
; j
++)
379 modMessagePtr(j
, MODM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
381 insert
.hParent
= type
;
382 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
383 insert
.u
.item
.pszText
= caps
.szPname
;
384 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
386 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
392 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIDIIN
, dev_type
,
393 sizeof(dev_type
)/sizeof(dev_type
[0]));
395 insert
.hParent
= driver
[i
];
396 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
397 insert
.u
.item
.pszText
= dev_type
;
398 insert
.u
.item
.cChildren
= 1;
400 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
402 for (j
= 0; j
< num_mid
; j
++)
406 midMessagePtr(j
, MIDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
408 insert
.hParent
= type
;
409 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
410 insert
.u
.item
.pszText
= caps
.szPname
;
411 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
413 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
419 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_AUX
, dev_type
,
420 sizeof(dev_type
)/sizeof(dev_type
[0]));
422 insert
.hParent
= driver
[i
];
423 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
424 insert
.u
.item
.pszText
= dev_type
;
425 insert
.u
.item
.cChildren
= 1;
427 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
429 for (j
= 0; j
< num_aux
; j
++)
433 auxMessagePtr(j
, AUXDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
435 insert
.hParent
= type
;
436 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
437 insert
.u
.item
.pszText
= caps
.szPname
;
438 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
440 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
446 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIXER
, dev_type
,
447 sizeof(dev_type
)/sizeof(dev_type
[0]));
449 insert
.hParent
= driver
[i
];
450 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
451 insert
.u
.item
.pszText
= dev_type
;
452 insert
.u
.item
.cChildren
= 1;
454 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
456 for (j
= 0; j
< num_mxd
; j
++)
460 mxdMessagePtr(j
, MXDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
462 insert
.hParent
= type
;
463 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
464 insert
.u
.item
.pszText
= caps
.szPname
;
465 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
467 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
475 /* restore the original cursor */
476 SetCursor(old_cursor
);
478 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_SELECTITEM
, 0, 0);
479 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)root
);
480 for (j
= 0; j
< i
; j
++)
481 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)driver
[j
]);
484 /* find all drivers that can be loaded */
485 static void findAudioDrivers(void)
488 AUDIO_DRIVER
*pAudioDrv
= NULL
;
491 /* delete an existing list */
492 HeapFree(GetProcessHeap(), 0, loadedAudioDrv
);
495 /* change to the wait cursor because this can take a while if there is a
496 * misbehaving driver that takes a long time to open
498 old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
500 for (pAudioDrv
= sAudioDrivers
; pAudioDrv
->nameID
; pAudioDrv
++)
502 if (strlen(pAudioDrv
->szDriver
))
505 char driver
[MAX_PATH
];
507 sprintf(driver
, "wine%s.drv", pAudioDrv
->szDriver
);
509 hdrv
= pAudioDrv
->hDriver
;
510 if (!pAudioDrv
->hDriver
&& (hdrv
= OpenDriverA(driver
, 0, 0))) {
511 HMODULE lib
= GetDriverModuleHandle(hdrv
);
512 MessagePtr wodMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "wodMessage");
513 MessagePtr widMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "widMessage");
514 MessagePtr modMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "modMessage");
515 MessagePtr midMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "midMessage");
516 MessagePtr auxMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "auxMessage");
517 MessagePtr mxdMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "mxdMessage");
519 pAudioDrv
->hDriver
= hdrv
;
522 wodMessagePtr(0, DRVM_INIT
, 0, 0, 0);
525 widMessagePtr(0, DRVM_INIT
, 0, 0, 0);
528 modMessagePtr(0, DRVM_INIT
, 0, 0, 0);
531 midMessagePtr(0, DRVM_INIT
, 0, 0, 0);
534 auxMessagePtr(0, DRVM_INIT
, 0, 0, 0);
537 mxdMessagePtr(0, DRVM_INIT
, 0, 0, 0);
542 loadedAudioDrv
= HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv
, (numFound
+ 1) * sizeof(AUDIO_DRIVER
));
544 loadedAudioDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER
));
546 CopyMemory(&loadedAudioDrv
[numFound
], pAudioDrv
, sizeof(AUDIO_DRIVER
));
552 /* restore the original cursor */
553 SetCursor(old_cursor
);
555 /* terminate list with empty driver */
557 loadedAudioDrv
= HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv
, (numFound
+ 1) * sizeof(AUDIO_DRIVER
));
558 CopyMemory(&loadedAudioDrv
[numFound
], pAudioDrv
, sizeof(AUDIO_DRIVER
));
560 loadedAudioDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER
));
561 CopyMemory(&loadedAudioDrv
[0], pAudioDrv
, sizeof(AUDIO_DRIVER
));
565 /* check local copy of registry string for unloadable drivers */
566 static void checkRegistrySetting(HWND hDlg
)
568 const AUDIO_DRIVER
*pAudioDrv
;
569 char * token
, * tokens
;
571 tokens
= HeapAlloc(GetProcessHeap(), 0, strlen(curAudioDriver
)+1);
572 strcpy(tokens
, curAudioDriver
);
575 token
= strtok(tokens
, ",");
576 while (token
!= NULL
)
579 for (pAudioDrv
= loadedAudioDrv
; pAudioDrv
->nameID
; pAudioDrv
++)
581 if (strcmp(token
, pAudioDrv
->szDriver
) == 0)
589 WCHAR tokenW
[MAX_NAME_LENGTH
+1];
590 WCHAR messageStr
[256];
594 MultiByteToWideChar (CP_ACP
, 0, token
, -1, tokenW
, sizeof(tokenW
)/sizeof(tokenW
[0]));
596 LoadStringW (GetModuleHandle (NULL
), IDS_UNAVAILABLE_DRIVER
, messageStr
,
597 sizeof(messageStr
)/sizeof(messageStr
[0]));
598 wsprintfW (str
, messageStr
, tokenW
);
599 LoadStringW (GetModuleHandle (NULL
), IDS_WARNING
, caption
,
600 sizeof(caption
)/sizeof(caption
[0]));
601 if (MessageBoxW (hDlg
, str
, caption
, MB_ICONWARNING
| MB_YESNOCANCEL
) == IDYES
)
604 strcpy(tokens
, curAudioDriver
);
608 token
= strtok(NULL
, ",");
610 HeapFree(GetProcessHeap(), 0, tokens
);
613 static void selectDriver(HWND hDlg
, const char * driver
)
618 strcpy(curAudioDriver
, driver
);
619 set_reg_key(config_key
, "Drivers", "Audio", curAudioDriver
);
621 if (LoadStringW(GetModuleHandle(NULL
), IDS_AUDIO_MISSING
, text
, sizeof(text
)/sizeof(text
[0])))
623 if (LoadStringW(GetModuleHandle(NULL
), IDS_WINECFG_TITLE
, caption
, sizeof(caption
)/sizeof(caption
[0])))
624 MessageBoxW(hDlg
, text
, caption
, MB_OK
| MB_ICONINFORMATION
);
627 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
630 static void initAudioDlg (HWND hDlg
)
637 /* make a list of all drivers that can be loaded */
640 /* get current registry setting if available */
641 buf
= get_reg_key(config_key
, "Drivers", "Audio", NULL
);
643 /* check for first time install and set a default driver
644 * select first available driver, and if that fails: none
648 /* select first available driver */
649 if (*loadedAudioDrv
->szDriver
)
650 selectDriver(hDlg
, loadedAudioDrv
->szDriver
);
652 else /* make a local copy of the current registry setting */
653 strcpy(curAudioDriver
, buf
);
655 WINE_TRACE("curAudioDriver = %s\n", curAudioDriver
);
657 /* check for drivers that can't be loaded */
658 checkRegistrySetting(hDlg
);
660 initAudioDeviceTree(hDlg
);
662 SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_RESETCONTENT
, 0, 0);
663 buf
= get_reg_key(config_key
, keypath("DirectSound"), "HardwareAcceleration", "Full");
666 for (i
= 0; 0 != DSound_HW_Accels
[i
].displayID
; ++i
) {
670 match
= (strcmp(buf
, DSound_HW_Accels
[i
].settingStr
) == 0);
673 DSound_HW_Accels
[i
].visible
= 1;
677 if (DSound_HW_Accels
[i
].visible
)
679 LoadStringW (GetModuleHandle (NULL
), DSound_HW_Accels
[i
].displayID
,
680 accelStr
, sizeof(accelStr
)/sizeof(accelStr
[0]));
681 SendDlgItemMessageW (hDlg
, IDC_DSOUND_HW_ACCEL
, CB_ADDSTRING
, 0, (LPARAM
)accelStr
);
683 SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_SETCURSEL
, j
, 0);
688 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf
);
690 HeapFree(GetProcessHeap(), 0, buf
);
692 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_RESETCONTENT
, 0, 0);
693 for (i
= 0; NULL
!= DSound_Rates
[i
]; ++i
) {
694 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_ADDSTRING
, 0, (LPARAM
) DSound_Rates
[i
]);
696 buf
= get_reg_key(config_key
, keypath("DirectSound"), "DefaultSampleRate", "44100");
697 for (i
= 0; NULL
!= DSound_Rates
[i
]; ++i
) {
698 if (strcmp(buf
, DSound_Rates
[i
]) == 0) {
699 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_SETCURSEL
, i
, 0);
704 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_RESETCONTENT
, 0, 0);
705 for (i
= 0; NULL
!= DSound_Bits
[i
]; ++i
) {
706 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_ADDSTRING
, 0, (LPARAM
) DSound_Bits
[i
]);
708 buf
= get_reg_key(config_key
, keypath("DirectSound"), "DefaultBitsPerSample", "16");
709 for (i
= 0; NULL
!= DSound_Bits
[i
]; ++i
) {
710 if (strcmp(buf
, DSound_Bits
[i
]) == 0) {
711 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_SETCURSEL
, i
, 0);
715 HeapFree(GetProcessHeap(), 0, buf
);
719 AudioDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
723 switch (LOWORD(wParam
)) {
724 case IDC_AUDIO_CONFIGURE
:
725 configureAudioDriver(hDlg
);
728 if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND
), NULL
, SND_RESOURCE
| SND_SYNC
))
729 MessageBox(NULL
, "Audio test failed!", "Error", MB_OK
| MB_ICONERROR
);
731 case IDC_AUDIO_CONTROL_PANEL
:
732 MessageBox(NULL
, "Launching audio control panel not implemented yet!", "Fixme", MB_OK
| MB_ICONERROR
);
734 case IDC_DSOUND_HW_ACCEL
:
735 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
736 int selected_dsound_accel
;
739 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
740 selected_dsound_accel
= SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_GETCURSEL
, 0, 0);
741 for (i
= 0; DSound_HW_Accels
[i
].settingStr
; ++i
)
743 if (DSound_HW_Accels
[i
].visible
)
745 if (j
== selected_dsound_accel
)
747 set_reg_key(config_key
, keypath("DirectSound"), "HardwareAcceleration",
748 DSound_HW_Accels
[i
].settingStr
);
756 case IDC_DSOUND_RATES
:
757 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
758 int selected_dsound_rate
;
759 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
760 selected_dsound_rate
= SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_GETCURSEL
, 0, 0);
761 set_reg_key(config_key
, keypath("DirectSound"), "DefaultSampleRate", DSound_Rates
[selected_dsound_rate
]);
764 case IDC_DSOUND_BITS
:
765 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
766 int selected_dsound_bits
;
767 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
768 selected_dsound_bits
= SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_GETCURSEL
, 0, 0);
769 set_reg_key(config_key
, keypath("DirectSound"), "DefaultBitsPerSample", DSound_Bits
[selected_dsound_bits
]);
776 set_window_title(hDlg
);
780 switch(((LPNMHDR
)lParam
)->code
) {
782 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, FALSE
);
785 set_reg_key(config_key
, "Drivers", "Audio", curAudioDriver
);
787 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
792 if (((LPNMHDR
)lParam
)->idFrom
== IDC_AUDIO_TREE
)
795 DWORD dwPos
= GetMessagePos();
796 HWND tree
= ((LPNMHDR
)lParam
)->hwndFrom
;
797 ZeroMemory(&ht
, sizeof(ht
));
798 ht
.pt
.x
= (short)LOWORD(dwPos
);
799 ht
.pt
.y
= (short)HIWORD(dwPos
);
800 MapWindowPoints(HWND_DESKTOP
, tree
, &ht
.pt
, 1);
801 SendMessageW( tree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
802 if (TVHT_ONITEMSTATEICON
& ht
.flags
)
806 ZeroMemory(&tvItem
, sizeof(tvItem
));
807 tvItem
.hItem
= ht
.hItem
;
808 SendMessageW( tree
, TVM_GETITEMW
, 0, (LPARAM
) &tvItem
);
810 index
= TreeView_GetItemState(tree
, ht
.hItem
, TVIS_STATEIMAGEMASK
);
811 if (index
== INDEXTOSTATEIMAGEMASK(1))
813 TreeView_SetItemState(tree
, ht
.hItem
, INDEXTOSTATEIMAGEMASK(2), TVIS_STATEIMAGEMASK
);
814 addDriver(loadedAudioDrv
[tvItem
.lParam
& 0xff].szDriver
);
815 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
817 else if (index
== INDEXTOSTATEIMAGEMASK(2))
819 TreeView_SetItemState(tree
, ht
.hItem
, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK
);
820 removeDriver(loadedAudioDrv
[tvItem
.lParam
& 0xff].szDriver
);
821 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
827 if (((LPNMHDR
)lParam
)->idFrom
== IDC_AUDIO_TREE
)
830 DWORD dwPos
= GetMessagePos();
831 HWND tree
= ((LPNMHDR
)lParam
)->hwndFrom
;
833 ZeroMemory(&ht
, sizeof(ht
));
834 pt
.x
= (short)LOWORD(dwPos
);
835 pt
.y
= (short)HIWORD(dwPos
);
837 MapWindowPoints(HWND_DESKTOP
, tree
, &ht
.pt
, 1);
838 SendMessageW( tree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
839 if (TVHT_ONITEMLABEL
& ht
.flags
)
842 ZeroMemory(&tvItem
, sizeof(tvItem
));
843 tvItem
.hItem
= ht
.hItem
;
844 tvItem
.mask
= TVIF_PARAM
;
846 if (TreeView_GetItem(tree
, &tvItem
))
848 if (tvItem
.lParam
& DRIVER_MASK
)
852 TrackPopupMenu(GetSubMenu(hPopupMenus
, 0), TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, tree
, NULL
);
853 toConfigure
= tvItem
.lParam
& ~DRIVER_MASK
;
856 else if (tvItem
.lParam
& DEVICE_MASK
)