DIALOG.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:22k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*==========================================================================
  2.  *
  3.  *  Copyright (C) 1996-1997 Microsoft Corporation.  All Rights Reserved.
  4.  *
  5.  *  File:       dialog.cpp
  6.  *  Content: Creates a dialog to query the user for connection settings
  7.  * and establish a connection.
  8.  *
  9.  ***************************************************************************/
  10. #include <windows.h>
  11. #include <windowsx.h>
  12. #include <cguid.h>
  13. #include "bellhop.h"
  14. #include "resource.h"
  15. // constants
  16. const DWORD MAXNAMELEN = 200; // max size of a session or player name
  17. const UINT TIMERID = 1; // timer ID to use
  18. const UINT TIMERINTERVAL = 1000; // timer interval
  19. // prototypes
  20. BOOL CALLBACK ConnectWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  21. BOOL CALLBACK SecurityCredentialsWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  22. HRESULT CreateDirectPlayInterface(LPDIRECTPLAY3A *lplpDirectPlay3A );
  23. HRESULT CreateDirectPlayLobbyInterface(LPDIRECTPLAYLOBBY2A *lplpDirectPlayLobby2A );
  24. BOOL FAR PASCAL DirectPlayEnumConnectionsCallback(LPCGUID lpguidSP, LPVOID lpConnection, DWORD dwSize, LPCDPNAME lpName, 
  25.   DWORD dwFlags, LPVOID lpContext);
  26. HRESULT DestroyDirectPlayInterface(HWND hWnd, LPDIRECTPLAY3A lpDirectPlay3A);
  27. HRESULT DestroyDirectPlayLobbyInterface(HWND hWnd, LPDIRECTPLAYLOBBY2A lpDirectPlayLobby2A);
  28. HRESULT JoinSession(HWND hWnd,
  29. LPDIRECTPLAY3A lpDirectPlay3A,
  30. LPDIRECTPLAYLOBBY2A lpDirectPlayLobby2A,
  31. LPGUID lpguidSessionInstance,
  32. DWORD dwSessionFlags,
  33. LPSTR lpszPlayerName,
  34. DWORD dwPlayerFlags,
  35. LPDPLAYINFO lpDPInfo);
  36. HRESULT EnumSessions(HWND hWnd, LPDIRECTPLAY3A lpDirectPlay3A);
  37. HRESULT GetConnection(HWND hWnd,  int idCombo, LPVOID *lplpConnection);
  38. HRESULT GetConnectionSPGuid(HWND hWnd, int idCombo, GUID *lpGuidSP);
  39. void DeleteConnectionList(HWND hWnd);
  40. HRESULT GetSessionInfo(HWND hWnd, LPGUID lpguidSessionInstance, LPDWORD lpdwFlags);
  41. void SelectSessionInstance(HWND hWnd, LPGUID lpguidSessionInstance);
  42. void DeleteSessionInstanceList(HWND hWnd);
  43. void EnableDlgButton(HWND hDlg, int nIDDlgItem, BOOL bEnable);
  44. ///////////////////////////////////////////////////////////////////////////////////////
  45. HRESULT ConnectUsingDialog(HINSTANCE hInstance, LPDPLAYINFO lpDPInfo)
  46. {
  47. // ask user for connection settings
  48. if (DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CONNECTDIALOG),
  49.    NULL, (DLGPROC) ConnectWndProc, (LPARAM) lpDPInfo))
  50. {
  51. return (DP_OK);
  52. }
  53. else
  54. {
  55. return (DPERR_USERCANCEL);
  56. }
  57. }
  58. ///////////////////////////////////////////////////////////////////////////////////////
  59. BOOL CALLBACK ConnectWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  60. {
  61. static LPDPLAYINFO lpDPInfo;
  62. static LPDIRECTPLAY3A lpDirectPlay3A;
  63. static LPDIRECTPLAYLOBBY2A lpDirectPlayLobby2A;
  64. static UINT idTimer;
  65. GUID guidSessionInstance;
  66. char szPlayerName[MAXNAMELEN];
  67. DWORD dwNameSize;
  68. HRESULT hr;
  69. LPVOID lpConnection = NULL;
  70. ENUMCONNSTRUCT enStruct;
  71. DWORD dwSessionFlags;
  72. DWORD dwPlayerFlags = NULL;
  73.     switch(uMsg)
  74.     {
  75.     case WM_INITDIALOG:
  76.         // save the connection info pointer
  77.         lpDPInfo = (LPDPLAYINFO) lParam;
  78. lpDirectPlay3A = NULL;
  79. lpDirectPlayLobby2A = NULL;
  80. // Create an IDirectPlay3 interface
  81. hr = CreateDirectPlayInterface(&lpDirectPlay3A);
  82. if FAILED(hr)
  83. goto SETUP_FAILURE;
  84. // Create an IDirectLobby2 interface
  85. hr = CreateDirectPlayLobbyInterface(&lpDirectPlayLobby2A);
  86. if FAILED(hr)
  87. goto SETUP_FAILURE;
  88. // set first item in the connections combo box
  89. SendDlgItemMessage(hWnd, IDC_SPCOMBO, CB_ADDSTRING, (WPARAM) 0, (LPARAM) "<Select a lobby provider>");
  90. SendDlgItemMessage(hWnd, IDC_SPCOMBO, CB_SETITEMDATA, (WPARAM) 0, (LPARAM) 0);
  91. SendDlgItemMessage(hWnd, IDC_SPCOMBO, CB_SETCURSEL, (WPARAM) 0, (LPARAM) 0);
  92. // put all the available connections in a combo box
  93. enStruct.hWnd = hWnd;
  94. enStruct.idCombo = IDC_SPCOMBO;
  95. IDirectPlay3_EnumConnections(lpDirectPlay3A, &BELLHOP_GUID, DirectPlayEnumConnectionsCallback,
  96. &enStruct, DPCONNECTION_DIRECTPLAYLOBBY);
  97. // setup initial button state
  98. EnableDlgButton(hWnd, IDC_JOINBUTTON, FALSE);
  99. EnableDlgButton(hWnd, IDC_SPECTATORBUTTON, FALSE);
  100. break;
  101. SETUP_FAILURE:
  102. ErrorBox("Could not create DirectPlay object because of error 0x%08X", hr);
  103. EndDialog(hWnd, FALSE);
  104. break;
  105. case WM_DESTROY:
  106. // delete information stored along with the lists
  107. DeleteConnectionList(hWnd);
  108. DeleteSessionInstanceList(hWnd);
  109.         break;
  110. case WM_TIMER:
  111. // refresh the session list
  112. hr = EnumSessions(hWnd, lpDirectPlay3A);
  113. break;
  114.     case WM_COMMAND:
  115.       switch(LOWORD(wParam))
  116.         {
  117. case IDC_SPCOMBO:
  118. switch (HIWORD(wParam))
  119. {
  120. case CBN_SELCHANGE:
  121. // service provider changed, so rebuild display and
  122. // delete any existing DirectPlay interface
  123. KillTimer(hWnd, idTimer ); 
  124. hr = DestroyDirectPlayInterface(hWnd, lpDirectPlay3A);
  125. lpDirectPlay3A = NULL;
  126. // get pointer to the selected connection
  127. hr = GetConnection(hWnd, IDC_SPCOMBO, &lpConnection);
  128. if FAILED(hr)
  129. goto SP_FAILURE;
  130. if (lpConnection)
  131. {
  132.   // Create a new DPlay interface.
  133. hr = CreateDirectPlayInterface(&lpDirectPlay3A);
  134. if ((FAILED(hr)) || (NULL == lpDirectPlay3A))
  135. goto SP_FAILURE;
  136. // initialize the connection
  137. hr = IDirectPlay3_InitializeConnection(lpDirectPlay3A, lpConnection, 0);
  138. if FAILED(hr)
  139. goto SP_FAILURE;
  140. // start enumerating the sessions
  141. hr = EnumSessions(hWnd, lpDirectPlay3A);
  142. if FAILED(hr)
  143. goto SP_FAILURE;
  144. // set a timer to refresh the session list
  145. idTimer = SetTimer(hWnd, TIMERID, TIMERINTERVAL, NULL);
  146. }
  147. else
  148. {
  149. // They've selected the generic option "<Select a service provider>"
  150. EnableDlgButton(hWnd, IDC_JOINBUTTON, FALSE);
  151. EnableDlgButton(hWnd, IDC_SPECTATORBUTTON, FALSE);
  152. }
  153. break;
  154. }
  155. break;
  156. SP_FAILURE:
  157. if (hr != DPERR_USERCANCEL)
  158. ErrorBox("Could not select service provider because of error 0x%08X", hr);
  159. break;
  160.         case IDC_SPECTATORBUTTON:
  161. // Joining as a spectator is the same as a regular join
  162. // just with different flags.
  163. dwPlayerFlags = DPPLAYER_SPECTATOR;
  164. // Fall through to case IDC_JOINBUTTON:
  165.         case IDC_JOINBUTTON:
  166. // should have an interface by now
  167. if (lpDirectPlay3A == NULL)
  168. break;
  169.     KillTimer(hWnd, idTimer ); 
  170. // get guid of selected session instance
  171. hr = GetSessionInfo(hWnd, &guidSessionInstance, &dwSessionFlags);
  172. if FAILED(hr)
  173. goto JOIN_FAILURE;
  174. // use computer name for player name
  175. dwNameSize = MAXNAMELEN;
  176. if (!GetComputerName(szPlayerName, &dwNameSize))
  177. lstrcpy(szPlayerName, "unknown");
  178. _strlwr(szPlayerName);
  179. // join this session
  180. hr = JoinSession( hWnd,
  181. lpDirectPlay3A,
  182.  lpDirectPlayLobby2A, 
  183.  &guidSessionInstance,
  184.  dwSessionFlags,
  185.  szPlayerName, 
  186.  dwPlayerFlags,
  187.  lpDPInfo);
  188. if FAILED(hr)
  189. goto JOIN_FAILURE;
  190. // dismiss dialog if we succeeded in joining
  191. EndDialog(hWnd, TRUE);
  192.             break;
  193. JOIN_FAILURE:
  194. ErrorBox("Could not join session because of error 0x%08X", hr);
  195. break;
  196.         case IDCANCEL:
  197. // delete any interface created if cancelling
  198. KillTimer(hWnd, idTimer ); 
  199. hr = DestroyDirectPlayInterface(hWnd, lpDirectPlay3A);
  200. lpDirectPlay3A = NULL;
  201. hr = DestroyDirectPlayLobbyInterface(hWnd, lpDirectPlayLobby2A);
  202. lpDirectPlayLobby2A = NULL;
  203. EndDialog(hWnd, FALSE);
  204.             break;
  205.         }
  206.         break;
  207.     }
  208.     // Allow for default processing
  209.     return FALSE;
  210. }
  211. ///////////////////////////////////////////////////////////////////////////////////////
  212. BOOL FAR PASCAL DirectPlayEnumConnectionsCallback(
  213. LPCGUID lpguidSP,
  214. LPVOID lpConnection,
  215. DWORD dwSize,
  216. LPCDPNAME lpName,
  217. DWORD dwFlags,
  218. LPVOID lpContext)
  219. {
  220. LPENUMCONNSTRUCT lp = (LPENUMCONNSTRUCT) lpContext;
  221.     LRESULT iIndex;
  222. LPCONNECTIONINFO lpConnectionBuffer = NULL;
  223. // store service provider name in combo box
  224. iIndex = SendDlgItemMessage(lp->hWnd, lp->idCombo, CB_ADDSTRING, 0, 
  225. (LPARAM) lpName->lpszShortNameA);
  226. if (iIndex == CB_ERR)
  227. goto FAILURE;
  228. // make space for Connection Shortcut
  229. lpConnectionBuffer = (LPCONNECTIONINFO) GlobalAllocPtr(GHND, dwSize+sizeof(CONNECTIONINFO));
  230. if (lpConnectionBuffer == NULL)
  231. goto FAILURE;
  232. // store pointer to GUID in combo box
  233. memcpy(lpConnectionBuffer->Connection, lpConnection, dwSize);
  234. lpConnectionBuffer->guidSP = *lpguidSP;
  235. SendDlgItemMessage(lp->hWnd, lp->idCombo, CB_SETITEMDATA, (WPARAM) iIndex, 
  236. (LPARAM) lpConnectionBuffer);
  237. FAILURE:
  238.     return (TRUE);
  239. }
  240. ///////////////////////////////////////////////////////////////////////////////////////
  241. HRESULT CreateDirectPlayInterface( LPDIRECTPLAY3A *lplpDirectPlay3A )
  242. {
  243. HRESULT hr;
  244. LPDIRECTPLAY3A lpDirectPlay3A = NULL;
  245. // Create an IDirectPlay3 interface
  246. hr = CoCreateInstance( CLSID_DirectPlay, NULL, CLSCTX_INPROC_SERVER, 
  247. IID_IDirectPlay3A, (LPVOID*)&lpDirectPlay3A);
  248. // return interface created
  249. *lplpDirectPlay3A = lpDirectPlay3A;
  250. return (hr);
  251. }
  252. ///////////////////////////////////////////////////////////////////////////////////////
  253. HRESULT CreateDirectPlayLobbyInterface( LPDIRECTPLAYLOBBY2A *lplpDirectPlayLobby2A )
  254. {
  255. HRESULT hr;
  256. LPDIRECTPLAYLOBBY2A lpDirectPlayLobby2A = NULL;
  257. // Create an IDirectPlay3 interface
  258. hr = CoCreateInstance( CLSID_DirectPlayLobby, NULL, CLSCTX_INPROC_SERVER, 
  259. IID_IDirectPlayLobby2A, (LPVOID*)&lpDirectPlayLobby2A);
  260. // return interface created
  261. *lplpDirectPlayLobby2A = lpDirectPlayLobby2A;
  262. return (hr);
  263. }
  264. ///////////////////////////////////////////////////////////////////////////////////////
  265. HRESULT DestroyDirectPlayInterface(HWND hWnd, LPDIRECTPLAY3A lpDirectPlay3A)
  266. {
  267. HRESULT hr = DP_OK;
  268. if (lpDirectPlay3A)
  269. {
  270. DeleteSessionInstanceList(hWnd);
  271. EnableDlgButton(hWnd, IDC_JOINBUTTON, FALSE);
  272. EnableDlgButton(hWnd, IDC_SPECTATORBUTTON, FALSE);
  273. hr = IDirectPlay3_Release(lpDirectPlay3A);
  274. }
  275. return (hr);
  276. }
  277. ///////////////////////////////////////////////////////////////////////////////////////
  278. HRESULT DestroyDirectPlayLobbyInterface(HWND hWnd, LPDIRECTPLAYLOBBY2A lpDirectPlayLobby2A)
  279. {
  280. HRESULT hr = DP_OK;
  281. if (lpDirectPlayLobby2A)
  282. {
  283. hr = lpDirectPlayLobby2A->Release();
  284. }
  285. return (hr);
  286. }
  287. ///////////////////////////////////////////////////////////////////////////////////////
  288. HRESULT JoinSession(HWND hWnd,
  289. LPDIRECTPLAY3A lpDirectPlay3A,
  290. LPDIRECTPLAYLOBBY2A lpDirectPlayLobby2A,
  291. LPGUID lpguidSessionInstance,
  292. DWORD dwSessionFlags,
  293. LPSTR lpszPlayerName,
  294. DWORD dwPlayerFlags,
  295. LPDPLAYINFO lpDPInfo)
  296. {
  297. DPID dpidPlayer;
  298. DPNAME dpName;
  299. DPSESSIONDESC2 sessionDesc;
  300. HRESULT hr;
  301. // check for valid interface
  302. if (lpDirectPlay3A == NULL)
  303. return (DPERR_INVALIDOBJECT);
  304. // Spectator or regular player
  305. lpDPInfo->dwPlayerFlags = dwPlayerFlags;
  306. // prepare a session description
  307. ZeroMemory(&sessionDesc, sizeof(DPSESSIONDESC2));
  308. sessionDesc.dwSize = sizeof(DPSESSIONDESC2);
  309.     sessionDesc.guidInstance = *lpguidSessionInstance;
  310. sessionDesc.dwFlags = dwSessionFlags;
  311. if (DPSESSION_SECURESERVER & dwSessionFlags )
  312. {
  313. hr = IDirectPlay3_SecureOpen( lpDirectPlay3A,
  314. &sessionDesc,
  315. DPOPEN_JOIN,
  316. NULL,
  317. NULL );
  318. if ( DPERR_LOGONDENIED == hr )
  319. {
  320. // we need to collect security credentials
  321. // and try again.
  322. if (DialogBoxParam( ghInstance, 
  323. MAKEINTRESOURCE(IDD_SECURITYCREDENTIALSDIALOG), 
  324. hWnd,
  325. (DLGPROC) SecurityCredentialsWndProc, 
  326. (LPARAM) &lpDPInfo))
  327. {
  328. DPCREDENTIALS dpcr;
  329. dpcr.dwSize = sizeof(DPCREDENTIALS);
  330. dpcr.dwFlags = 0;
  331. dpcr.lpszUsernameA = lpDPInfo->szSecureName;
  332. dpcr.lpszPasswordA = lpDPInfo->szSecurePassword;
  333. dpcr.lpszDomainA = lpDPInfo->szSecureDomain;
  334. hr = IDirectPlay3_SecureOpen( lpDirectPlay3A,
  335. &sessionDesc,
  336. DPOPEN_JOIN,
  337. NULL,
  338. &dpcr );
  339. if (FAILED(hr))
  340. {
  341. // Conceivably, we could cycle back and try to get credentials again
  342. // but in this sample, we'll just drop out on the error.
  343. goto OPEN_FAILURE;
  344. }
  345. lpDPInfo->bSecureSession = TRUE;
  346. }
  347. else
  348. {
  349. // abort. user clicked cancel.
  350. goto OPEN_FAILURE;
  351. }
  352. }
  353. }
  354. else
  355. {
  356. // Session does not require security
  357. hr = IDirectPlay3_Open(lpDirectPlay3A, &sessionDesc, DPOPEN_JOIN);
  358. if FAILED(hr)
  359. goto OPEN_FAILURE;
  360. }
  361. // fill out name structure
  362. ZeroMemory(&dpName, sizeof(DPNAME));
  363. dpName.dwSize = sizeof(DPNAME);
  364. dpName.lpszShortNameA = lpszPlayerName;
  365. dpName.lpszLongNameA = NULL;
  366. // create a player with this name
  367. hr = IDirectPlay3_CreatePlayer(lpDirectPlay3A, &dpidPlayer, &dpName, 
  368. lpDPInfo->hPlayerEvent,
  369. NULL, 0, dwPlayerFlags );
  370. if FAILED(hr)
  371. goto CREATEPLAYER_FAILURE;
  372. // return connection info
  373. lpDPInfo->lpDirectPlay3A = lpDirectPlay3A;
  374. lpDPInfo->lpDirectPlayLobby2A = lpDirectPlayLobby2A;
  375. lpDPInfo->dpidPlayer = dpidPlayer;
  376. lpDPInfo->bIsHost = FALSE;
  377. return (DP_OK);
  378. CREATEPLAYER_FAILURE:
  379. OPEN_FAILURE:
  380. IDirectPlay3_Close(lpDirectPlay3A);
  381. return (hr);
  382. }
  383. ///////////////////////////////////////////////////////////////////////////////////////
  384. BOOL FAR PASCAL EnumSessionsCallback(
  385. LPCDPSESSIONDESC2 lpSessionDesc,
  386. LPDWORD lpdwTimeOut,
  387. DWORD dwFlags,
  388. LPVOID lpContext)
  389. {
  390. HWND hWnd = (HWND) lpContext;
  391. LONG iIndex;
  392. char szBuffer[256];
  393. LPSESSIONINFO lpSessionInfo = NULL;
  394. // see if last session has been enumerated
  395.     if (dwFlags & DPESC_TIMEDOUT)
  396. return (FALSE);
  397. wsprintf( szBuffer, 
  398. (DPSESSION_SECURESERVER & lpSessionDesc->dwFlags ? "%s (SECURE)" : "%s" ),
  399. lpSessionDesc->lpszSessionNameA );
  400. // store session name in list
  401. iIndex = SendDlgItemMessage( hWnd, IDC_SESSIONLIST, LB_ADDSTRING, 
  402. (WPARAM) 0, (LPARAM) szBuffer);
  403. if (iIndex == LB_ERR)
  404. goto FAILURE;
  405. // make space for session instance guid
  406. lpSessionInfo = (LPSESSIONINFO) GlobalAllocPtr( GHND, sizeof(SESSIONINFO) );
  407. if (lpSessionInfo == NULL)
  408. goto FAILURE;
  409. // Extract the data we need from the session description
  410. lpSessionInfo->guidInstance = lpSessionDesc->guidInstance;
  411. lpSessionInfo->dwFlags = lpSessionDesc->dwFlags;
  412. // store pointer to guid in list
  413. SendDlgItemMessage( hWnd, IDC_SESSIONLIST, LB_SETITEMDATA, (WPARAM) iIndex, (LPARAM) lpSessionInfo);
  414. FAILURE:
  415.     return (TRUE);
  416. }
  417. ///////////////////////////////////////////////////////////////////////////////////////
  418. HRESULT EnumSessions(HWND hWnd, LPDIRECTPLAY3A lpDirectPlay3A)
  419. {
  420. DPSESSIONDESC2 sessionDesc;
  421. GUID guidSessionInstance;
  422. DWORD dwFlags;
  423. LONG iIndex;
  424. HRESULT hr;
  425. // check for valid interface
  426. if (lpDirectPlay3A == NULL)
  427. return (DPERR_INVALIDOBJECT);
  428. // get guid of currently selected session
  429. guidSessionInstance = GUID_NULL;
  430. hr = GetSessionInfo(hWnd, &guidSessionInstance, &dwFlags);
  431. // delete existing session list
  432. DeleteSessionInstanceList(hWnd);
  433. // add sessions to session list
  434. ZeroMemory(&sessionDesc, sizeof(DPSESSIONDESC2));
  435. sessionDesc.dwSize = sizeof(DPSESSIONDESC2);
  436.     sessionDesc.guidApplication = BELLHOP_GUID;
  437. hr = IDirectPlay3_EnumSessions(lpDirectPlay3A, &sessionDesc, 0, EnumSessionsCallback,
  438.   hWnd, DPENUMSESSIONS_AVAILABLE | DPENUMSESSIONS_ASYNC);
  439. // select the session that was previously selected
  440. SelectSessionInstance(hWnd, &guidSessionInstance);
  441. // hilite "Join" button only if there are sessions to join
  442. iIndex = SendDlgItemMessage(hWnd, IDC_SESSIONLIST, LB_GETCOUNT,
  443.    (WPARAM) 0, (LPARAM) 0);
  444. EnableDlgButton(hWnd, IDC_JOINBUTTON, (iIndex > 0) ? TRUE : FALSE);
  445. EnableDlgButton(hWnd, IDC_SPECTATORBUTTON, (iIndex > 0) ? TRUE : FALSE);
  446. return (hr);
  447. }
  448. ///////////////////////////////////////////////////////////////////////////////////////
  449. HRESULT GetConnection(HWND hWnd, int idCombo, LPVOID *lplpConnection)
  450. {
  451. LONG iIndex;
  452. // get index of the item currently selected in the combobox
  453. iIndex = SendDlgItemMessage(hWnd,  idCombo, CB_GETCURSEL,
  454. (WPARAM) 0, (LPARAM) 0);
  455. if (iIndex == CB_ERR)
  456. return (DPERR_GENERIC);
  457. // get the pointer to the connection shortcut associated with
  458. // the item
  459. iIndex = SendDlgItemMessage(hWnd, idCombo, CB_GETITEMDATA,
  460. (WPARAM) iIndex, (LPARAM) 0);
  461. if ((CB_ERR == iIndex) || ( NULL == iIndex ))
  462. return (DPERR_GENERIC);
  463. *lplpConnection = &((LPCONNECTIONINFO) iIndex)->Connection;
  464. return (DP_OK);
  465. }
  466. ///////////////////////////////////////////////////////////////////////////////////////
  467. HRESULT GetConnectionSPGuid(HWND hWnd, int idCombo, GUID *lpGuidSP)
  468. {
  469. LONG iIndex;
  470. // get index of the item currently selected in the combobox
  471. iIndex = SendDlgItemMessage(hWnd,  idCombo, CB_GETCURSEL,
  472. (WPARAM) 0, (LPARAM) 0);
  473. if (iIndex == CB_ERR)
  474. return (DPERR_GENERIC);
  475. // get the pointer to the connection shortcut associated with
  476. // the item
  477. iIndex = SendDlgItemMessage(hWnd, idCombo, CB_GETITEMDATA,
  478. (WPARAM) iIndex, (LPARAM) 0);
  479. if ((iIndex == CB_ERR) || (iIndex == NULL ))
  480. return (DPERR_GENERIC);
  481. *lpGuidSP = ((LPCONNECTIONINFO) iIndex)->guidSP;
  482. return (DP_OK);
  483. }
  484. ///////////////////////////////////////////////////////////////////////////////////////
  485. void DeleteConnectionList(HWND hWnd)
  486. {
  487. WPARAM i;
  488. LONG lpData;
  489. // destroy the GUID's stored with each service provider name
  490. i = 0;
  491. while (TRUE)
  492. {
  493. // get data pointer stored with item
  494. lpData = SendDlgItemMessage(hWnd, IDC_SPCOMBO, CB_GETITEMDATA,
  495. (WPARAM) i, (LPARAM) 0);
  496. if (lpData == CB_ERR) // error getting data
  497. break;
  498. if (lpData != 0) // no data to delete
  499. GlobalFreePtr((LPVOID) lpData);
  500. i += 1;
  501. }
  502. // delete all items in combo box
  503. SendDlgItemMessage(hWnd, IDC_SPCOMBO, CB_RESETCONTENT,
  504. (WPARAM) 0, (LPARAM) 0);
  505. }
  506. ///////////////////////////////////////////////////////////////////////////////////////
  507. HRESULT GetSessionInfo(HWND hWnd, LPGUID lpguidSessionInstance, LPDWORD lpdwFlags)
  508. {
  509. LONG iIndex;
  510. LPSESSIONINFO lp;
  511. // get guid for session
  512. iIndex = SendDlgItemMessage(hWnd, IDC_SESSIONLIST, LB_GETCURSEL,
  513. (WPARAM) 0, (LPARAM) 0);
  514. if (iIndex == LB_ERR)
  515. return (DPERR_GENERIC);
  516. iIndex = SendDlgItemMessage(hWnd, IDC_SESSIONLIST, LB_GETITEMDATA,
  517. (WPARAM) iIndex, (LPARAM) 0);
  518. if ((iIndex == LB_ERR) || (iIndex == 0))
  519. return (DPERR_GENERIC);
  520. lp = (LPSESSIONINFO) iIndex;
  521. *lpguidSessionInstance = lp->guidInstance;
  522. *lpdwFlags = lp->dwFlags;
  523. return (DP_OK);
  524. }
  525. ///////////////////////////////////////////////////////////////////////////////////////
  526. void DeleteSessionInstanceList(HWND hWnd)
  527. {
  528. WPARAM i;
  529. LONG lpData;
  530. // destroy the GUID's stored with each session name
  531. i = 0;
  532. while (TRUE)
  533. {
  534. // get data pointer stored with item
  535. lpData = SendDlgItemMessage(hWnd, IDC_SESSIONLIST, LB_GETITEMDATA,
  536. (WPARAM) i, (LPARAM) 0);
  537. if (lpData == CB_ERR) // error getting data
  538. break;
  539. if (lpData == 0) // no data to delete
  540. continue;
  541. GlobalFreePtr((LPVOID) lpData);
  542. i += 1;
  543. }
  544. // delete all items in list
  545. SendDlgItemMessage(hWnd, IDC_SESSIONLIST, LB_RESETCONTENT,
  546. (WPARAM) 0, (LPARAM) 0);
  547. }
  548. ///////////////////////////////////////////////////////////////////////////////////////
  549. void SelectSessionInstance(HWND hWnd, LPGUID lpguidSessionInstance)
  550. {
  551. WPARAM i, iIndex;
  552. LONG lpData;
  553. // loop over the GUID's stored with each session name
  554. // to find the one that matches what was passed in
  555. i = 0;
  556. iIndex = 0;
  557. while (TRUE)
  558. {
  559. // get data pointer stored with item
  560. lpData = SendDlgItemMessage(hWnd, IDC_SESSIONLIST, LB_GETITEMDATA,
  561. (WPARAM) i, (LPARAM) 0);
  562. if (lpData == CB_ERR) // error getting data
  563. break;
  564. if (lpData == 0) // no data to compare to
  565. continue;
  566. // guid matches
  567. if (IsEqualGUID(*lpguidSessionInstance, *((LPGUID) lpData)))
  568. {
  569. iIndex = i; // store index of this string
  570. break;
  571. }
  572. i += 1;
  573. }
  574. // select this item
  575. SendDlgItemMessage(hWnd, IDC_SESSIONLIST, LB_SETCURSEL, (WPARAM) iIndex, (LPARAM) 0);
  576. }
  577. ///////////////////////////////////////////////////////////////////////////////////////
  578. void EnableDlgButton(HWND hDlg, int nIDDlgItem, BOOL bEnable)
  579. {
  580. EnableWindow(GetDlgItem(hDlg, nIDDlgItem), bEnable);
  581. }
  582. ///////////////////////////////////////////////////////////////////////////////////////
  583. BOOL CALLBACK SecurityCredentialsWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  584. {
  585. static LPDPLAYINFO lpDPInfo;
  586. HWND hwndName = NULL,
  587. hwndPassword = NULL,
  588. hwndDomain = NULL;
  589.     switch(uMsg)
  590.     {
  591.     case WM_INITDIALOG:
  592.         lpDPInfo = (LPDPLAYINFO) lParam;
  593. break;
  594.     case WM_COMMAND:
  595.       switch(LOWORD(wParam))
  596.         {
  597. case IDOK:
  598. hwndName = GetDlgItem( hWnd, IDC_SECURENAME );
  599. hwndPassword = GetDlgItem( hWnd, IDC_SECUREPASSWORD );
  600. hwndDomain = GetDlgItem( hWnd, IDC_SECUREDOMAIN );
  601. Edit_GetText(hwndName, lpDPInfo->szSecureName, 256);
  602. Edit_GetText(hwndPassword, lpDPInfo->szSecurePassword, 256);
  603. Edit_GetText(hwndDomain, lpDPInfo->szSecureDomain, 256);
  604. EndDialog(hWnd, TRUE);
  605. break;
  606.         case IDCANCEL:
  607. EndDialog(hWnd, FALSE);
  608.             break;
  609.         }
  610.         break;
  611.     }
  612.     // Allow for default processing
  613.     return FALSE;
  614. }