audio.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /*
  2. * Audio management UI code
  3. *
  4. * Copyright 2004 Chris Morgan
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. *
  20. */
  21. #define WIN32_LEAN_AND_MEAN
  22. #define NONAMELESSUNION
  23. #include <assert.h>
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #define COBJMACROS
  28. #include <windows.h>
  29. #include <wine/debug.h>
  30. #include <shellapi.h>
  31. #include <objbase.h>
  32. #include <shlguid.h>
  33. #include <shlwapi.h>
  34. #include <shlobj.h>
  35. #include <mmsystem.h>
  36. #include <mmreg.h>
  37. #include <mmddk.h>
  38. #include "ole2.h"
  39. #include "initguid.h"
  40. #include "propkey.h"
  41. #include "devpkey.h"
  42. #include "mmdeviceapi.h"
  43. #include "audioclient.h"
  44. #include "audiopolicy.h"
  45. #include "winecfg.h"
  46. #include "resource.h"
  47. WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
  48. struct DeviceInfo {
  49. WCHAR *id;
  50. PROPVARIANT name;
  51. int speaker_config;
  52. };
  53. static WCHAR g_drv_keyW[256] = L"Software\\Wine\\Drivers\\";
  54. static UINT num_render_devs, num_capture_devs;
  55. static struct DeviceInfo *render_devs, *capture_devs;
  56. static const struct
  57. {
  58. int text_id;
  59. DWORD speaker_mask;
  60. } speaker_configs[] =
  61. {
  62. { IDS_AUDIO_SPEAKER_5POINT1, KSAUDIO_SPEAKER_5POINT1 },
  63. { IDS_AUDIO_SPEAKER_QUAD, KSAUDIO_SPEAKER_QUAD },
  64. { IDS_AUDIO_SPEAKER_STEREO, KSAUDIO_SPEAKER_STEREO },
  65. { IDS_AUDIO_SPEAKER_MONO, KSAUDIO_SPEAKER_MONO },
  66. { 0, 0 }
  67. };
  68. static BOOL load_device(IMMDevice *dev, struct DeviceInfo *info)
  69. {
  70. IPropertyStore *ps;
  71. HRESULT hr;
  72. PROPVARIANT pv;
  73. UINT i;
  74. hr = IMMDevice_GetId(dev, &info->id);
  75. if(FAILED(hr)){
  76. info->id = NULL;
  77. return FALSE;
  78. }
  79. hr = IMMDevice_OpenPropertyStore(dev, STGM_READ, &ps);
  80. if(FAILED(hr)){
  81. CoTaskMemFree(info->id);
  82. info->id = NULL;
  83. return FALSE;
  84. }
  85. PropVariantInit(&info->name);
  86. hr = IPropertyStore_GetValue(ps,
  87. (PROPERTYKEY*)&DEVPKEY_Device_FriendlyName, &info->name);
  88. if(FAILED(hr)){
  89. CoTaskMemFree(info->id);
  90. info->id = NULL;
  91. IPropertyStore_Release(ps);
  92. return FALSE;
  93. }
  94. PropVariantInit(&pv);
  95. hr = IPropertyStore_GetValue(ps,
  96. &PKEY_AudioEndpoint_PhysicalSpeakers, &pv);
  97. info->speaker_config = -1;
  98. if(SUCCEEDED(hr) && pv.vt == VT_UI4){
  99. i = 0;
  100. while (speaker_configs[i].text_id != 0) {
  101. if ((speaker_configs[i].speaker_mask & pv.ulVal) == speaker_configs[i].speaker_mask) {
  102. info->speaker_config = i;
  103. break;
  104. }
  105. i++;
  106. }
  107. }
  108. /* fallback to stereo */
  109. if(info->speaker_config == -1)
  110. info->speaker_config = 2;
  111. IPropertyStore_Release(ps);
  112. return TRUE;
  113. }
  114. static BOOL load_devices(IMMDeviceEnumerator *devenum, EDataFlow dataflow,
  115. UINT *ndevs, struct DeviceInfo **out)
  116. {
  117. IMMDeviceCollection *coll;
  118. UINT i;
  119. HRESULT hr;
  120. hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, dataflow,
  121. DEVICE_STATE_ACTIVE, &coll);
  122. if(FAILED(hr))
  123. return FALSE;
  124. hr = IMMDeviceCollection_GetCount(coll, ndevs);
  125. if(FAILED(hr)){
  126. IMMDeviceCollection_Release(coll);
  127. return FALSE;
  128. }
  129. if(*ndevs > 0){
  130. *out = HeapAlloc(GetProcessHeap(), 0,
  131. sizeof(struct DeviceInfo) * (*ndevs));
  132. if(!*out){
  133. IMMDeviceCollection_Release(coll);
  134. return FALSE;
  135. }
  136. for(i = 0; i < *ndevs; ++i){
  137. IMMDevice *dev;
  138. hr = IMMDeviceCollection_Item(coll, i, &dev);
  139. if(FAILED(hr)){
  140. (*out)[i].id = NULL;
  141. continue;
  142. }
  143. load_device(dev, &(*out)[i]);
  144. IMMDevice_Release(dev);
  145. }
  146. }else
  147. *out = NULL;
  148. IMMDeviceCollection_Release(coll);
  149. return TRUE;
  150. }
  151. static BOOL get_driver_name(IMMDeviceEnumerator *devenum, PROPVARIANT *pv)
  152. {
  153. IMMDevice *device;
  154. IPropertyStore *ps;
  155. HRESULT hr;
  156. hr = IMMDeviceEnumerator_GetDevice(devenum, L"Wine info device", &device);
  157. if(FAILED(hr))
  158. return FALSE;
  159. hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
  160. if(FAILED(hr)){
  161. IMMDevice_Release(device);
  162. return FALSE;
  163. }
  164. hr = IPropertyStore_GetValue(ps,
  165. (const PROPERTYKEY *)&DEVPKEY_Device_Driver, pv);
  166. IPropertyStore_Release(ps);
  167. IMMDevice_Release(device);
  168. if(FAILED(hr))
  169. return FALSE;
  170. return TRUE;
  171. }
  172. static void initAudioDlg (HWND hDlg)
  173. {
  174. WCHAR display_str[256], format_str[256], sysdefault_str[256], disabled_str[64];
  175. IMMDeviceEnumerator *devenum;
  176. BOOL have_driver = FALSE;
  177. HRESULT hr;
  178. UINT i;
  179. LVCOLUMNW lvcol;
  180. WCHAR colW[64], speaker_str[256];
  181. RECT rect;
  182. DWORD width;
  183. WINE_TRACE("\n");
  184. LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_DRIVER, format_str, ARRAY_SIZE(format_str));
  185. LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_DRIVER_NONE, disabled_str,
  186. ARRAY_SIZE(disabled_str));
  187. LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_SYSDEFAULT, sysdefault_str,
  188. ARRAY_SIZE(sysdefault_str));
  189. hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
  190. CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&devenum);
  191. if(SUCCEEDED(hr)){
  192. PROPVARIANT pv;
  193. load_devices(devenum, eRender, &num_render_devs, &render_devs);
  194. load_devices(devenum, eCapture, &num_capture_devs, &capture_devs);
  195. PropVariantInit(&pv);
  196. if(get_driver_name(devenum, &pv) && pv.pwszVal[0] != '\0'){
  197. have_driver = TRUE;
  198. swprintf(display_str, ARRAY_SIZE(display_str), format_str, pv.pwszVal);
  199. lstrcatW(g_drv_keyW, pv.pwszVal);
  200. }
  201. PropVariantClear(&pv);
  202. IMMDeviceEnumerator_Release(devenum);
  203. }
  204. SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_ADDSTRING,
  205. 0, (LPARAM)sysdefault_str);
  206. SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_SETCURSEL, 0, 0);
  207. SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_ADDSTRING,
  208. 0, (LPARAM)sysdefault_str);
  209. SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_SETCURSEL, 0, 0);
  210. SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_ADDSTRING,
  211. 0, (LPARAM)sysdefault_str);
  212. SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_SETCURSEL, 0, 0);
  213. SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_ADDSTRING,
  214. 0, (LPARAM)sysdefault_str);
  215. SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_SETCURSEL, 0, 0);
  216. i = 0;
  217. while (speaker_configs[i].text_id != 0) {
  218. LoadStringW(GetModuleHandleW(NULL), speaker_configs[i].text_id, speaker_str,
  219. ARRAY_SIZE(speaker_str));
  220. SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_ADDSTRING,
  221. 0, (LPARAM)speaker_str);
  222. i++;
  223. }
  224. GetClientRect(GetDlgItem(hDlg, IDC_LIST_AUDIO_DEVICES), &rect);
  225. width = (rect.right - rect.left) * 3 / 5;
  226. LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_DEVICE, colW, ARRAY_SIZE(colW));
  227. lvcol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
  228. lvcol.pszText = colW;
  229. lvcol.cchTextMax = lstrlenW(colW);
  230. lvcol.cx = width;
  231. SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_INSERTCOLUMNW, 0, (LPARAM)&lvcol);
  232. LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_SPEAKER_CONFIG, colW, ARRAY_SIZE(colW));
  233. lvcol.pszText = colW;
  234. lvcol.cchTextMax = lstrlenW(colW);
  235. lvcol.cx = rect.right - rect.left - width;
  236. SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_INSERTCOLUMNW, 1, (LPARAM)&lvcol);
  237. EnableWindow(GetDlgItem(hDlg, IDC_SPEAKERCONFIG_SPEAKERS), 0);
  238. if(have_driver){
  239. WCHAR *reg_out_dev, *reg_vout_dev, *reg_in_dev, *reg_vin_dev;
  240. reg_out_dev = get_reg_key(HKEY_CURRENT_USER, g_drv_keyW, L"DefaultOutput", NULL);
  241. reg_vout_dev = get_reg_key(HKEY_CURRENT_USER, g_drv_keyW, L"DefaultVoiceOutput", NULL);
  242. reg_in_dev = get_reg_key(HKEY_CURRENT_USER, g_drv_keyW, L"DefaultInput", NULL);
  243. reg_vin_dev = get_reg_key(HKEY_CURRENT_USER, g_drv_keyW, L"DefaultVoiceInput", NULL);
  244. for(i = 0; i < num_render_devs; ++i){
  245. LVITEMW lvitem;
  246. if(!render_devs[i].id)
  247. continue;
  248. SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_ADDSTRING,
  249. 0, (LPARAM)render_devs[i].name.pwszVal);
  250. SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_SETITEMDATA,
  251. i + 1, (LPARAM)&render_devs[i]);
  252. if(reg_out_dev && !wcscmp(render_devs[i].id, reg_out_dev)){
  253. SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_SETCURSEL, i + 1, 0);
  254. SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_SETCURSEL, render_devs[i].speaker_config, 0);
  255. }
  256. SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_ADDSTRING,
  257. 0, (LPARAM)render_devs[i].name.pwszVal);
  258. SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_SETITEMDATA,
  259. i + 1, (LPARAM)&render_devs[i]);
  260. if(reg_vout_dev && !wcscmp(render_devs[i].id, reg_vout_dev))
  261. SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_SETCURSEL, i + 1, 0);
  262. lvitem.mask = LVIF_TEXT | LVIF_PARAM;
  263. lvitem.iItem = i;
  264. lvitem.iSubItem = 0;
  265. lvitem.pszText = render_devs[i].name.pwszVal;
  266. lvitem.cchTextMax = lstrlenW(lvitem.pszText);
  267. lvitem.lParam = (LPARAM)&render_devs[i];
  268. SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_INSERTITEMW, 0, (LPARAM)&lvitem);
  269. LoadStringW(GetModuleHandleW(NULL), speaker_configs[render_devs[i].speaker_config].text_id,
  270. speaker_str, ARRAY_SIZE(speaker_str));
  271. lvitem.mask = LVIF_TEXT;
  272. lvitem.iItem = i;
  273. lvitem.iSubItem = 1;
  274. lvitem.pszText = speaker_str;
  275. lvitem.cchTextMax = lstrlenW(lvitem.pszText);
  276. SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_SETITEMW, 0, (LPARAM)&lvitem);
  277. }
  278. for(i = 0; i < num_capture_devs; ++i){
  279. if(!capture_devs[i].id)
  280. continue;
  281. SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_ADDSTRING,
  282. 0, (LPARAM)capture_devs[i].name.pwszVal);
  283. SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_SETITEMDATA,
  284. i + 1, (LPARAM)&capture_devs[i]);
  285. if(reg_in_dev && !wcscmp(capture_devs[i].id, reg_in_dev))
  286. SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_SETCURSEL, i + 1, 0);
  287. SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_ADDSTRING,
  288. 0, (LPARAM)capture_devs[i].name.pwszVal);
  289. SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_SETITEMDATA,
  290. i + 1, (LPARAM)&capture_devs[i]);
  291. if(reg_vin_dev && !wcscmp(capture_devs[i].id, reg_vin_dev))
  292. SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_SETCURSEL, i + 1, 0);
  293. }
  294. HeapFree(GetProcessHeap(), 0, reg_out_dev);
  295. HeapFree(GetProcessHeap(), 0, reg_vout_dev);
  296. HeapFree(GetProcessHeap(), 0, reg_in_dev);
  297. HeapFree(GetProcessHeap(), 0, reg_vin_dev);
  298. }else
  299. swprintf(display_str, ARRAY_SIZE(display_str), format_str, disabled_str);
  300. SetDlgItemTextW(hDlg, IDC_AUDIO_DRIVER, display_str);
  301. }
  302. static void set_reg_device(HWND hDlg, int dlgitem, const WCHAR *key_name)
  303. {
  304. UINT idx;
  305. struct DeviceInfo *info;
  306. idx = SendDlgItemMessageW(hDlg, dlgitem, CB_GETCURSEL, 0, 0);
  307. info = (struct DeviceInfo *)SendDlgItemMessageW(hDlg, dlgitem,
  308. CB_GETITEMDATA, idx, 0);
  309. if(!info || info == (void*)CB_ERR)
  310. set_reg_key(HKEY_CURRENT_USER, g_drv_keyW, key_name, NULL);
  311. else
  312. set_reg_key(HKEY_CURRENT_USER, g_drv_keyW, key_name, info->id);
  313. }
  314. static void test_sound(void)
  315. {
  316. if(!PlaySoundW(MAKEINTRESOURCEW(IDW_TESTSOUND), NULL, SND_RESOURCE | SND_ASYNC)){
  317. WCHAR error_str[256], title_str[256];
  318. LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_TEST_FAILED, error_str,
  319. ARRAY_SIZE(error_str));
  320. LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_TEST_FAILED_TITLE, title_str,
  321. ARRAY_SIZE(title_str));
  322. MessageBoxW(NULL, error_str, title_str, MB_OK | MB_ICONERROR);
  323. }
  324. }
  325. static void apply_speaker_configs(void)
  326. {
  327. UINT i;
  328. IMMDeviceEnumerator *devenum;
  329. IMMDevice *dev;
  330. IPropertyStore *ps;
  331. PROPVARIANT pv;
  332. HRESULT hr;
  333. hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
  334. CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&devenum);
  335. if(FAILED(hr)){
  336. ERR("Unable to create MMDeviceEnumerator: 0x%08x\n", hr);
  337. return;
  338. }
  339. PropVariantInit(&pv);
  340. pv.vt = VT_UI4;
  341. for (i = 0; i < num_render_devs; i++) {
  342. hr = IMMDeviceEnumerator_GetDevice(devenum, render_devs[i].id, &dev);
  343. if(FAILED(hr)){
  344. WARN("Could not get MMDevice for %s: 0x%08x\n", wine_dbgstr_w(render_devs[i].id), hr);
  345. continue;
  346. }
  347. hr = IMMDevice_OpenPropertyStore(dev, STGM_WRITE, &ps);
  348. if(FAILED(hr)){
  349. WARN("Could not open property store for %s: 0x%08x\n", wine_dbgstr_w(render_devs[i].id), hr);
  350. IMMDevice_Release(dev);
  351. continue;
  352. }
  353. pv.ulVal = speaker_configs[render_devs[i].speaker_config].speaker_mask;
  354. hr = IPropertyStore_SetValue(ps, &PKEY_AudioEndpoint_PhysicalSpeakers, &pv);
  355. if (FAILED(hr))
  356. WARN("IPropertyStore_SetValue failed for %s: 0x%08x\n", wine_dbgstr_w(render_devs[i].id), hr);
  357. IPropertyStore_Release(ps);
  358. IMMDevice_Release(dev);
  359. }
  360. IMMDeviceEnumerator_Release(devenum);
  361. }
  362. static void listview_changed(HWND hDlg)
  363. {
  364. int idx;
  365. idx = SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
  366. if(idx < 0) {
  367. EnableWindow(GetDlgItem(hDlg, IDC_SPEAKERCONFIG_SPEAKERS), 0);
  368. return;
  369. }
  370. SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_SETCURSEL,
  371. render_devs[idx].speaker_config, 0);
  372. EnableWindow(GetDlgItem(hDlg, IDC_SPEAKERCONFIG_SPEAKERS), 1);
  373. }
  374. INT_PTR CALLBACK
  375. AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  376. {
  377. switch (uMsg) {
  378. case WM_COMMAND:
  379. switch (LOWORD(wParam)) {
  380. case IDC_AUDIO_TEST:
  381. test_sound();
  382. break;
  383. case IDC_AUDIOOUT_DEVICE:
  384. if(HIWORD(wParam) == CBN_SELCHANGE){
  385. set_reg_device(hDlg, IDC_AUDIOOUT_DEVICE, L"DefaultOutput");
  386. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  387. }
  388. break;
  389. case IDC_VOICEOUT_DEVICE:
  390. if(HIWORD(wParam) == CBN_SELCHANGE){
  391. set_reg_device(hDlg, IDC_VOICEOUT_DEVICE, L"DefaultVoiceOutput");
  392. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  393. }
  394. break;
  395. case IDC_AUDIOIN_DEVICE:
  396. if(HIWORD(wParam) == CBN_SELCHANGE){
  397. set_reg_device(hDlg, IDC_AUDIOIN_DEVICE, L"DefaultInput");
  398. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  399. }
  400. break;
  401. case IDC_VOICEIN_DEVICE:
  402. if(HIWORD(wParam) == CBN_SELCHANGE){
  403. set_reg_device(hDlg, IDC_VOICEIN_DEVICE, L"DefaultVoiceInput");
  404. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  405. }
  406. break;
  407. case IDC_SPEAKERCONFIG_SPEAKERS:
  408. if(HIWORD(wParam) == CBN_SELCHANGE){
  409. UINT dev, idx;
  410. idx = SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_GETCURSEL, 0, 0);
  411. dev = SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
  412. if(dev < num_render_devs){
  413. WCHAR speaker_str[256];
  414. LVITEMW lvitem;
  415. render_devs[dev].speaker_config = idx;
  416. LoadStringW(GetModuleHandleW(NULL), speaker_configs[idx].text_id,
  417. speaker_str, ARRAY_SIZE(speaker_str));
  418. lvitem.mask = LVIF_TEXT;
  419. lvitem.iItem = dev;
  420. lvitem.iSubItem = 1;
  421. lvitem.pszText = speaker_str;
  422. lvitem.cchTextMax = lstrlenW(lvitem.pszText);
  423. SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_SETITEMW, 0, (LPARAM)&lvitem);
  424. SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
  425. }
  426. }
  427. break;
  428. }
  429. break;
  430. case WM_SHOWWINDOW:
  431. set_window_title(hDlg);
  432. break;
  433. case WM_NOTIFY:
  434. switch(((LPNMHDR)lParam)->code) {
  435. case PSN_KILLACTIVE:
  436. SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, FALSE);
  437. break;
  438. case PSN_APPLY:
  439. apply_speaker_configs();
  440. apply();
  441. SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  442. break;
  443. case PSN_SETACTIVE:
  444. break;
  445. case LVN_ITEMCHANGED:
  446. listview_changed(hDlg);
  447. break;
  448. }
  449. break;
  450. case WM_INITDIALOG:
  451. initAudioDlg(hDlg);
  452. break;
  453. }
  454. return FALSE;
  455. }