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.

289 lines
6.8 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995-1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: hostdlg.cpp
  6. * Content: Host Dialog Support Routines
  7. * History:
  8. *
  9. * Date By Reason
  10. * ==== == ======
  11. * 10/15/99 rodtoll created it
  12. * rodtoll Plugged memory leak in enumcompressiontypes
  13. * 12/07/99 rodtoll Bug #122628 Make error messages silent when running in silent mode
  14. * 03/03/2000 rodtoll Updated to handle alternative gamevoice build.
  15. * 06/28/2000 rodtoll Prefix Bug #38033,
  16. * 08/31/2000 rodtoll Prefix Bug #171843 - Out of Memory Handling Error
  17. *
  18. ***************************************************************************/
  19. #include "dxvhelppch.h"
  20. GUID g_guidCT;
  21. DWORD g_dwSessionType;
  22. #undef DPF_MODNAME
  23. #define DPF_MODNAME "HostDialog_FillCompressionPulldown"
  24. void HostDialog_FillCompressionPulldown( HWND hDlg )
  25. {
  26. HWND hPulldown = GetDlgItem( hDlg, IDC_COMBO_CT );
  27. LPDVCOMPRESSIONINFO lpdvCompressionInfo;
  28. LPBYTE lpBuffer = NULL;
  29. DWORD dwSize = 0;
  30. DWORD dwNumElements = 0;
  31. HRESULT hr;
  32. LPDIRECTPLAYVOICECLIENT lpdpvClient = NULL;
  33. LRESULT lResultIndex, lFirst;
  34. LPGUID lpGuid = NULL;
  35. hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
  36. if( FAILED( hr ) )
  37. {
  38. DPVDX_DVERRDisplay( hr, "Failure initializing COM", FALSE );
  39. return;
  40. }
  41. hr = CoCreateInstance( DPVOICE_CLSID_DPVOICE, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlayVoiceClient, (void **) &lpdpvClient );
  42. if( FAILED( hr ) )
  43. {
  44. DPVDX_DVERRDisplay( hr, "Unable to create client to get ct info", FALSE );
  45. return;
  46. }
  47. hr = lpdpvClient->GetCompressionTypes( lpBuffer, &dwSize, &dwNumElements, 0 );
  48. if( hr != DVERR_BUFFERTOOSMALL )
  49. {
  50. DPVDX_DVERRDisplay( hr, "Unable to to get ct info", FALSE );
  51. lpdpvClient->Release();
  52. return;
  53. }
  54. lpBuffer = new BYTE[dwSize];
  55. if( !lpBuffer )
  56. {
  57. DPVDX_DVERRDisplay( DVERR_OUTOFMEMORY, "Failed allocating memory", FALSE );
  58. lpdpvClient->Release();
  59. return;
  60. }
  61. hr = lpdpvClient->GetCompressionTypes( lpBuffer, &dwSize, &dwNumElements, 0 );
  62. if( FAILED( hr ) )
  63. {
  64. DPVDX_DVERRDisplay( hr, "Unable to to get ct info", FALSE );
  65. lpdpvClient->Release();
  66. return;
  67. }
  68. lpdvCompressionInfo = (LPDVCOMPRESSIONINFO) lpBuffer;
  69. LPSTR lpszName;
  70. for( DWORD dwIndex = 0; dwIndex < dwNumElements; dwIndex++ )
  71. {
  72. if( FAILED( DPVDX_AllocAndConvertToANSI( &lpszName, lpdvCompressionInfo[dwIndex].lpszName ) ) )
  73. {
  74. lResultIndex = SendMessage( hPulldown, CB_ADDSTRING, 0, (LPARAM) "Unable to convert" );
  75. }
  76. else
  77. {
  78. lResultIndex = SendMessage( hPulldown, CB_ADDSTRING, 0, (LPARAM) lpszName );
  79. delete [] lpszName;
  80. }
  81. if( dwIndex == 0 )
  82. lFirst = lResultIndex;
  83. lpGuid = new GUID;
  84. if( lpGuid == NULL )
  85. {
  86. DNASSERT( FALSE );
  87. DPVDX_DVERRDisplay( DVERR_OUTOFMEMORY, "Error allocating memory", FALSE );
  88. continue;
  89. }
  90. (*lpGuid) = lpdvCompressionInfo[dwIndex].guidType;
  91. SendMessage( hPulldown, CB_SETITEMDATA, lResultIndex, (LPARAM) lpGuid );
  92. }
  93. delete [] lpBuffer;
  94. // lFirst isn't initialized if we didn't enter the 'for' loop above
  95. if (dwIndex > 0)
  96. {
  97. SendMessage( hPulldown, CB_SETCURSEL, 0, lFirst );
  98. }
  99. lpdpvClient->Release();
  100. CoUninitialize();
  101. return;
  102. }
  103. #undef DPF_MODNAME
  104. #define DPF_MODNAME "HostDialog_FillSessionTypePulldown"
  105. void HostDialog_FillSessionTypePulldown( HWND hDlg )
  106. {
  107. HWND hPulldown = GetDlgItem( hDlg, IDC_COMBO_TYPE );
  108. LRESULT lIndex, lFirst;
  109. lFirst = SendMessage( hPulldown, CB_ADDSTRING, 0, (DWORD_PTR) "Peer To Peer" );
  110. SendMessage( hPulldown, CB_SETITEMDATA, lFirst, DVSESSIONTYPE_PEER );
  111. lIndex = SendMessage( hPulldown, CB_ADDSTRING, 0, (DWORD_PTR) "Mixing" );
  112. SendMessage( hPulldown, CB_SETITEMDATA, lIndex, DVSESSIONTYPE_MIXING );
  113. lIndex = SendMessage( hPulldown, CB_ADDSTRING, 0, (DWORD_PTR) "Multicast" );
  114. SendMessage( hPulldown, CB_SETITEMDATA, lIndex, DVSESSIONTYPE_FORWARDING );
  115. lIndex = SendMessage( hPulldown, CB_ADDSTRING, 0, (DWORD_PTR) "Echo" );
  116. SendMessage( hPulldown, CB_SETITEMDATA, lIndex, DVSESSIONTYPE_ECHO );
  117. SendMessage( hPulldown, CB_SETCURSEL, 0, lFirst );
  118. }
  119. #undef DPF_MODNAME
  120. #define DPF_MODNAME "CleanupCompressionGUIDs"
  121. void CleanupCompressionGUIDs( HWND hDlg )
  122. {
  123. LRESULT lCurSelection;
  124. LPGUID lpguidCT;
  125. lCurSelection = SendMessage( GetDlgItem( hDlg, IDC_COMBO_CT ), CB_GETCOUNT, 0, 0 );
  126. if( lCurSelection != CB_ERR )
  127. {
  128. for( LRESULT lIndex = 0; lIndex < lCurSelection; lIndex++ )
  129. {
  130. lpguidCT = (LPGUID) SendMessage( GetDlgItem( hDlg, IDC_COMBO_CT ), CB_GETITEMDATA, lIndex, 0 );
  131. if( lpguidCT )
  132. delete lpguidCT;
  133. }
  134. }
  135. }
  136. #undef DPF_MODNAME
  137. #define DPF_MODNAME "HostDialog_HandleCommandCancel"
  138. BOOL HostDialog_HandleCommandCancel( HWND hDlg )
  139. {
  140. CleanupCompressionGUIDs( hDlg );
  141. return TRUE;
  142. }
  143. #undef DPF_MODNAME
  144. #define DPF_MODNAME "HostDialog_HandleCommandOK"
  145. BOOL HostDialog_HandleCommandOK( HWND hDlg )
  146. {
  147. LRESULT lCurSelection;
  148. LPGUID lpguidCT;
  149. PDXVHELP_RTINFO prtInfo = (PDXVHELP_RTINFO) GetWindowLongPtr( hDlg, DWLP_USER );
  150. lCurSelection = SendMessage( GetDlgItem( hDlg, IDC_COMBO_CT ), CB_GETCURSEL, 0, 0 );
  151. if( lCurSelection == CB_ERR )
  152. {
  153. MessageBox( NULL, "Select a compression type!", "Error", MB_OK );
  154. return FALSE;
  155. }
  156. lpguidCT = (LPGUID) SendMessage( GetDlgItem( hDlg, IDC_COMBO_CT ), CB_GETITEMDATA, lCurSelection, 0 );
  157. if( lpguidCT != NULL )
  158. {
  159. g_guidCT = (*lpguidCT);
  160. }
  161. CleanupCompressionGUIDs( hDlg );
  162. lCurSelection = SendMessage( GetDlgItem( hDlg, IDC_COMBO_TYPE ), CB_GETCURSEL, 0, 0 );
  163. if( lCurSelection == CB_ERR )
  164. {
  165. MessageBox( NULL, "Select a session type!", "Error", MB_OK );
  166. return FALSE;
  167. }
  168. g_dwSessionType = (DWORD) SendMessage( GetDlgItem( hDlg, IDC_COMBO_TYPE ), CB_GETITEMDATA, lCurSelection, 0 );
  169. return TRUE;
  170. }
  171. #undef DPF_MODNAME
  172. #define DPF_MODNAME "HostDialog_WinProc"
  173. INT_PTR CALLBACK HostDialog_WinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  174. {
  175. switch (message)
  176. {
  177. case WM_INITDIALOG:
  178. HostDialog_FillCompressionPulldown( hDlg );
  179. HostDialog_FillSessionTypePulldown( hDlg );
  180. return TRUE;
  181. case WM_COMMAND:
  182. if (LOWORD(wParam) == IDOK )
  183. {
  184. if( !HostDialog_HandleCommandOK( hDlg ) )
  185. {
  186. return FALSE;
  187. }
  188. }
  189. else if( LOWORD(wParam) == IDCANCEL )
  190. {
  191. HostDialog_HandleCommandCancel( hDlg );
  192. }
  193. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  194. {
  195. EndDialog(hDlg, LOWORD(wParam));
  196. return TRUE;
  197. }
  198. break;
  199. }
  200. return FALSE;
  201. }
  202. #undef DPF_MODNAME
  203. #define DPF_MODNAME "GetHostSettings"
  204. BOOL GetHostSettings( HINSTANCE hInst, HWND hOwner, LPGUID pguidCT, PDWORD pdwSessionType )
  205. {
  206. g_dwSessionType = *pdwSessionType;
  207. g_guidCT = *pguidCT;
  208. if( DialogBox( hInst, MAKEINTRESOURCE( IDD_DIALOG_HOST ), hOwner, HostDialog_WinProc ) == IDOK )
  209. {
  210. *pdwSessionType = g_dwSessionType;
  211. *pguidCT = g_guidCT;
  212. return TRUE;
  213. }
  214. else
  215. {
  216. return FALSE;
  217. }
  218. }