Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

316 lines
6.9 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995-1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: snddlg.cpp
  6. * Content: Sound card selection dialog
  7. * History:
  8. *
  9. * Date By Reason
  10. * ==== == ======
  11. * 12/1/99 rodtoll created it
  12. *
  13. ***************************************************************************/
  14. #include "dxvhelppch.h"
  15. GUID g_guidPlayback = GUID_NULL;
  16. GUID g_guidRecord = GUID_NULL;
  17. typedef HRESULT (WINAPI *DSENUM)( LPDSENUMCALLBACK lpDSEnumCallback,LPVOID lpContext );
  18. #undef DPF_MODNAME
  19. #define DPF_MODNAME "SoundListFillCallback"
  20. BOOL CALLBACK SoundListFillCallback(
  21. LPGUID lpGuid,
  22. LPCSTR lpcstrDescription,
  23. LPCSTR lpcstrModule,
  24. LPVOID lpContext
  25. )
  26. {
  27. DNASSERT( lpContext != NULL );
  28. HWND hwnd = *((HWND *) lpContext);
  29. LRESULT lIndex;
  30. if( lpGuid == NULL )
  31. return TRUE;
  32. LPGUID pTmpGuid = new GUID;
  33. if( pTmpGuid != NULL )
  34. {
  35. memcpy( pTmpGuid, lpGuid, sizeof(GUID) );
  36. lIndex = SendMessage( hwnd, CB_ADDSTRING, 0, (LPARAM) lpcstrDescription );
  37. SendMessage( hwnd, CB_SETITEMDATA, lIndex, (LPARAM) pTmpGuid );
  38. }
  39. return TRUE;
  40. }
  41. struct GetGUIDParam
  42. {
  43. DWORD dwCurrentIndex;
  44. DWORD dwTargetIndex;
  45. GUID guidDevice;
  46. };
  47. #undef DPF_MODNAME
  48. #define DPF_MODNAME "SoundGetGUIDCallback"
  49. BOOL CALLBACK SoundGetGUIDCallback(
  50. LPGUID lpGuid,
  51. LPCSTR lpcstrDescription,
  52. LPCSTR lpcstrModule,
  53. LPVOID lpContext
  54. )
  55. {
  56. DNASSERT( lpContext != NULL );
  57. GetGUIDParam *pParam = (GetGUIDParam *) lpContext;
  58. if( pParam->dwCurrentIndex == pParam->dwTargetIndex )
  59. {
  60. if( lpGuid == NULL )
  61. {
  62. pParam->guidDevice = GUID_NULL;
  63. }
  64. else
  65. {
  66. pParam->guidDevice = *lpGuid;
  67. }
  68. return FALSE;
  69. }
  70. pParam->dwCurrentIndex++;
  71. return TRUE;
  72. }
  73. #undef DPF_MODNAME
  74. #define DPF_MODNAME "LoadDSAndCallEnum"
  75. HRESULT LoadDSAndCallEnum( const TCHAR *lpszEnumFuncName, LPDSENUMCALLBACK enumCallback, LPVOID lpvContext )
  76. {
  77. DSENUM enumFunc;
  78. HINSTANCE hinstds;
  79. HRESULT hr;
  80. hinstds = NULL;
  81. // Attempt to load the directsound DLL
  82. hinstds = LoadLibrary( _T("DSOUND.DLL") );
  83. // If it couldn't be loaded, this sub system is not supported
  84. // on this system.
  85. if( hinstds == NULL )
  86. {
  87. DPFX(DPFPREP, DVF_INFOLEVEL, "Unable to load dsound.dll to enum devices" );
  88. return DVERR_GENERIC;
  89. }
  90. // Attempt to get the DirectSoundCaptureEnumerateA function from the
  91. // DSOUND.DLL. If it's not available then this class assumes it's
  92. // not supported on this system.
  93. enumFunc = (DSENUM) GetProcAddress( hinstds, lpszEnumFuncName );
  94. if( enumFunc == NULL )
  95. {
  96. DPFX(DPFPREP, DVF_INFOLEVEL, "Unable to find cap enum func for enumerate" );
  97. FreeLibrary( hinstds );
  98. return DVERR_GENERIC;
  99. }
  100. hr = (*enumFunc)( enumCallback, lpvContext );
  101. if( FAILED( hr ) )
  102. {
  103. DPFX(DPFPREP, DVF_ERRORLEVEL, "Enum call failed hr=0x%x", hr );
  104. }
  105. FreeLibrary( hinstds );
  106. return hr;
  107. }
  108. #undef DPF_MODNAME
  109. #define DPF_MODNAME "SoundDialog_FillPlaybackPulldown"
  110. void SoundDialog_FillPlaybackPulldown( HWND hDlg )
  111. {
  112. HWND hwndPulldown = GetDlgItem( hDlg, IDC_COMBO_PLAYBACK );
  113. DNASSERT( hwndPulldown != NULL );
  114. HRESULT hr = LoadDSAndCallEnum( _T("DirectSoundEnumerateA"), SoundListFillCallback, (LPVOID) &hwndPulldown );
  115. if( FAILED( hr ) )
  116. {
  117. DPFX(DPFPREP, DVF_ERRORLEVEL, "Load and enum of devices failed hr=0x%x", hr );
  118. }
  119. SendMessage( hwndPulldown, CB_SETCURSEL, 0, 0 );
  120. }
  121. #undef DPF_MODNAME
  122. #define DPF_MODNAME "SoundDialog_FillRecordPulldown"
  123. void SoundDialog_FillRecordPulldown( HWND hDlg )
  124. {
  125. HWND hwndPulldown = GetDlgItem( hDlg, IDC_COMBO_RECORD );
  126. DNASSERT( hwndPulldown != NULL );
  127. HRESULT hr = LoadDSAndCallEnum( _T("DirectSoundCaptureEnumerateA"), SoundListFillCallback, (LPVOID) &hwndPulldown );
  128. if( FAILED( hr ) )
  129. {
  130. DPFX(DPFPREP, DVF_ERRORLEVEL, "Load and enum of devices failed hr=0x%x", hr );
  131. }
  132. SendMessage( hwndPulldown, CB_SETCURSEL, 0, 0 );
  133. }
  134. #undef DPF_MODNAME
  135. #define DPF_MODNAME "SoundDialog_HandleCommandOK"
  136. BOOL SoundDialog_HandleCommandOK( HWND hDlg )
  137. {
  138. LRESULT lIndex;
  139. lIndex = SendMessage( GetDlgItem( hDlg, IDC_COMBO_PLAYBACK ), CB_GETCURSEL, 0, 0 );
  140. if( lIndex == CB_ERR )
  141. {
  142. MessageBox( NULL, _T("Select a playback device!"), _T("Error"), MB_OK );
  143. return FALSE;
  144. }
  145. LPGUID lpguidTmp = (LPGUID) SendMessage( GetDlgItem( hDlg, IDC_COMBO_PLAYBACK ), CB_GETITEMDATA, lIndex, 0 );
  146. if( lpguidTmp != NULL )
  147. {
  148. memcpy( &g_guidPlayback, lpguidTmp, sizeof( GUID ) );
  149. }
  150. else
  151. {
  152. memset( &g_guidPlayback, 0x00, sizeof( GUID ) );
  153. }
  154. lIndex = SendMessage( GetDlgItem( hDlg, IDC_COMBO_RECORD ), CB_GETCURSEL, 0, 0 );
  155. if( lIndex == CB_ERR )
  156. {
  157. MessageBox( NULL, _T("Select a playback device!"), _T("Error"), MB_OK );
  158. return FALSE;
  159. }
  160. lpguidTmp = (LPGUID) SendMessage( GetDlgItem( hDlg, IDC_COMBO_RECORD ), CB_GETITEMDATA, lIndex, 0 );
  161. if( lpguidTmp != NULL )
  162. {
  163. memcpy( &g_guidRecord, lpguidTmp, sizeof( GUID ) );
  164. }
  165. else
  166. {
  167. memset( &g_guidRecord, 0x00, sizeof( GUID ) );
  168. }
  169. /* enumParam.dwCurrentIndex = 0;
  170. enumParam.dwTargetIndex = lIndex;
  171. enumParam.guidDevice = GUID_NULL;
  172. hr = LoadDSAndCallEnum( _T("DirectSoundCaptureEnumerateA"), SoundGetGUIDCallback, (LPVOID) &enumParam );
  173. if( FAILED( hr ) )
  174. {
  175. DPFX(DPFPREP, DVF_ERRORLEVEL, "Retrieval of capture device failed hr=0x%x", hr );
  176. }
  177. else
  178. {
  179. g_guidRecord = enumParam.guidDevice;
  180. }
  181. lIndex = SendMessage( GetDlgItem( hDlg, IDC_COMBO_RECORD ), CB_GETCURSEL, 0, 0 );
  182. if( lIndex == CB_ERR )
  183. {
  184. MessageBox( NULL, _T("Select a record device!"), _T("Error"), MB_OK );
  185. return FALSE;
  186. }
  187. enumParam.dwCurrentIndex = 0;
  188. enumParam.dwTargetIndex = lIndex;
  189. enumParam.guidDevice = GUID_NULL;
  190. hr = LoadDSAndCallEnum( _T("DirectSoundEnumerateA"), SoundGetGUIDCallback, (LPVOID) &enumParam );
  191. if( FAILED( hr ) )
  192. {
  193. DPFX(DPFPREP, DVF_ERRORLEVEL, "Retrieval of playback device failed hr=0x%x", hr );
  194. }
  195. else
  196. {
  197. g_guidPlayback = enumParam.guidDevice;
  198. } */
  199. return TRUE;
  200. }
  201. #undef DPF_MODNAME
  202. #define DPF_MODNAME "SoundDialog_WinProc"
  203. INT_PTR CALLBACK SoundDialog_WinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  204. {
  205. switch (message)
  206. {
  207. case WM_INITDIALOG:
  208. SoundDialog_FillPlaybackPulldown( hDlg );
  209. SoundDialog_FillRecordPulldown( hDlg );
  210. return TRUE;
  211. case WM_COMMAND:
  212. if (LOWORD(wParam) == IDOK )
  213. {
  214. if( !SoundDialog_HandleCommandOK( hDlg ) )
  215. {
  216. return FALSE;
  217. }
  218. }
  219. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  220. {
  221. EndDialog(hDlg, LOWORD(wParam));
  222. return TRUE;
  223. }
  224. break;
  225. }
  226. return FALSE;
  227. }
  228. #undef DPF_MODNAME
  229. #define DPF_MODNAME "SoundDialog_GetCardSettings"
  230. BOOL GetCardSettings( HINSTANCE hInst, HWND hOwner, LPGUID pguidPlayback, LPGUID pguidRecord )
  231. {
  232. if( DialogBox( hInst, MAKEINTRESOURCE( IDD_DIALOG_SOUND ), hOwner, SoundDialog_WinProc ) == IDOK )
  233. {
  234. *pguidPlayback = g_guidPlayback;
  235. *pguidRecord = g_guidRecord;
  236. return TRUE;
  237. }
  238. else
  239. {
  240. return FALSE;
  241. }
  242. }