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.

516 lines
14 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995-1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: maindlg.cpp
  6. * Content: Main Dialog Support Routines
  7. * History:
  8. *
  9. * Date By Reason
  10. * ==== == ======
  11. * 10/15/99 rodtoll created it
  12. * 10/15/99 rodtoll Placed guards to prevent operating on window once it's gone
  13. * 10/20/99 rodtoll Fix: Bug #114185 Adjusting volume while not connected causes crash
  14. * 11/12/99 rodtoll Added code to handle the new "Enable Echo suppression" check box.
  15. * 12/07/99 rodtoll Bug #122628 Make error messages silent when running in silent mode
  16. * 7/21/2000 rodtoll 64-bit build bug -- just appeared
  17. *
  18. ***************************************************************************/
  19. #include "dxvhelppch.h"
  20. PDXVHELP_RTINFO g_prtInfo = NULL;
  21. #undef DPF_MODNAME
  22. #define DPF_MODNAME "MainDialog_EnumPlayers"
  23. BOOL FAR PASCAL MainDialog_EnumPlayers(
  24. DPID dpId,
  25. DWORD dwPlayerType,
  26. LPCDPNAME lpName,
  27. DWORD dwFlags,
  28. LPVOID lpContext
  29. )
  30. {
  31. PDXVHELP_RTINFO prtInfo = (PDXVHELP_RTINFO) lpContext;
  32. MainDialog_AddTransportPlayer( prtInfo->hMainDialog, dpId );
  33. return TRUE;
  34. }
  35. #undef DPF_MODNAME
  36. #define DPF_MODNAME "MainDialog_UpdatePlayerList"
  37. void MainDialog_UpdatePlayerList( HWND hDlg, PDXVHELP_RTINFO prtInfo )
  38. {
  39. prtInfo->lpdpDirectPlay->EnumPlayers( NULL, MainDialog_EnumPlayers, prtInfo, DPENUMPLAYERS_ALL );
  40. }
  41. #undef DPF_MODNAME
  42. #define DPF_MODNAME "MainDialog_AddTransportPlayer"
  43. void MainDialog_AddTransportPlayer( HWND hDlg, DWORD dwID )
  44. {
  45. TCHAR tszBuffer[100];
  46. _stprintf( tszBuffer, _T("0x%x"), dwID );
  47. SendMessage( GetDlgItem( hDlg, IDC_LIST_DPLAY ), LB_ADDSTRING, 0, (WPARAM) tszBuffer );
  48. }
  49. #undef DPF_MODNAME
  50. #define DPF_MODNAME "MainDialog_RemoveTransportPlayer"
  51. void MainDialog_RemoveTransportPlayer( HWND hDlg, DWORD dwID )
  52. {
  53. TCHAR tszBuffer[100];
  54. _stprintf( tszBuffer, _T("0x%x"), dwID );
  55. LONG_PTR lResult;
  56. lResult = SendMessage( GetDlgItem( hDlg, IDC_LIST_DPLAY ), LB_FINDSTRINGEXACT, -1, (WPARAM)tszBuffer );
  57. if( lResult != LB_ERR )
  58. {
  59. SendMessage( GetDlgItem( hDlg, IDC_LIST_DPLAY ), LB_DELETESTRING, lResult, 0 );
  60. }
  61. }
  62. #undef DPF_MODNAME
  63. #define DPF_MODNAME "MainDialog_AddVoicePlayer"
  64. void MainDialog_AddVoicePlayer( HWND hDlg, DWORD dwID )
  65. {
  66. TCHAR tszBuffer[100];
  67. _stprintf( tszBuffer, _T("0x%x"), dwID );
  68. SendMessage( GetDlgItem( hDlg, IDC_LIST_DVOICE ), LB_ADDSTRING, 0, (WPARAM)tszBuffer );
  69. }
  70. #undef DPF_MODNAME
  71. #define DPF_MODNAME "MainDialog_RemoveVoicePlayer"
  72. void MainDialog_RemoveVoicePlayer( HWND hDlg, DWORD dwID )
  73. {
  74. TCHAR tszBuffer[100];
  75. _stprintf( tszBuffer, _T("0x%x"), dwID );
  76. LONG_PTR lResult;
  77. lResult = SendMessage( GetDlgItem( hDlg, IDC_LIST_DVOICE ), LB_FINDSTRINGEXACT, -1, (WPARAM)tszBuffer );
  78. if( lResult != LB_ERR )
  79. {
  80. SendMessage( GetDlgItem( hDlg, IDC_LIST_DVOICE ), LB_DELETESTRING, lResult, 0 );
  81. }
  82. }
  83. #undef DPF_MODNAME
  84. #define DPF_MODNAME "MainDialog_AddToLog"
  85. void MainDialog_AddToLog( HWND hDlg, LPTSTR lpstrMessage )
  86. {
  87. LONG_PTR lResult;
  88. lResult = SendMessage( GetDlgItem( hDlg, IDC_LIST_OUTPUT ), LB_ADDSTRING, 0, (WPARAM)lpstrMessage );
  89. SendMessage( GetDlgItem( hDlg, IDC_LIST_OUTPUT ), LB_SETTOPINDEX,lResult, 0 );
  90. }
  91. #undef DPF_MODNAME
  92. #define DPF_MODNAME "MainDialog_DisplayStatus"
  93. void MainDialog_DisplayStatus( HWND hDlg, LPTSTR lpstrStatus )
  94. {
  95. if( hDlg == NULL )
  96. return;
  97. HWND hwndItem = GetDlgItem( hDlg, IDC_STATIC_STATUS );
  98. if( hwndItem != NULL )
  99. {
  100. SetWindowText( hwndItem, lpstrStatus );
  101. }
  102. }
  103. #undef DPF_MODNAME
  104. #define DPF_MODNAME "MainDialog_DisplayVolumeSettings"
  105. void MainDialog_DisplayVolumeSettings( HWND hDlg, PDXVHELP_RTINFO prtInfo )
  106. {
  107. if( hDlg == NULL )
  108. return;
  109. if( prtInfo->dxvParameters.fAGC )
  110. {
  111. CheckDlgButton( hDlg, IDC_CHECK_AGC, BST_CHECKED );
  112. EnableWindow( GetDlgItem( hDlg, IDC_SLIDER_RECVOLUME ), FALSE );
  113. }
  114. else
  115. {
  116. CheckDlgButton( hDlg, IDC_CHECK_AGC, BST_UNCHECKED );
  117. EnableWindow( GetDlgItem( hDlg, IDC_SLIDER_RECVOLUME ), TRUE );
  118. }
  119. if( prtInfo->dxvParameters.fEchoSuppression )
  120. {
  121. CheckDlgButton( hDlg, IDC_CHECK_ES, BST_CHECKED );
  122. }
  123. else
  124. {
  125. CheckDlgButton( hDlg, IDC_CHECK_ES, BST_UNCHECKED );
  126. }
  127. SendMessage( GetDlgItem( hDlg, IDC_SLIDER_RECVOLUME ), TBM_SETPOS, (WPARAM) TRUE, (LPARAM) (((LONG) prtInfo->dxvParameters.lRecordVolume)*((LONG) -1)) );
  128. }
  129. #undef DPF_MODNAME
  130. #define DPF_MODNAME "MainDialog_HandleESCheck"
  131. void MainDialog_HandleESCheck( HWND hDlg, HWND hwndControl, PDXVHELP_RTINFO prtInfo )
  132. {
  133. DVCLIENTCONFIG dvClientConfig;
  134. dvClientConfig.dwSize = sizeof( DVCLIENTCONFIG );
  135. if( prtInfo->lpdvClient != NULL )
  136. prtInfo->lpdvClient->GetClientConfig( &dvClientConfig );
  137. if( SendMessage( (HWND) hwndControl, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
  138. {
  139. dvClientConfig.dwFlags |= DVCLIENTCONFIG_ECHOSUPPRESSION;
  140. prtInfo->dxvParameters.fEchoSuppression = TRUE;
  141. }
  142. else
  143. {
  144. dvClientConfig.dwFlags &= ~DVCLIENTCONFIG_ECHOSUPPRESSION;
  145. prtInfo->dxvParameters.fEchoSuppression = FALSE;
  146. }
  147. if( prtInfo->lpdvClient != NULL )
  148. prtInfo->lpdvClient->SetClientConfig( &dvClientConfig );
  149. MainDialog_DisplayVolumeSettings( hDlg, prtInfo );
  150. }
  151. #undef DPF_MODNAME
  152. #define DPF_MODNAME "MainDialog_HandleAGCCheck"
  153. void MainDialog_HandleAGCCheck( HWND hDlg, HWND hwndControl, PDXVHELP_RTINFO prtInfo )
  154. {
  155. DVCLIENTCONFIG dvClientConfig;
  156. dvClientConfig.dwSize = sizeof( DVCLIENTCONFIG );
  157. if( prtInfo->lpdvClient != NULL )
  158. prtInfo->lpdvClient->GetClientConfig( &dvClientConfig );
  159. if( SendMessage( (HWND) hwndControl, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
  160. {
  161. dvClientConfig.dwFlags |= DVCLIENTCONFIG_AUTORECORDVOLUME;
  162. prtInfo->dxvParameters.lRecordVolume = 0;
  163. prtInfo->dxvParameters.fAGC = TRUE;
  164. }
  165. else
  166. {
  167. dvClientConfig.dwFlags &= ~DVCLIENTCONFIG_AUTORECORDVOLUME;
  168. prtInfo->dxvParameters.lRecordVolume = -9000;
  169. prtInfo->dxvParameters.fAGC = FALSE;
  170. }
  171. dvClientConfig.lRecordVolume = prtInfo->dxvParameters.lRecordVolume;
  172. if( prtInfo->lpdvClient != NULL )
  173. prtInfo->lpdvClient->SetClientConfig( &dvClientConfig );
  174. MainDialog_DisplayVolumeSettings( hDlg, prtInfo );
  175. }
  176. #undef DPF_MODNAME
  177. #define DPF_MODNAME "MainDialog_HandleConnect"
  178. void MainDialog_HandleConnect( HWND hDlg, PDXVHELP_RTINFO prtInfo )
  179. {
  180. if( GetConnectSettings( prtInfo->hInst, hDlg, prtInfo->dxvParameters.lpszConnectAddress ) )
  181. {
  182. prtInfo->dxvParameters.fHost = FALSE;
  183. SetEvent( prtInfo->hGo );
  184. EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_CONNECT ), FALSE );
  185. EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_HOST ), FALSE );
  186. }
  187. }
  188. #undef DPF_MODNAME
  189. #define DPF_MODNAME "MainDialog_HandleHost"
  190. void MainDialog_HandleHost( HWND hDlg, PDXVHELP_RTINFO prtInfo )
  191. {
  192. if( GetHostSettings( prtInfo->hInst, hDlg, &prtInfo->dxvParameters.guidCT, &prtInfo->dxvParameters.dwSessionType ) )
  193. {
  194. prtInfo->dxvParameters.fHost = TRUE;
  195. SetEvent( prtInfo->hGo );
  196. EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_CONNECT ), FALSE );
  197. EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_HOST ), FALSE );
  198. }
  199. }
  200. #undef DPF_MODNAME
  201. #define DPF_MODNAME "MainDialog_HandleScroll"
  202. void MainDialog_HandleScroll( HWND hDlg, PDXVHELP_RTINFO prtInfo )
  203. {
  204. DWORD dwPosition;
  205. DVCLIENTCONFIG dvClientConfig;
  206. dvClientConfig.dwSize = sizeof( DVCLIENTCONFIG );
  207. dwPosition = (DWORD) SendMessage( GetDlgItem( hDlg, IDC_SLIDER_RECVOLUME ), TBM_GETPOS, 0, 0 );
  208. prtInfo->dxvParameters.lRecordVolume = ((LONG) dwPosition) * ((LONG) -1);
  209. if( prtInfo->lpdvClient != NULL )
  210. {
  211. prtInfo->lpdvClient->GetClientConfig( &dvClientConfig );
  212. }
  213. dvClientConfig.lRecordVolume = prtInfo->dxvParameters.lRecordVolume;
  214. if( prtInfo->lpdvClient != NULL )
  215. {
  216. prtInfo->lpdvClient->SetClientConfig( &dvClientConfig );
  217. }
  218. }
  219. #undef DPF_MODNAME
  220. #define DPF_MODNAME "MainDialog_HandleClose"
  221. void MainDialog_HandleClose( HWND hDlg, PDXVHELP_RTINFO prtInfo )
  222. {
  223. SetEvent( prtInfo->hShutdown );
  224. DestroyWindow( hDlg );
  225. prtInfo->hMainDialog = NULL;
  226. }
  227. #undef DPF_MODNAME
  228. #define DPF_MODNAME "MainDialog_SetIdleState"
  229. void MainDialog_SetIdleState( HWND hDlg, PDXVHELP_RTINFO prtInfo )
  230. {
  231. if( hDlg == NULL )
  232. return;
  233. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_STATUS ), _T("Idle") );
  234. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_CT), _T("N/A") );
  235. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_PLAYERS ), _T("0") );
  236. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_HOST), _T("N/A") );
  237. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_TYPE), _T("N/A") );
  238. SendMessage( GetDlgItem( hDlg, IDC_SLIDER_RECVOLUME ), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 10000 ) );
  239. SendMessage( GetDlgItem( hDlg, IDC_SLIDER_RECVOLUME ), TBM_SETTICFREQ, (WPARAM) 2000, (LPARAM) 0 );
  240. SendMessage( GetDlgItem( hDlg, IDC_PROGRESS_TX ), PBM_SETRANGE, (WPARAM) 0, MAKELPARAM( 0, 100 ) );
  241. SendMessage( GetDlgItem( hDlg, IDC_PROGRESS_RX ), PBM_SETRANGE, (WPARAM) 0, MAKELPARAM( 0, 100 ) );
  242. MainDialog_DisplayVolumeSettings( hDlg, prtInfo );
  243. }
  244. #undef DPF_MODNAME
  245. #define DPF_MODNAME "MainDialog_HandleInitDialog"
  246. void MainDialog_HandleInitDialog( HWND hDlg, PDXVHELP_RTINFO prtInfo )
  247. {
  248. MainDialog_SetIdleState( hDlg, prtInfo );
  249. }
  250. #undef DPF_MODNAME
  251. #define DPF_MODNAME "MainDialog_Proc"
  252. INT_PTR CALLBACK MainDialog_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  253. {
  254. PDXVHELP_RTINFO prtInfo = g_prtInfo;
  255. switch (message)
  256. {
  257. case WM_INITDIALOG:
  258. MainDialog_HandleInitDialog( hDlg, prtInfo );
  259. return TRUE;
  260. case WM_COMMAND:
  261. if( HIWORD( wParam ) == BN_CLICKED &&
  262. LOWORD( wParam ) == IDC_CHECK_AGC )
  263. {
  264. MainDialog_HandleAGCCheck( hDlg, (HWND) lParam, prtInfo );
  265. }
  266. else if( LOWORD( wParam ) == IDC_BUTTON_CONNECT &&
  267. HIWORD( wParam ) == BN_CLICKED )
  268. {
  269. MainDialog_HandleConnect( hDlg, prtInfo );
  270. }
  271. else if( LOWORD( wParam ) == IDC_BUTTON_HOST &&
  272. HIWORD( wParam ) == BN_CLICKED )
  273. {
  274. MainDialog_HandleHost( hDlg, prtInfo );
  275. }
  276. else if( HIWORD( wParam ) == BN_CLICKED &&
  277. LOWORD( wParam ) == IDC_CHECK_ES )
  278. {
  279. MainDialog_HandleESCheck( hDlg, (HWND) lParam, prtInfo );
  280. }
  281. break;
  282. case WM_VSCROLL:
  283. MainDialog_HandleScroll( hDlg, prtInfo );
  284. break;
  285. case WM_CLOSE:
  286. MainDialog_HandleClose( hDlg, prtInfo );
  287. break;
  288. }
  289. return FALSE;
  290. }
  291. #undef DPF_MODNAME
  292. #define DPF_MODNAME "MainDialog_ShowSessionSettings"
  293. void MainDialog_ShowSessionSettings( HWND hDlg, PDXVHELP_RTINFO prtInfo )
  294. {
  295. DWORD dwSize;
  296. DVSESSIONDESC dvSessionDesc;
  297. HRESULT hr;
  298. GUID guidCT;
  299. dwSize = 0;
  300. dvSessionDesc.dwSize = sizeof( DVSESSIONDESC );
  301. hr = prtInfo->lpdvClient->GetSessionDesc( &dvSessionDesc );
  302. if( hr == DV_OK )
  303. {
  304. guidCT = dvSessionDesc.guidCT;
  305. switch( dvSessionDesc.dwSessionType )
  306. {
  307. case DVSESSIONTYPE_PEER:
  308. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_TYPE ), _T("Peer") );
  309. break;
  310. case DVSESSIONTYPE_MIXING:
  311. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_TYPE ), _T("Mixing") );
  312. break;
  313. case DVSESSIONTYPE_FORWARDING:
  314. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_TYPE ), _T("Forwarding") );
  315. break;
  316. case DVSESSIONTYPE_ECHO:
  317. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_TYPE ), _T("Echo"));
  318. break;
  319. default:
  320. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_TYPE ), _T("Unknown") );
  321. break;
  322. }
  323. LPTSTR lpstrCTName = NULL;
  324. DWORD dwLength = 0;
  325. hr = DPVDX_GetCompressionName( guidCT, lpstrCTName, &dwLength );
  326. if( hr != DVERR_BUFFERTOOSMALL )
  327. {
  328. DPVDX_DVERRDisplay( hr, _T("GetCompressionName"), FALSE );
  329. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_CT ), _T("Unknown") );
  330. }
  331. else
  332. {
  333. lpstrCTName = new TCHAR[dwLength];
  334. hr = DPVDX_GetCompressionName( guidCT, lpstrCTName, &dwLength );
  335. if( FAILED( hr ) )
  336. {
  337. DPVDX_DVERRDisplay( hr, _T("GetCompressionName"), FALSE );
  338. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_CT ), _T("Unknown") );
  339. }
  340. else
  341. {
  342. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_CT ), lpstrCTName );
  343. }
  344. delete [] lpstrCTName;
  345. }
  346. }
  347. else
  348. {
  349. DPFX(DPFPREP, DVF_ERRORLEVEL, "Error getting full session settings" );
  350. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_TYPE ), _T("Unknown" ));
  351. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_CT ), _T("Unknown") );
  352. }
  353. if( prtInfo->dxvParameters.fHost )
  354. {
  355. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_HOST ), _T("Local Host") );
  356. }
  357. else
  358. {
  359. SetWindowText( GetDlgItem( hDlg, IDC_STATIC_HOST ), _T("Remote Host") );
  360. }
  361. TCHAR szTmpString[100];
  362. _stprintf( szTmpString, _T("0x%x"), prtInfo->dpidLocalPlayer );
  363. HWND hwndTmp = GetDlgItem( hDlg, IDC_STATIC_ID );
  364. SetWindowText( hwndTmp, szTmpString );
  365. MainDialog_UpdatePlayerList( hDlg, prtInfo );
  366. return;
  367. }
  368. // Show the main dialog box
  369. #undef DPF_MODNAME
  370. #define DPF_MODNAME "MainDialog_Create"
  371. BOOL MainDialog_Create( PDXVHELP_RTINFO prtInfo )
  372. {
  373. HRESULT hr;
  374. g_prtInfo = prtInfo;
  375. prtInfo->hMainDialog = CreateDialog( prtInfo->hInst, (prtInfo->dxvParameters.fLobbyLaunched) ? MAKEINTRESOURCE( IDD_DIALOG_MAIN ) : MAKEINTRESOURCE( IDD_DIALOG_MAIN_STANDALONE ), prtInfo->hMainWnd, MainDialog_Proc );
  376. if( prtInfo->hMainDialog == NULL )
  377. {
  378. hr = GetLastError();
  379. return FALSE;
  380. }
  381. if( prtInfo->dxvParameters.fAdvancedUI )
  382. {
  383. ShowWindow( GetDlgItem( prtInfo->hMainDialog, IDC_STATIC_PLAYERS_TITLE ), TRUE );
  384. ShowWindow( GetDlgItem( prtInfo->hMainDialog, IDC_STATIC_HOST_TITLE ), TRUE );
  385. ShowWindow( GetDlgItem( prtInfo->hMainDialog, IDC_STATIC_TYPE_TITLE ), TRUE );
  386. ShowWindow( GetDlgItem( prtInfo->hMainDialog, IDC_STATIC_CT_TITLE ), TRUE );
  387. ShowWindow( GetDlgItem( prtInfo->hMainDialog, IDC_STATIC_PLAYERS ), TRUE );
  388. ShowWindow( GetDlgItem( prtInfo->hMainDialog, IDC_STATIC_HOST ), TRUE );
  389. ShowWindow( GetDlgItem( prtInfo->hMainDialog, IDC_STATIC_TYPE ), TRUE );
  390. ShowWindow( GetDlgItem( prtInfo->hMainDialog, IDC_STATIC_CT ), TRUE );
  391. }
  392. ShowWindow( prtInfo->hMainDialog, SW_SHOW );
  393. return TRUE;
  394. }