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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
53 typedef DWORD (WINAPI
* MessagePtr
)(UINT
, UINT
, DWORD
, DWORD
, DWORD
);
55 static const char* DSound_HW_Accels
[] = {
63 static const AUDIO_DRIVER sAudioDrivers
[] = {
70 {"Audio IO(Solaris)", "audioio"},
71 {"Disable sound", ""},
75 /* list of available drivers */
76 static AUDIO_DRIVER
* loadedAudioDrv
;
78 /* local copy of registry setting */
79 static char curAudioDriver
[1024];
81 /* driver index to configure */
82 static int toConfigure
;
84 /* display a driver specific configuration dialog */
85 static void configureAudioDriver(HWND hDlg
)
87 const AUDIO_DRIVER
*pAudioDrv
= &loadedAudioDrv
[toConfigure
];
89 if (strlen(pAudioDrv
->szDriver
) != 0)
92 char wine_driver
[MAX_NAME_LENGTH
+ 8];
93 sprintf(wine_driver
, "wine%s.drv", pAudioDrv
->szDriver
);
94 hdrvr
= OpenDriverA(wine_driver
, 0, 0);
97 if (SendDriverMessage(hdrvr
, DRV_QUERYCONFIGURE
, 0, 0) != 0)
101 dci
.dwDCISize
= sizeof (dci
);
102 dci
.lpszDCISectionName
= NULL
;
103 dci
.lpszDCIAliasName
= NULL
;
104 lRes
= SendDriverMessage(hdrvr
, DRV_CONFIGURE
, 0, (LONG
)&dci
);
106 CloseDriver(hdrvr
, 0, 0);
111 sprintf(str
, "Couldn't open %s!", wine_driver
);
112 MessageBox(hDlg
, str
, "Fixme", MB_OK
| MB_ICONERROR
);
117 /* is driver in local copy of driver registry string */
118 static BOOL
isDriverSet(const char * driver
)
120 WINE_TRACE("driver = %s, curAudioDriver = %s\n", driver
, curAudioDriver
);
122 if (strstr(curAudioDriver
, driver
))
128 /* add driver to local copy of driver registry string */
129 static void addDriver(const char * driver
)
131 if (!isDriverSet(driver
))
133 if (strlen(curAudioDriver
))
134 strcat(curAudioDriver
, ",");
135 strcat(curAudioDriver
, driver
);
139 /* remove driver from local copy of driver registry string */
140 static void removeDriver(const char * driver
)
142 char before
[32], after
[32], * start
;
145 strcat(before
, driver
);
146 strcpy(after
, driver
);
149 if ((start
= strstr(curAudioDriver
, after
)))
151 int len
= strlen(after
);
152 char * end
= curAudioDriver
+ strlen(curAudioDriver
);
153 int i
, count
= end
- start
+ len
;
154 for (i
= 0; i
< count
; i
++)
156 if (start
+ len
>= end
)
163 else if ((start
= strstr(curAudioDriver
, before
)))
165 int len
= strlen(before
);
166 char * end
= curAudioDriver
+ strlen(curAudioDriver
);
167 int i
, count
= end
- start
+ len
;
168 for (i
= 0; i
< count
; i
++)
170 if (start
+ len
>= end
)
177 else if (strcmp(curAudioDriver
, driver
) == 0)
179 strcpy(curAudioDriver
, "");
183 static void initAudioDeviceTree(HWND hDlg
)
185 const AUDIO_DRIVER
*pAudioDrv
= NULL
;
187 TVINSERTSTRUCT insert
;
188 HTREEITEM root
, driver
[10];
190 HIMAGELIST hImageList
;
194 tree
= GetDlgItem(hDlg
, IDC_AUDIO_TREE
);
199 /* set tree view style */
200 SetWindowLong(tree
, GWL_STYLE
, GetWindowLong(tree
, GWL_STYLE
) | TVS_HASBUTTONS
| TVS_HASLINES
| TVS_LINESATROOT
);
203 hImageList
= ImageList_Create(16, 16, FALSE
, 3, 0);
204 hBitMap
= LoadBitmap(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_CHECKBOX
));
205 ImageList_Add(hImageList
, hBitMap
, NULL
);
206 DeleteObject(hBitMap
);
207 SendMessageW( tree
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)hImageList
);
210 insert
.hParent
= TVI_ROOT
;
211 insert
.hInsertAfter
= TVI_LAST
;
212 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
213 insert
.u
.item
.pszText
= "Sound Drivers";
214 insert
.u
.item
.cChildren
= 1;
215 root
= (HTREEITEM
)SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
217 /* change to the wait cursor because this can take a while if there is a
218 * misbehaving driver that takes a long time to open
220 old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
222 /* iterate over list of loaded drivers */
223 for (pAudioDrv
= loadedAudioDrv
, i
= 0; *pAudioDrv
->szName
; i
++, pAudioDrv
++) {
228 sprintf(name
, "wine%s.drv", pAudioDrv
->szDriver
);
229 sprintf(text
, "%s Driver", pAudioDrv
->szName
);
231 if ((hdrv
= OpenDriverA(name
, 0, 0)))
234 if ((lib
= GetDriverModuleHandle(hdrv
)))
236 int num_wod
= 0, num_wid
= 0, num_mod
= 0, num_mid
= 0, num_aux
= 0, num_mxd
= 0;
237 MessagePtr wodMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "wodMessage");
238 MessagePtr widMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "widMessage");
239 MessagePtr modMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "modMessage");
240 MessagePtr midMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "midMessage");
241 MessagePtr auxMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "auxMessage");
242 MessagePtr mxdMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "mxdMessage");
245 num_wod
= wodMessagePtr(0, WODM_GETNUMDEVS
, 0, 0, 0);
248 num_wid
= widMessagePtr(0, WIDM_GETNUMDEVS
, 0, 0, 0);
251 num_mod
= modMessagePtr(0, MODM_GETNUMDEVS
, 0, 0, 0);
254 num_mid
= midMessagePtr(0, MIDM_GETNUMDEVS
, 0, 0, 0);
257 num_aux
= auxMessagePtr(0, AUXDM_GETNUMDEVS
, 0, 0, 0);
260 num_mxd
= mxdMessagePtr(0, MXDM_GETNUMDEVS
, 0, 0, 0);
262 if (num_wod
== 0 && num_wid
== 0 && num_mod
== 0 && num_mid
== 0 && num_aux
== 0 && num_mxd
== 0)
264 insert
.hParent
= root
;
265 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_STATE
| TVIF_PARAM
;
266 insert
.u
.item
.pszText
= text
;
267 insert
.u
.item
.stateMask
= TVIS_STATEIMAGEMASK
;
268 insert
.u
.item
.lParam
= i
+ DRIVER_MASK
;
270 driver
[i
] = (HTREEITEM
)SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
276 insert
.hParent
= root
;
277 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
| TVIF_STATE
| TVIF_PARAM
;
278 insert
.u
.item
.pszText
= text
;
279 insert
.u
.item
.cChildren
= 1;
280 insert
.u
.item
.stateMask
= TVIS_STATEIMAGEMASK
;
281 insert
.u
.item
.lParam
= i
+ DRIVER_MASK
;
283 if (isDriverSet(pAudioDrv
->szDriver
))
284 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(2);
286 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(1);
288 driver
[i
] = (HTREEITEM
)SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
292 insert
.hParent
= driver
[i
];
293 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
294 insert
.u
.item
.pszText
= "Wave Out Devices";
295 insert
.u
.item
.cChildren
= 1;
297 type
= (HTREEITEM
)SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
299 for (j
= 0; j
< num_wod
; j
++)
302 char szPname
[MAXPNAMELEN
];
304 wodMessagePtr(j
, WODM_GETDEVCAPS
, 0, (DWORD
)&caps
, sizeof(caps
));
305 WideCharToMultiByte(CP_ACP
, 0, caps
.szPname
, -1, szPname
, MAXPNAMELEN
, 0, 0);
307 insert
.hParent
= type
;
308 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
309 insert
.u
.item
.pszText
= szPname
;
310 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
312 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
318 insert
.hParent
= driver
[i
];
319 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
320 insert
.u
.item
.pszText
= "Wave In Devices";
321 insert
.u
.item
.cChildren
= 1;
323 type
= (HTREEITEM
)SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
325 for (j
= 0; j
< num_wid
; j
++)
328 char szPname
[MAXPNAMELEN
];
330 widMessagePtr(j
, WIDM_GETDEVCAPS
, 0, (DWORD
)&caps
, sizeof(caps
));
331 WideCharToMultiByte(CP_ACP
, 0, caps
.szPname
, -1, szPname
, MAXPNAMELEN
, 0, 0);
333 insert
.hParent
= type
;
334 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
335 insert
.u
.item
.pszText
= szPname
;
336 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
338 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
344 insert
.hParent
= driver
[i
];
345 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
346 insert
.u
.item
.pszText
= "MIDI Out Devices";
347 insert
.u
.item
.cChildren
= 1;
349 type
= (HTREEITEM
)SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
351 for (j
= 0; j
< num_mod
; j
++)
354 char szPname
[MAXPNAMELEN
];
356 modMessagePtr(j
, MODM_GETDEVCAPS
, 0, (DWORD
)&caps
, sizeof(caps
));
357 WideCharToMultiByte(CP_ACP
, 0, caps
.szPname
, -1, szPname
, MAXPNAMELEN
, 0, 0);
359 insert
.hParent
= type
;
360 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
361 insert
.u
.item
.pszText
= szPname
;
362 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
364 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
370 insert
.hParent
= driver
[i
];
371 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
372 insert
.u
.item
.pszText
= "MIDI In Devices";
373 insert
.u
.item
.cChildren
= 1;
375 type
= (HTREEITEM
)SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
377 for (j
= 0; j
< num_mid
; j
++)
380 char szPname
[MAXPNAMELEN
];
382 midMessagePtr(j
, MIDM_GETDEVCAPS
, 0, (DWORD
)&caps
, sizeof(caps
));
383 WideCharToMultiByte(CP_ACP
, 0, caps
.szPname
, -1, szPname
, MAXPNAMELEN
, 0, 0);
385 insert
.hParent
= type
;
386 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
387 insert
.u
.item
.pszText
= szPname
;
388 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
390 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
396 insert
.hParent
= driver
[i
];
397 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
398 insert
.u
.item
.pszText
= "Aux Devices";
399 insert
.u
.item
.cChildren
= 1;
401 type
= (HTREEITEM
)SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
403 for (j
= 0; j
< num_aux
; j
++)
406 char szPname
[MAXPNAMELEN
];
408 auxMessagePtr(j
, AUXDM_GETDEVCAPS
, 0, (DWORD
)&caps
, sizeof(caps
));
409 WideCharToMultiByte(CP_ACP
, 0, caps
.szPname
, -1, szPname
, MAXPNAMELEN
, 0, 0);
411 insert
.hParent
= type
;
412 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
413 insert
.u
.item
.pszText
= szPname
;
414 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
416 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
422 insert
.hParent
= driver
[i
];
423 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
424 insert
.u
.item
.pszText
= "Mixer Devices";
425 insert
.u
.item
.cChildren
= 1;
427 type
= (HTREEITEM
)SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
429 for (j
= 0; j
< num_mxd
; j
++)
432 char szPname
[MAXPNAMELEN
];
434 mxdMessagePtr(j
, MXDM_GETDEVCAPS
, 0, (DWORD
)&caps
, sizeof(caps
));
435 WideCharToMultiByte(CP_ACP
, 0, caps
.szPname
, -1, szPname
, MAXPNAMELEN
, 0, 0);
437 insert
.hParent
= type
;
438 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
439 insert
.u
.item
.pszText
= szPname
;
440 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
442 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEM
, 0, (LPARAM
)&insert
);
450 /* restore the original cursor */
451 SetCursor(old_cursor
);
453 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_SELECTITEM
, 0, 0);
454 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)root
);
455 for (j
= 0; j
< i
; j
++)
456 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)driver
[j
]);
459 /* find all drivers that can be loaded */
460 static void findAudioDrivers(void)
463 const AUDIO_DRIVER
*pAudioDrv
= NULL
;
466 /* delete an existing list */
469 HeapFree(GetProcessHeap(), 0, loadedAudioDrv
);
473 /* change to the wait cursor because this can take a while if there is a
474 * misbehaving driver that takes a long time to open
476 old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
478 for (pAudioDrv
= sAudioDrivers
; *pAudioDrv
->szName
; pAudioDrv
++)
480 if (strlen(pAudioDrv
->szDriver
))
483 char driver
[MAX_PATH
];
485 sprintf(driver
, "wine%s.drv", pAudioDrv
->szDriver
);
487 if ((hdrv
= OpenDriverA(driver
, 0, 0)))
489 CloseDriver(hdrv
, 0, 0);
492 loadedAudioDrv
= HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv
, (numFound
+ 1) * sizeof(AUDIO_DRIVER
));
494 loadedAudioDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER
));
496 CopyMemory(&loadedAudioDrv
[numFound
], pAudioDrv
, sizeof(AUDIO_DRIVER
));
502 /* restore the original cursor */
503 SetCursor(old_cursor
);
505 /* terminate list with empty driver */
506 loadedAudioDrv
= HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv
, (numFound
+ 1) * sizeof(AUDIO_DRIVER
));
507 CopyMemory(&loadedAudioDrv
[numFound
], pAudioDrv
, sizeof(AUDIO_DRIVER
));
510 /* check local copy of registry string for unloadable drivers */
511 static void checkRegistrySetting(HWND hDlg
)
513 const AUDIO_DRIVER
*pAudioDrv
;
514 char * token
, * tokens
= strdup(curAudioDriver
);
517 token
= strtok(tokens
, ",");
518 while (token
!= NULL
)
521 for (pAudioDrv
= loadedAudioDrv
; *pAudioDrv
->szName
; pAudioDrv
++)
523 if (strcmp(token
, pAudioDrv
->szDriver
) == 0)
532 sprintf(str
, "Found driver in registry that in not available!\n\nRemove \"%s\" from registry?", token
);
533 if (MessageBox(hDlg
, str
, "WARNING", MB_ICONWARNING
| MB_YESNOCANCEL
) == IDYES
)
536 strcpy(tokens
, curAudioDriver
);
540 token
= strtok(NULL
, ",");
545 static void selectDriver(HWND hDlg
, const char * driver
)
550 strcpy(curAudioDriver
, driver
);
551 set_reg_key(config_key
, "Drivers", "Audio", curAudioDriver
);
553 if (LoadStringW(GetModuleHandle(NULL
), IDS_AUDIO_MISSING
, text
, sizeof(text
)/sizeof(text
[0])))
555 if (LoadStringW(GetModuleHandle(NULL
), IDS_WINECFG_TITLE
, caption
, sizeof(caption
)/sizeof(caption
[0])))
556 MessageBoxW(hDlg
, text
, caption
, MB_OK
| MB_ICONINFORMATION
);
559 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
562 static void initAudioDlg (HWND hDlg
)
569 /* make a list of all drivers that can be loaded */
572 /* get current registry setting if available */
573 buf
= get_reg_key(config_key
, "Drivers", "Audio", NULL
);
575 /* check for first time install and set a default driver
576 * select in this order: oss, alsa, first available driver, none
580 const AUDIO_DRIVER
*pAudioDrv
= NULL
;
582 /* select oss if available */
583 for (pAudioDrv
= loadedAudioDrv
; *pAudioDrv
->szName
; pAudioDrv
++)
585 if (strcmp(pAudioDrv
->szDriver
, "oss") == 0)
587 selectDriver(hDlg
, "oss");
592 if (strlen(curAudioDriver
) == 0)
594 /* select alsa if available */
595 for (pAudioDrv
= loadedAudioDrv
; *pAudioDrv
->szName
; pAudioDrv
++)
597 if (strcmp(pAudioDrv
->szDriver
, "alsa") == 0)
599 selectDriver(hDlg
, "alsa");
605 if (strlen(curAudioDriver
) == 0)
607 /* select first available driver */
608 if (*loadedAudioDrv
->szDriver
)
609 selectDriver(hDlg
, loadedAudioDrv
->szDriver
);
612 else /* make a local copy of the current registry setting */
613 strcpy(curAudioDriver
, buf
);
615 WINE_TRACE("curAudioDriver = %s\n", curAudioDriver
);
617 /* check for drivers that can't be loaded */
618 checkRegistrySetting(hDlg
);
620 initAudioDeviceTree(hDlg
);
622 SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_RESETCONTENT
, 0, 0);
623 for (i
= 0; NULL
!= DSound_HW_Accels
[i
]; ++i
) {
624 SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_ADDSTRING
, 0, (LPARAM
) DSound_HW_Accels
[i
]);
626 buf
= get_reg_key(config_key
, keypath("DirectSound"), "HardwareAcceleration", "Full");
627 for (i
= 0; NULL
!= DSound_HW_Accels
[i
]; ++i
) {
628 if (strcmp(buf
, DSound_HW_Accels
[i
]) == 0) {
629 SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_SETCURSEL
, i
, 0);
633 if (NULL
== DSound_HW_Accels
[i
]) {
634 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf
);
636 HeapFree(GetProcessHeap(), 0, buf
);
638 buf
= get_reg_key(config_key
, keypath("DirectSound"), "EmulDriver", "N");
639 if (IS_OPTION_TRUE(*buf
))
640 CheckDlgButton(hDlg
, IDC_DSOUND_DRV_EMUL
, BST_CHECKED
);
642 CheckDlgButton(hDlg
, IDC_DSOUND_DRV_EMUL
, BST_UNCHECKED
);
643 HeapFree(GetProcessHeap(), 0, buf
);
647 AudioDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
651 switch (LOWORD(wParam
)) {
652 case IDC_AUDIO_CONFIGURE
:
653 configureAudioDriver(hDlg
);
655 case IDC_AUDIO_CONTROL_PANEL
:
656 MessageBox(NULL
, "Launching audio control panel not implemented yet!", "Fixme", MB_OK
| MB_ICONERROR
);
658 case IDC_DSOUND_HW_ACCEL
:
659 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
660 int selected_dsound_accel
;
661 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
662 selected_dsound_accel
= SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_GETCURSEL
, 0, 0);
663 set_reg_key(config_key
, keypath("DirectSound"), "HardwareAcceleration", DSound_HW_Accels
[selected_dsound_accel
]);
666 case IDC_DSOUND_DRV_EMUL
:
667 if (HIWORD(wParam
) == BN_CLICKED
) {
668 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
669 if (IsDlgButtonChecked(hDlg
, IDC_DSOUND_DRV_EMUL
) == BST_CHECKED
)
670 set_reg_key(config_key
, keypath("DirectSound"), "EmulDriver", "Y");
672 set_reg_key(config_key
, keypath("DirectSound"), "EmulDriver", "N");
679 set_window_title(hDlg
);
683 switch(((LPNMHDR
)lParam
)->code
) {
685 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, FALSE
);
688 set_reg_key(config_key
, "Drivers", "Audio", curAudioDriver
);
690 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
695 if (((LPNMHDR
)lParam
)->idFrom
== IDC_AUDIO_TREE
)
698 DWORD dwPos
= GetMessagePos();
699 HWND tree
= ((LPNMHDR
)lParam
)->hwndFrom
;
700 ZeroMemory(&ht
, sizeof(ht
));
701 ht
.pt
.x
= (short)LOWORD(dwPos
);
702 ht
.pt
.y
= (short)HIWORD(dwPos
);
703 MapWindowPoints(HWND_DESKTOP
, tree
, &ht
.pt
, 1);
704 SendMessageW( tree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
705 if (TVHT_ONITEMSTATEICON
& ht
.flags
)
709 ZeroMemory(&tvItem
, sizeof(tvItem
));
710 tvItem
.hItem
= ht
.hItem
;
711 SendMessageW( tree
, TVM_GETITEMW
, 0, (LPARAM
) &tvItem
);
713 index
= TreeView_GetItemState(tree
, ht
.hItem
, TVIS_STATEIMAGEMASK
);
714 if (index
== INDEXTOSTATEIMAGEMASK(1))
716 TreeView_SetItemState(tree
, ht
.hItem
, INDEXTOSTATEIMAGEMASK(2), TVIS_STATEIMAGEMASK
);
717 addDriver(loadedAudioDrv
[tvItem
.lParam
& 0xff].szDriver
);
718 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
720 else if (index
== INDEXTOSTATEIMAGEMASK(2))
722 TreeView_SetItemState(tree
, ht
.hItem
, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK
);
723 removeDriver(loadedAudioDrv
[tvItem
.lParam
& 0xff].szDriver
);
724 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
730 if (((LPNMHDR
)lParam
)->idFrom
== IDC_AUDIO_TREE
)
733 DWORD dwPos
= GetMessagePos();
734 HWND tree
= ((LPNMHDR
)lParam
)->hwndFrom
;
736 ZeroMemory(&ht
, sizeof(ht
));
737 pt
.x
= (short)LOWORD(dwPos
);
738 pt
.y
= (short)HIWORD(dwPos
);
740 MapWindowPoints(HWND_DESKTOP
, tree
, &ht
.pt
, 1);
741 SendMessageW( tree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
742 if (TVHT_ONITEMLABEL
& ht
.flags
)
745 ZeroMemory(&tvItem
, sizeof(tvItem
));
746 tvItem
.hItem
= ht
.hItem
;
747 tvItem
.mask
= TVIF_PARAM
;
749 if (TreeView_GetItem(tree
, &tvItem
))
751 if (tvItem
.lParam
& DRIVER_MASK
)
755 TrackPopupMenu(GetSubMenu(hPopupMenus
, 0), TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, tree
, NULL
);
756 toConfigure
= tvItem
.lParam
& ~DRIVER_MASK
;
759 else if (tvItem
.lParam
& DEVICE_MASK
)