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.

948 lines
26 KiB

  1. //+---------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 1997.
  5. //
  6. // File: epoptppg.cpp
  7. //
  8. // Contents: Implements the classes CRpcOptionsPropertyPage
  9. //
  10. // Classes:
  11. //
  12. // Methods: CRpcOptionsPropertyPage::CRpcOptionsPropertyPage
  13. // CRpcOptionsPropertyPage::~CRpcOptionsPropertyPage
  14. //
  15. // History: 02-Dec-96 RonanS Created.
  16. //
  17. //----------------------------------------------------------------------
  18. #include "stdafx.h"
  19. #include "olecnfg.h"
  20. #include "resource.h"
  21. #include "Epoptppg.h"
  22. #include "Epprops.h"
  23. #include "TChar.h"
  24. #include "util.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CRpcOptionsPropertyPage property page
  32. IMPLEMENT_DYNCREATE(CRpcOptionsPropertyPage, CPropertyPage)
  33. //+-------------------------------------------------------------------------
  34. //
  35. // Member: CRpcOptionsPropertyPage::CRpcOptionsPropertyPage
  36. //
  37. // Synopsis: Constructor
  38. //
  39. // Arguments: None
  40. //
  41. // Returns: Nothing
  42. //
  43. // Algorithm: N/A
  44. //
  45. // History: 02-Dec-96 Ronans Created
  46. //
  47. //--------------------------------------------------------------------------
  48. CRpcOptionsPropertyPage::CRpcOptionsPropertyPage() : CPropertyPage(CRpcOptionsPropertyPage::IDD)
  49. {
  50. //{{AFX_DATA_INIT(CRpcOptionsPropertyPage)
  51. //}}AFX_DATA_INIT
  52. m_bChanged = FALSE;
  53. // make distinguished ednpoint data description for default settings
  54. m_epSysDefault = new CEndpointData;
  55. m_nSelected = -1;
  56. }
  57. //+-------------------------------------------------------------------------
  58. //
  59. // Member: CRpcOptionsPropertyPage::~CRpcOptionsPropertyPage
  60. //
  61. // Synopsis: Destructor
  62. //
  63. // Arguments: None
  64. //
  65. // Returns: Nothing
  66. //
  67. // Algorithm: N/A
  68. //
  69. // History: 02-Dec-96 Ronans Created
  70. //
  71. //--------------------------------------------------------------------------
  72. CRpcOptionsPropertyPage::~CRpcOptionsPropertyPage()
  73. {
  74. ClearProtocols();
  75. // remove distinguished default settings descriptor
  76. if (m_epSysDefault)
  77. delete m_epSysDefault;
  78. }
  79. //+-------------------------------------------------------------------------
  80. //
  81. // Member: CRpcOptionsPropertyPage::DoDataExchange
  82. //
  83. // Synopsis: Standard method for dialog data exchange. MFC uses this to
  84. // transfer data between the controls and the C++ classes memeber variables.
  85. //
  86. // Arguments: None
  87. //
  88. // Returns: Nothing
  89. //
  90. // Algorithm: N/A
  91. //
  92. // History: 02-Dec-96 Ronans Created
  93. //
  94. //--------------------------------------------------------------------------
  95. void CRpcOptionsPropertyPage::DoDataExchange(CDataExchange* pDX)
  96. {
  97. CPropertyPage::DoDataExchange(pDX);
  98. //{{AFX_DATA_MAP(CRpcOptionsPropertyPage)
  99. DDX_Control(pDX, IDC_LSTPROTSEQ, m_lstProtseqs);
  100. DDX_Control(pDX, IDC_CMDUPDATE, m_btnUpdate);
  101. DDX_Control(pDX, IDC_CMDREMOVE, m_btnRemove);
  102. DDX_Control(pDX, IDC_CMDCLEAR, m_btnClear);
  103. DDX_Control(pDX, IDC_CMDADD, m_btnAdd);
  104. //}}AFX_DATA_MAP
  105. }
  106. BEGIN_MESSAGE_MAP(CRpcOptionsPropertyPage, CPropertyPage)
  107. //{{AFX_MSG_MAP(CRpcOptionsPropertyPage)
  108. ON_BN_CLICKED(IDC_CMDCLEAR, OnClearEndpoints)
  109. ON_BN_CLICKED(IDC_CMDREMOVE, OnRemoveEndpoint)
  110. ON_BN_CLICKED(IDC_CMDUPDATE, OnUpdateEndpoint)
  111. ON_BN_CLICKED(IDC_CMDADD, OnAddEndpoint)
  112. ON_NOTIFY(NM_CLICK, IDC_LSTPROTSEQ, OnSelectProtseq)
  113. ON_WM_SETFOCUS()
  114. ON_WM_KILLFOCUS()
  115. ON_WM_HELPINFO()
  116. ON_NOTIFY(NM_DBLCLK, IDC_LSTPROTSEQ, OnPropertiesProtseq)
  117. //}}AFX_MSG_MAP
  118. END_MESSAGE_MAP()
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CRpcOptionsPropertyPage message handlers
  121. //+-------------------------------------------------------------------------
  122. //
  123. // Member: CRpcOptionsPropertyPage::OnInitDialog
  124. //
  125. // Synopsis: This standard MFC method will be called when the dialog is to be initialised.
  126. // It is called when the WIN32 Window object receives a WM_INITDIALOG message.
  127. //
  128. // Arguments: None
  129. //
  130. // Returns: Nothing
  131. //
  132. // Algorithm: N/A
  133. //
  134. // History: 02-Dec-96 Ronans Created
  135. //
  136. //--------------------------------------------------------------------------
  137. BOOL CRpcOptionsPropertyPage::OnInitDialog()
  138. {
  139. CPropertyPage::OnInitDialog();
  140. // setup image list control for dialog (for use with listview)
  141. m_imgNetwork.Create( IDB_IMGNETWORK, 16, 0, RGB(255,255,255));
  142. m_lstProtseqs.SetImageList(&m_imgNetwork, LVSIL_SMALL);
  143. ASSERT(m_imgNetwork.GetImageCount() == 2);
  144. RefreshEPList();
  145. return TRUE; // return TRUE unless you set the focus to a control
  146. }
  147. const TCHAR szEndpointText[] = TEXT("Endpoint");
  148. const int lenEndpoint = (sizeof(szEndpointText) / sizeof(TCHAR)) -1;
  149. //+-------------------------------------------------------------------------
  150. //
  151. // Member: CRpcOptionsPropertyPage::InitData
  152. //
  153. // Synopsis: Method to initialise options
  154. //
  155. // Arguments: None
  156. //
  157. // Returns: Nothing
  158. //
  159. // Algorithm: N/A
  160. //
  161. // History: 02-Dec-96 Ronans Created
  162. //
  163. //--------------------------------------------------------------------------
  164. void CRpcOptionsPropertyPage::InitData(CString AppName, HKEY hkAppID)
  165. {
  166. // read DCOM endpoint data from the registry
  167. ASSERT(hkAppID != NULL);
  168. HKEY hkEndpoints = NULL;
  169. DWORD dwType = REG_MULTI_SZ;
  170. DWORD dwcbBuffer = 1024;
  171. TCHAR* pszBuffer = new TCHAR[1024];
  172. ASSERT(pszBuffer != NULL);
  173. // try to read values into default sized buffer
  174. LONG lErr = RegQueryValueEx(hkAppID,
  175. TEXT("Endpoints"),
  176. 0,
  177. &dwType,
  178. (LPBYTE)pszBuffer,
  179. &dwcbBuffer);
  180. // if buffer is not big enough, extend it and reread
  181. if (lErr == ERROR_MORE_DATA)
  182. {
  183. delete pszBuffer;
  184. DWORD dwNewSize = (dwcbBuffer + 1 / sizeof(TCHAR));
  185. pszBuffer = new TCHAR[dwNewSize];
  186. if (pszBuffer)
  187. dwcbBuffer = dwNewSize;
  188. lErr = RegQueryValueEx(hkAppID,
  189. TEXT("Endpoints"),
  190. 0,
  191. &dwType,
  192. (LPBYTE)pszBuffer,
  193. &dwcbBuffer);
  194. }
  195. if ((lErr == ERROR_SUCCESS) &&
  196. (dwcbBuffer > 0) &&
  197. (dwType == REG_MULTI_SZ))
  198. {
  199. // parse each string
  200. TCHAR * lpszRegEntry = pszBuffer;
  201. while(*lpszRegEntry)
  202. {
  203. // caclulate length of entry
  204. int nLenEntry = _tcslen(lpszRegEntry);
  205. // ok its a valid endpoint so parse it
  206. TCHAR* pszProtseq = NULL;
  207. TCHAR* pszEndpointData = NULL;
  208. TCHAR* pszTmpDynamic = NULL;
  209. CEndpointData::EndpointFlags nDynamic;
  210. pszProtseq = _tcstok(lpszRegEntry, TEXT(", "));
  211. pszTmpDynamic = _tcstok(NULL, TEXT(", "));
  212. nDynamic = (CEndpointData::EndpointFlags) _ttoi(pszTmpDynamic);
  213. pszEndpointData = _tcstok(NULL, TEXT(", "));
  214. // at this point we should have the protseq, endpoint and flags
  215. // .. so add the entry
  216. // ignore result as we will continue even if one fails
  217. AddEndpoint(new CEndpointData(pszProtseq, nDynamic, pszEndpointData));
  218. lpszRegEntry += nLenEntry + 1;
  219. }
  220. }
  221. else if ((lErr != ERROR_SUCCESS) && (lErr != ERROR_FILE_NOT_FOUND))
  222. g_util.PostErrorMessage();
  223. delete pszBuffer;
  224. m_bChanged = FALSE;
  225. SetModified(FALSE);
  226. // select first item
  227. if (!m_colProtseqs.GetCount())
  228. // add default item
  229. m_colProtseqs.AddTail(m_epSysDefault);
  230. m_nSelected = 0;
  231. }
  232. //+-------------------------------------------------------------------------
  233. //
  234. // Member: CRpcOptionsPropertyPage::OnClearEndpoints
  235. //
  236. // Synopsis: Clears endpoint list and restores default settings
  237. //
  238. // Arguments: None
  239. //
  240. // Returns: Nothing
  241. //
  242. // Algorithm: N/A
  243. //
  244. // History: 02-Dec-96 Ronans Created
  245. //
  246. //--------------------------------------------------------------------------
  247. void CRpcOptionsPropertyPage::OnClearEndpoints()
  248. {
  249. // clear protocol list
  250. ClearProtocols();
  251. m_bChanged = TRUE;
  252. m_colProtseqs.AddTail(m_epSysDefault);
  253. m_nSelected = 0;
  254. RefreshEPList();
  255. SetModified(TRUE);
  256. SetFocus();
  257. }
  258. //+-------------------------------------------------------------------------
  259. //
  260. // Member: CRpcOptionsPropertyPage::OnRemoveEndpoint
  261. //
  262. // Synopsis: Updates display after removal of endpoint
  263. //
  264. // Arguments: None
  265. //
  266. // Returns: Nothing
  267. //
  268. // Algorithm: N/A
  269. //
  270. // History: 02-Dec-96 Ronans Created
  271. //
  272. //--------------------------------------------------------------------------
  273. void CRpcOptionsPropertyPage::OnRemoveEndpoint()
  274. {
  275. if (m_nSelected != (-1))
  276. {
  277. if (m_colProtseqs.GetCount() == 1)
  278. OnClearEndpoints();
  279. else
  280. {
  281. // get the corresponding endpoint data object
  282. CEndpointData * pData = (CEndpointData*) m_lstProtseqs.GetItemData(m_nSelected);
  283. POSITION pos = m_colProtseqs. Find(pData, NULL);
  284. if (pos)
  285. {
  286. // remove item
  287. m_colProtseqs.RemoveAt(pos);
  288. if (pData != m_epSysDefault)
  289. delete pData;
  290. // update item focus
  291. if (m_nSelected >= m_colProtseqs.GetCount())
  292. m_nSelected = -1;
  293. UpdateData(FALSE);
  294. m_bChanged = TRUE;
  295. SetModified(TRUE);
  296. RefreshEPList();
  297. SetFocus();
  298. }
  299. }
  300. }
  301. }
  302. //+-------------------------------------------------------------------------
  303. //
  304. // Member: CRpcOptionsPropertyPage::OnUpdateEndpoint
  305. //
  306. // Synopsis: Called to process update command btn on existing endpoint
  307. //
  308. // Arguments: None
  309. //
  310. // Returns: Nothing
  311. //
  312. // Algorithm: N/A
  313. //
  314. // History: 02-Dec-96 Ronans Created
  315. //
  316. //--------------------------------------------------------------------------
  317. void CRpcOptionsPropertyPage::OnUpdateEndpoint()
  318. {
  319. // if there's a current selection (should always be the case)
  320. if (m_nSelected != -1)
  321. {
  322. // get the corresponding endpoint data object
  323. CEndpointData * pData = (CEndpointData*) m_lstProtseqs.GetItemData(m_nSelected);
  324. if (pData != m_epSysDefault)
  325. {
  326. CEndpointDetails ced;
  327. ced.SetOperation( CEndpointDetails::opUpdateProtocol);
  328. ced.SetEndpointData(pData);
  329. if (ced.DoModal() == IDOK)
  330. {
  331. pData = ced.GetEndpointData(pData);
  332. m_bChanged = TRUE;
  333. SetModified(TRUE);
  334. RefreshEPList();
  335. }
  336. SetFocus();
  337. }
  338. }
  339. }
  340. //+-------------------------------------------------------------------------
  341. //
  342. // Member: CRpcOptionsPropertyPage::OnAddEndpoint
  343. //
  344. // Synopsis: Called to process add endpoint command button
  345. //
  346. // Arguments: None
  347. //
  348. // Returns: Nothing
  349. //
  350. // Algorithm: N/A
  351. //
  352. // History: 02-Dec-96 Ronans Created
  353. //
  354. //--------------------------------------------------------------------------
  355. void CRpcOptionsPropertyPage::OnAddEndpoint()
  356. {
  357. CEndpointDetails ced;
  358. ced.SetOperation( CEndpointDetails::opAddProtocol);
  359. if (ced.DoModal() == IDOK)
  360. {
  361. // create new endpoint
  362. CEndpointData *pNewEndpoint = new CEndpointData();
  363. ASSERT(pNewEndpoint);
  364. pNewEndpoint = ced.GetEndpointData(pNewEndpoint);
  365. ASSERT(pNewEndpoint);
  366. // check if protseq is already in collection
  367. POSITION pos = NULL;
  368. pos = m_colProtseqs.GetHeadPosition();
  369. while (pos != NULL)
  370. {
  371. CEndpointData *pEPD = (CEndpointData*)m_colProtseqs.GetNext(pos);
  372. if (pEPD -> m_pProtocol == pNewEndpoint -> m_pProtocol)
  373. {
  374. delete pNewEndpoint;
  375. pNewEndpoint = NULL;
  376. AfxMessageBox((UINT)IDS_DUPLICATE_PROTSEQ);
  377. break;
  378. }
  379. }
  380. // only add the endpoint if its not already in collection
  381. if (pNewEndpoint)
  382. {
  383. // reset old hilited item
  384. if (m_nSelected != -1)
  385. {
  386. m_lstProtseqs.SetItemState(m_nSelected, 0, LVIS_SELECTED | LVIS_FOCUSED);
  387. m_lstProtseqs.Update(m_nSelected);
  388. }
  389. // add new endpoint
  390. AddEndpoint(pNewEndpoint);
  391. // set new item in list
  392. CString sTmp;
  393. if (pNewEndpoint -> m_pProtocol)
  394. sTmp .LoadString(pNewEndpoint -> m_pProtocol -> nResidDesc);
  395. // insert item and store pointer to its associated CEndpointData
  396. int nImageNum = (pNewEndpoint -> m_nDynamicFlags != CEndpointData::edDisableEP) ? 0 : 1;
  397. m_nSelected = m_lstProtseqs.InsertItem(0, sTmp, nImageNum);
  398. if (m_nSelected != -1)
  399. {
  400. m_lstProtseqs.SetItemData(m_nSelected, (DWORD_PTR)pNewEndpoint);
  401. UpdateSelection();
  402. m_bChanged = TRUE;
  403. SetModified(TRUE);
  404. }
  405. }
  406. }
  407. SetFocus();
  408. }
  409. //+-------------------------------------------------------------------------
  410. //
  411. // Member: CRpcOptionsPropertyPage::ClearProtocols
  412. //
  413. // Synopsis: Clears protocol list
  414. //
  415. // Arguments: None
  416. //
  417. // Returns: Nothing
  418. //
  419. // Algorithm: N/A
  420. //
  421. // History: 02-Dec-96 Ronans Created
  422. //
  423. //--------------------------------------------------------------------------
  424. void CRpcOptionsPropertyPage::ClearProtocols()
  425. {
  426. // clean up endpoint data collection
  427. POSITION pos = NULL;
  428. pos = m_colProtseqs.GetHeadPosition();
  429. while (pos != NULL)
  430. {
  431. CEndpointData *pEPD = (CEndpointData*)m_colProtseqs.GetNext(pos);
  432. if (pEPD != m_epSysDefault)
  433. delete pEPD;
  434. }
  435. m_colProtseqs.RemoveAll();
  436. m_nSelected = -1;
  437. }
  438. //+-------------------------------------------------------------------------
  439. //
  440. // Member: CRpcOptionsPropertyPage::RefreshEPList
  441. //
  442. // Synopsis: Refreshes display from protocol list
  443. //
  444. // Arguments: None
  445. //
  446. // Returns: Nothing
  447. //
  448. // Algorithm: N/A
  449. //
  450. // History: 02-Dec-96 Ronans Created
  451. //
  452. //--------------------------------------------------------------------------
  453. void CRpcOptionsPropertyPage::RefreshEPList()
  454. {
  455. POSITION pos = m_colProtseqs.GetHeadPosition();
  456. // clear the list controls current contents
  457. m_lstProtseqs.DeleteAllItems();
  458. while (pos != NULL)
  459. {
  460. CString sTmp;
  461. CEndpointData *pEPD = (CEndpointData*)m_colProtseqs.GetNext(pos);
  462. if (pEPD -> m_pProtocol)
  463. sTmp .LoadString(pEPD -> m_pProtocol -> nResidDesc);
  464. // insert item and store pointer to its associated CEndpointData
  465. int nImageNum = (pEPD -> m_nDynamicFlags != CEndpointData::edDisableEP) ? 0 : 1;
  466. m_lstProtseqs.InsertItem(0, sTmp, nImageNum);
  467. m_lstProtseqs.SetItemData(0, (DWORD_PTR)pEPD);
  468. }
  469. UpdateSelection();
  470. }
  471. //+-------------------------------------------------------------------------
  472. //
  473. // Member: CRpcOptionsPropertyPage::AddEndpoint
  474. //
  475. // Synopsis: This method adds a new endpoint to the collection
  476. // of endpoints (m_colProtSeqs). If the collection justs consists of
  477. // the default endpoint, it removes it first.
  478. //
  479. // Arguments: pED - The new endpoint object to add
  480. //
  481. // Returns: Nothing
  482. //
  483. // Algorithm: N/A
  484. //
  485. // History: 02-Dec-96 Ronans Created
  486. //
  487. //--------------------------------------------------------------------------
  488. void CRpcOptionsPropertyPage::AddEndpoint(CEndpointData* pED)
  489. {
  490. // remove default item if present
  491. if ((m_colProtseqs.GetCount() == 1) &&
  492. (m_colProtseqs.GetHead() == m_epSysDefault))
  493. {
  494. m_colProtseqs.RemoveAll();
  495. if (m_lstProtseqs.GetItemCount())
  496. m_lstProtseqs.DeleteItem(0);
  497. }
  498. // add new item
  499. m_colProtseqs.AddTail(pED);
  500. m_bChanged = TRUE;
  501. }
  502. //+-------------------------------------------------------------------------
  503. //
  504. // Member: CRpcOptionsPropertyPage::OnSelectProtseq
  505. //
  506. // Synopsis: This method is called when an element is selected from the listview
  507. // containing the list of protocols and endpoints.
  508. // It updates the buttons and controls to reflect the current selection
  509. //
  510. // Arguments: Standard args for ListCtrl callbacks
  511. //
  512. // Returns: Nothing
  513. //
  514. // Algorithm: N/A
  515. //
  516. // History: 02-Dec-96 Ronans Created
  517. //
  518. //--------------------------------------------------------------------------
  519. void CRpcOptionsPropertyPage::OnSelectProtseq(NMHDR* pNMHDR, LRESULT* pResult)
  520. {
  521. m_nSelected = m_lstProtseqs.GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
  522. UpdateSelection();
  523. *pResult = 0;
  524. }
  525. //+-------------------------------------------------------------------------
  526. //
  527. // Member: CRpcOptionsPropertyPage::UpdateSelection
  528. //
  529. // Synopsis: Updates UI after protocol has been selected
  530. //
  531. // Arguments: None
  532. //
  533. // Returns: Nothing
  534. //
  535. // Algorithm: N/A
  536. //
  537. // History: 02-Dec-96 Ronans Created
  538. //
  539. //--------------------------------------------------------------------------
  540. void CRpcOptionsPropertyPage::UpdateSelection()
  541. {
  542. // check to see what buttons should be enabled
  543. if ((m_colProtseqs.GetCount() == 1) &&
  544. (m_colProtseqs.GetHead() == m_epSysDefault))
  545. {
  546. m_btnClear.EnableWindow(FALSE);
  547. m_btnRemove.EnableWindow(FALSE);
  548. m_btnUpdate.EnableWindow(FALSE);
  549. }
  550. else
  551. {
  552. m_btnClear.EnableWindow(TRUE);
  553. if (m_nSelected == -1)
  554. {
  555. m_btnRemove.EnableWindow(FALSE);
  556. m_btnUpdate.EnableWindow(FALSE);
  557. }
  558. else
  559. {
  560. // get the corresponding endpoint data object
  561. CEndpointData * pData = (CEndpointData*) m_lstProtseqs.GetItemData(m_nSelected);
  562. m_btnRemove.EnableWindow(TRUE);
  563. m_btnUpdate.EnableWindow(TRUE);
  564. }
  565. }
  566. // set up initial selection
  567. if (m_nSelected != (-1))
  568. {
  569. m_lstProtseqs.SetItemState(m_nSelected, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  570. m_lstProtseqs.Update(m_nSelected);
  571. }
  572. UpdateData(FALSE);
  573. }
  574. //+-------------------------------------------------------------------------
  575. //
  576. // Member: CRpcOptionsPropertyPage::OnSetActive
  577. //
  578. // Synopsis: Called when page is activated
  579. //
  580. // Arguments: None
  581. //
  582. // Returns: Nothing
  583. //
  584. // Algorithm: N/A
  585. //
  586. // History: 02-Dec-96 Ronans Created
  587. //
  588. //--------------------------------------------------------------------------
  589. BOOL CRpcOptionsPropertyPage::OnSetActive()
  590. {
  591. BOOL bRetval = CPropertyPage::OnSetActive();
  592. PostMessage(WM_SETFOCUS);
  593. return bRetval;
  594. }
  595. //+-------------------------------------------------------------------------
  596. //
  597. // Member: CRpcOptionsPropertyPage::OnSetFocus
  598. //
  599. // Synopsis: Called when page gets focus
  600. //
  601. // Arguments: None
  602. //
  603. // Returns: Nothing
  604. //
  605. // Algorithm: N/A
  606. //
  607. // History: 02-Dec-96 Ronans Created
  608. //
  609. //--------------------------------------------------------------------------
  610. void CRpcOptionsPropertyPage::OnSetFocus(CWnd* pOldWnd)
  611. {
  612. CPropertyPage::OnSetFocus(pOldWnd);
  613. m_lstProtseqs.SetFocus();
  614. if (m_nSelected != (-1))
  615. {
  616. m_lstProtseqs.SetItemState(m_nSelected, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  617. m_lstProtseqs.Update(m_nSelected);
  618. }
  619. else
  620. {
  621. TRACE(TEXT("Invalid state"));
  622. }
  623. }
  624. //+-------------------------------------------------------------------------
  625. //
  626. // Member: CRpcOptionsPropertyPage::OnKillFocus
  627. //
  628. // Synopsis: Called when page loses focus
  629. //
  630. // Arguments: None
  631. //
  632. // Returns: Nothing
  633. //
  634. // Algorithm: N/A
  635. //
  636. // History: 02-Dec-96 Ronans Created
  637. //
  638. //--------------------------------------------------------------------------
  639. void CRpcOptionsPropertyPage::OnKillFocus(CWnd* pNewWnd)
  640. {
  641. CPropertyPage::OnKillFocus(pNewWnd);
  642. }
  643. //+-------------------------------------------------------------------------
  644. //
  645. // Member: CRpcOptionsPropertyPage::OnKillActive
  646. //
  647. // Synopsis: Called when page is deactivated
  648. //
  649. // Arguments: None
  650. //
  651. // Returns: Nothing
  652. //
  653. // Algorithm: N/A
  654. //
  655. // History: 02-Dec-96 Ronans Created
  656. //
  657. //--------------------------------------------------------------------------
  658. BOOL CRpcOptionsPropertyPage::OnKillActive()
  659. {
  660. return CPropertyPage::OnKillActive();
  661. }
  662. //+-------------------------------------------------------------------------
  663. //
  664. // Member: CRpcOptionsPropertyPage::OnHelpInfo
  665. //
  666. // Synopsis: Called to display help info on items
  667. //
  668. // Arguments: None
  669. //
  670. // Returns: Nothing
  671. //
  672. // Algorithm: N/A
  673. //
  674. // History: 02-Dec-96 Ronans Created
  675. //
  676. //--------------------------------------------------------------------------
  677. BOOL CRpcOptionsPropertyPage::OnHelpInfo(HELPINFO* pHelpInfo)
  678. {
  679. if(-1 != pHelpInfo->iCtrlId)
  680. {
  681. WORD hiWord = 0x8000 | CRpcOptionsPropertyPage::IDD;
  682. WORD loWord = (WORD) pHelpInfo->iCtrlId;
  683. DWORD dwLong = MAKELONG(loWord,hiWord);
  684. WinHelp(dwLong, HELP_CONTEXTPOPUP);
  685. TRACE1("Help Id 0x%lx\n", dwLong);
  686. return TRUE;
  687. }
  688. else
  689. {
  690. return CPropertyPage::OnHelpInfo(pHelpInfo);
  691. }
  692. }
  693. void CRpcOptionsPropertyPage::OnPropertiesProtseq(NMHDR* pNMHDR, LRESULT* pResult)
  694. {
  695. m_nSelected = m_lstProtseqs.GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
  696. OnUpdateEndpoint();
  697. UpdateSelection();
  698. *pResult = 0;
  699. }
  700. //+-------------------------------------------------------------------------
  701. //
  702. // Member: CRpcOptionsPropertyPage::ValidateChanges
  703. //
  704. // Synopsis: To be called to validate the endpoint set before saving
  705. //
  706. // Arguments: None
  707. //
  708. // Returns: Nothing
  709. //
  710. // Algorithm: N/A
  711. //
  712. // History: 02-Dec-96 Ronans Created
  713. //
  714. //--------------------------------------------------------------------------
  715. BOOL CRpcOptionsPropertyPage::ValidateChanges()
  716. {
  717. UpdateData(TRUE);
  718. // only validate if data has changed
  719. if (m_bChanged)
  720. {
  721. // validate endpoint entries
  722. }
  723. return TRUE;
  724. }
  725. //+-------------------------------------------------------------------------
  726. //
  727. // Member: CRpcOptionsPropertyPage::UpdateChanges
  728. //
  729. // Synopsis: Called to update the changes to registry
  730. //
  731. // Arguments: None
  732. //
  733. // Returns: BOOL success flag
  734. //
  735. // Algorithm: N/A
  736. //
  737. // History: 27-Oct-97 Ronans Created
  738. //
  739. //--------------------------------------------------------------------------
  740. BOOL CRpcOptionsPropertyPage::UpdateChanges(HKEY hkAppID)
  741. {
  742. ASSERT(hkAppID != NULL);
  743. // only write the keys if there have been changes
  744. if (m_bChanged)
  745. {
  746. // write the DCOM endpoint data to the registry if necessary
  747. LONG lErr = ERROR_SUCCESS;
  748. // delete old key
  749. lErr = RegDeleteValue(hkAppID, TEXT("Endpoints"));
  750. // if we successfully deleted the old value (or
  751. // there was no old value) then write the new values
  752. if ((lErr == ERROR_SUCCESS) || (lErr == ERROR_FILE_NOT_FOUND))
  753. {
  754. POSITION pos = NULL;
  755. int inxEP = 0;
  756. int nLenRegString = 0;
  757. TCHAR * lpszBuffer , *lpszBuffer2;
  758. // calculate string length
  759. pos = m_colProtseqs.GetHeadPosition();
  760. while (pos != NULL)
  761. {
  762. CEndpointData *pEPD = (CEndpointData*)m_colProtseqs.GetNext(pos);
  763. ASSERT(pEPD != NULL);
  764. if (pEPD != m_epSysDefault)
  765. {
  766. // create string for saving
  767. CString sKeyValue;
  768. sKeyValue.Format(TEXT("%s,%d,%s"),
  769. (LPCTSTR)(pEPD -> m_szProtseq),
  770. pEPD -> m_nDynamicFlags,
  771. (LPCTSTR) pEPD -> m_szEndpoint);
  772. nLenRegString += sKeyValue.GetLength() + 1;
  773. }
  774. }
  775. // if the combined string length is zero, we don't need to write anything
  776. if (nLenRegString)
  777. {
  778. lpszBuffer2 = lpszBuffer = new TCHAR[nLenRegString+1];
  779. pos = m_colProtseqs.GetHeadPosition();
  780. while (pos != NULL)
  781. {
  782. CEndpointData *pEPD = (CEndpointData*)m_colProtseqs.GetNext(pos);
  783. if (pEPD != m_epSysDefault)
  784. {
  785. // create string for saving
  786. CString sKeyValue;
  787. sKeyValue.Format(TEXT("%s,%d,%s"),
  788. (LPCTSTR)(pEPD -> m_szProtseq),
  789. pEPD -> m_nDynamicFlags,
  790. (LPCTSTR) pEPD -> m_szEndpoint);
  791. lstrcpy(lpszBuffer2, sKeyValue);
  792. lpszBuffer2 += sKeyValue.GetLength() + 1; // skip over trailing null
  793. }
  794. }
  795. *lpszBuffer2 = 0;
  796. // write out the string
  797. lErr = RegSetValueEx(hkAppID,
  798. (LPCTSTR)TEXT("Endpoints"),
  799. NULL,
  800. REG_MULTI_SZ,
  801. (BYTE*)(LPCTSTR)lpszBuffer,
  802. (nLenRegString + 1) * sizeof(TCHAR));
  803. delete lpszBuffer;
  804. }
  805. }
  806. else
  807. g_util.PostErrorMessage();
  808. SetModified(FALSE);
  809. }
  810. return TRUE;
  811. }
  812. //+-------------------------------------------------------------------------
  813. //
  814. // Member: CRpcOptionsPropertyPage::CancelChanges
  815. //
  816. // Synopsis: Called to cancel the changes to registry
  817. //
  818. // Arguments: None
  819. //
  820. // Returns: BOOL success flag
  821. //
  822. // Algorithm: N/A
  823. //
  824. // History: 27-Oct-97 Ronans Created
  825. //
  826. //--------------------------------------------------------------------------
  827. BOOL CRpcOptionsPropertyPage::CancelChanges()
  828. {
  829. return TRUE;
  830. }