Leaked source code of windows server 2003
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.

1680 lines
46 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998.
  5. //
  6. // File: S M G E N P S P . C P P
  7. //
  8. // Contents: The rendering of the UI for the network status monitor.
  9. //
  10. // Notes:
  11. //
  12. // Author: CWill 6 Oct 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "foldinc.h"
  18. #include "ncatlui.h"
  19. #include "ncnetcon.h"
  20. #include "ncperms.h"
  21. #include "ncui.h"
  22. #include "ncreg.h"
  23. #include "nsres.h"
  24. #include "sminc.h"
  25. #include "smpsh.h"
  26. #include "windutil.h"
  27. #include "conprops.h"
  28. #include "oncommand.h"
  29. #include "pidlutil.h"
  30. #include "openfold.h"
  31. #include "..\folder\confold.h"
  32. #include "cfpidl.h"
  33. DWORD MapRSSIToWirelessSignalStrength(int iRSSI);
  34. PCWSTR PszGetRSSIString(int iRSSI);
  35. //
  36. // Function Prototypes
  37. //
  38. VOID CompressionToSz(UINT uiCompression, WCHAR* pchbuffer);
  39. //
  40. // Common Strings
  41. //
  42. extern const WCHAR c_szNetShellDll[];
  43. //
  44. // Constants
  45. //
  46. const UINT c_unLocalRefreshTimerID = 817;
  47. const INT c_iSignalStrengthIconXOffset = 24;
  48. const INT c_iSignalStrengthIconYOffset = -32;
  49. //
  50. // ShowLanErrors
  51. //
  52. static const WCHAR c_szRegKeyStatmonRoot[] = L"System\\CurrentControlSet\\Control\\Network\\Connections\\StatMon";
  53. static const WCHAR c_szShowLanErrors[] = L"ShowLanErrors";
  54. // forward declaration
  55. DWORD PropertyThread(CNetStatisticsEngine * pnse);
  56. //+---------------------------------------------------------------------------
  57. //
  58. // Member: CPspStatusMonitorGen::CPspStatusMonitorGen
  59. //
  60. // Purpose: Creator
  61. //
  62. // Arguments: None
  63. //
  64. // Returns: Nil
  65. //
  66. CPspStatusMonitorGen::CPspStatusMonitorGen() :
  67. m_psmEngineData(NULL),
  68. m_pnseStat(NULL),
  69. m_dwConPointCookie(0),
  70. m_fStats(FALSE),
  71. m_ncmType(NCM_LAN),
  72. m_ncsmType(NCSM_LAN),
  73. m_dwCharacter(0),
  74. m_dwLastUpdateStatusDisplayTick(0),
  75. m_fProcessingTimerEvent(FALSE),
  76. m_fIsFirstPage(FALSE),
  77. m_iLastSignalStrength(-100)
  78. {
  79. TraceFileFunc(ttidStatMon);
  80. }
  81. //+---------------------------------------------------------------------------
  82. //
  83. // Member: CPspStatusMonitorGen::FinalRelease
  84. //
  85. // Purpose: Called after last Release.
  86. //
  87. // Arguments: None
  88. //
  89. // Returns: Nil
  90. //
  91. VOID
  92. CPspStatusMonitorGen::FinalRelease(VOID)
  93. {
  94. TraceFileFunc(ttidStatMon);
  95. (VOID) HrCleanupGenPage();
  96. }
  97. //+---------------------------------------------------------------------------
  98. //
  99. // Member: CPspStatusMonitorGen::HrInitGenPage
  100. //
  101. // Purpose: Before the property page is populated, we have to make sure
  102. // that we have some of the required data. This method
  103. // initializes the page so that it is ready to be shown.
  104. //
  105. // Arguments: pnseNew - The statistics engine associated with this page
  106. // pncNew - The connection the page is being created for
  107. //
  108. // Returns: Error code
  109. //
  110. HRESULT
  111. CPspStatusMonitorGen::HrInitGenPage (
  112. CNetStatisticsEngine* pnseNew,
  113. INetConnection* pncNew,
  114. const DWORD * adwHelpIDs)
  115. {
  116. TraceFileFunc(ttidStatMon);
  117. HRESULT hr = S_OK;
  118. INetStatisticsEngine* pnseInter = pnseNew;
  119. AssertSz(pnseNew, "We don't have a pnseNew");
  120. // Set context help ID
  121. m_adwHelpIDs = adwHelpIDs;
  122. // Initialize the engine data
  123. //
  124. AssertSz(!m_psmEngineData, "We should't have a m_psmEngineData");
  125. DWORD dwBytes = sizeof(STATMON_ENGINEDATA);
  126. PVOID pbBuf;
  127. hr = HrCoTaskMemAlloc(dwBytes, &pbBuf);
  128. if (SUCCEEDED(hr))
  129. {
  130. m_psmEngineData = reinterpret_cast<STATMON_ENGINEDATA *>(pbBuf);
  131. ZeroMemory(m_psmEngineData, sizeof(STATMON_ENGINEDATA));
  132. }
  133. // Advise the interface
  134. //
  135. if (SUCCEEDED(hr))
  136. {
  137. IConnectionPoint* pcpStat = NULL;
  138. hr = ::HrGetPcpFromPnse(pnseInter, &pcpStat);
  139. if (SUCCEEDED(hr))
  140. {
  141. INetConnectionStatisticsNotifySink* pncsThis = this;
  142. hr = pcpStat->Advise(pncsThis, &m_dwConPointCookie);
  143. ::ReleaseObj(pcpStat);
  144. }
  145. }
  146. // Keep track of our owner
  147. //
  148. if (SUCCEEDED(hr))
  149. {
  150. AssertSz(!m_pnseStat, "We should't have a m_pnseStat");
  151. m_pnseStat = pnseNew;
  152. ::AddRefObj(pnseInter);
  153. }
  154. TraceError("CPspStatusMonitorGen::HrInitGenPage", hr);
  155. return hr;
  156. }
  157. //+---------------------------------------------------------------------------
  158. //
  159. // Member: CPspStatusMonitorGen::OnInitDialog
  160. //
  161. // Purpose: When the page comes up, initialize the fields
  162. //
  163. // Arguments: Standard command parameters
  164. //
  165. // Returns: Standard return
  166. //
  167. LRESULT
  168. CPspStatusMonitorGen::OnInitDialog (
  169. UINT uMsg,
  170. WPARAM wParam,
  171. LPARAM lParam,
  172. BOOL& bHandled)
  173. {
  174. TraceFileFunc(ttidStatMon);
  175. // initialize data member
  176. m_iStatTrans = Stat_Unknown;
  177. // Initialize the icon in the dialog by forcing it to change
  178. //
  179. UpdatePageIcon(SMDCF_TRANSMITTING | SMDCF_RECEIVING);
  180. UpdatePageIcon(SMDCF_NULL);
  181. UpdateSignalStrengthIcon(0);
  182. // Tell the CNetStatisticsEngine about our parent property sheet
  183. // so if someone attempts to bring up a statistics monitor we
  184. // can utilize the existing one
  185. //
  186. Assert(m_pnseStat);
  187. m_pnseStat->SetPropsheetWindow(GetParent());
  188. // Start our local refresh timer with a 1 second period.
  189. //
  190. SetTimer (c_unLocalRefreshTimerID, 1000, NULL);
  191. // leaving creating mode
  192. m_pnseStat->UnSetCreatingDialog();
  193. BOOL fEnableDisconnect = TRUE; // Should we disable the Disconnect button
  194. BOOL fEnableProperties = TRUE; // Should we disable the Properties button
  195. BOOL fShowErrorCount = TRUE;
  196. switch(m_ncmType)
  197. {
  198. case NCM_LAN:
  199. case NCM_BRIDGE:
  200. fEnableDisconnect = FHasPermission(NCPERM_LanConnect);
  201. fEnableProperties = FHasPermission(NCPERM_LanProperties);
  202. if(!FIsShowLanErrorRegKeySet())
  203. {
  204. fShowErrorCount = FALSE;
  205. }
  206. ::ShowWindow(GetDlgItem(IDC_TXT_ERROR), fShowErrorCount);
  207. ::ShowWindow(GetDlgItem(IDC_TXT_SM_ERROR_TRANS), fShowErrorCount);
  208. ::ShowWindow(GetDlgItem(IDC_TXT_SM_ERROR_RECV), fShowErrorCount);
  209. ::ShowWindow(GetDlgItem(IDC_FRM_LONG), fShowErrorCount);
  210. ::ShowWindow(GetDlgItem(IDC_FRM_SHORT), !fShowErrorCount); // reversed...
  211. break;
  212. case NCM_SHAREDACCESSHOST_RAS:
  213. ::SetWindowText(GetDlgItem(IDC_PSB_DISCONNECT), ::SzLoadIds(IDS_SM_PSH_DISCONNECT)); // If RAS connection, change the "Disable" button to "Disconnect"
  214. //fallthru
  215. case NCM_SHAREDACCESSHOST_LAN:
  216. {
  217. // TODO fEnableDisconnect
  218. // TODO fEnableProperties
  219. HRESULT hr;
  220. fShowErrorCount = FALSE; // no error stuff in spec
  221. }
  222. break;
  223. case NCM_TUNNEL:
  224. ::ShowWindow(GetDlgItem(IDC_TXT_SM_SPEED_LABEL), FALSE);
  225. ::ShowWindow(GetDlgItem(IDC_TXT_SM_SPEED), FALSE);
  226. //fallthru
  227. case NCM_DIRECT: // REVIEW correct?
  228. case NCM_ISDN:
  229. case NCM_PHONE:
  230. case NCM_PPPOE:
  231. fEnableDisconnect = FHasPermission(NCPERM_RasConnect);
  232. if (
  233. (m_dwCharacter & NCCF_INCOMING_ONLY) ||
  234. ((m_dwCharacter & NCCF_ALL_USERS) && !FHasPermission(NCPERM_RasAllUserProperties)) ||
  235. (!(m_dwCharacter & NCCF_ALL_USERS) && !FHasPermission(NCPERM_RasMyProperties))
  236. )
  237. {
  238. fEnableProperties = FALSE;
  239. }
  240. ::SetWindowText(GetDlgItem(IDC_PSB_DISCONNECT), ::SzLoadIds(IDS_SM_PSH_DISCONNECT)); // If RAS connection, change the "Disable" button to "Disconnect"
  241. ::ShowWindow(GetDlgItem(IDC_TXT_ERROR), fShowErrorCount);
  242. ::ShowWindow(GetDlgItem(IDC_TXT_SM_ERROR_TRANS), fShowErrorCount);
  243. ::ShowWindow(GetDlgItem(IDC_TXT_SM_ERROR_RECV), fShowErrorCount);
  244. ::ShowWindow(GetDlgItem(IDC_FRM_LONG), fShowErrorCount);
  245. ::ShowWindow(GetDlgItem(IDC_FRM_SHORT), !fShowErrorCount); // reversed...
  246. break;
  247. default:
  248. AssertSz(FALSE, "Unknown media type");
  249. break;
  250. }
  251. ::EnableWindow(::GetDlgItem(m_hWnd, IDC_PSB_DISCONNECT), fEnableDisconnect);
  252. ::EnableWindow(::GetDlgItem(m_hWnd, IDC_PSB_PROPERTIES), fEnableProperties);
  253. if (m_fIsFirstPage)
  254. {
  255. // get window handle to propertysheet
  256. HWND hwndParent=GetParent();
  257. Assert(hwndParent);
  258. // center the property sheet on desktop
  259. FCenterWindow (hwndParent, NULL);
  260. // hide the "ok" button
  261. //
  262. ::ShowWindow(::GetDlgItem(hwndParent, IDOK), FALSE);
  263. }
  264. return TRUE;
  265. }
  266. //+---------------------------------------------------------------------------
  267. //
  268. // Member: CPspStatusMonitorGen::OnSetActive
  269. //
  270. // Purpose: Enable statistics when the page has focus
  271. //
  272. // Arguments: Standard notification parameters
  273. //
  274. // Returns: Standard return
  275. //
  276. LRESULT
  277. CPspStatusMonitorGen::OnSetActive (
  278. INT idCtrl,
  279. LPNMHDR pnmh,
  280. BOOL& bHandled)
  281. {
  282. TraceFileFunc(ttidStatMon);
  283. HRESULT hr = S_OK;
  284. // Only turn them on if they are not running
  285. //
  286. if (!m_fStats)
  287. {
  288. hr = m_pnseStat->StartStatistics();
  289. m_fStats = TRUE;
  290. }
  291. // User's intent is to view statistics, so give them an immediate
  292. // refreshed view of them.
  293. //
  294. ::PostMessage (m_hWnd, PWM_UPDATE_STATUS_DISPLAY, 0, SMDCF_NULL);
  295. TraceError("CPspStatusMonitorGen::OnSetActive", hr);
  296. return LresFromHr(hr);
  297. }
  298. //+---------------------------------------------------------------------------
  299. //
  300. // Member: CPspStatusMonitorGen::OnKillActive
  301. //
  302. // Purpose: Disable statistics when the page is changed
  303. //
  304. // Arguments: Standard notification parameters
  305. //
  306. // Returns: Standard return
  307. //
  308. LRESULT
  309. CPspStatusMonitorGen::OnKillActive (
  310. INT idCtrl,
  311. LPNMHDR pnmh,
  312. BOOL& bHandled)
  313. {
  314. TraceFileFunc(ttidStatMon);
  315. HRESULT hr = S_OK;
  316. // Only turn them off if they are running
  317. //
  318. if (m_fStats)
  319. {
  320. hr = m_pnseStat->StopStatistics();
  321. m_fStats = FALSE;
  322. }
  323. TraceError("CPspStatusMonitorGen::OnKillActive", hr);
  324. return LresFromHr(hr);
  325. }
  326. //+---------------------------------------------------------------------------
  327. //
  328. // Member: CPspStatusMonitorGen::OnClose
  329. //
  330. // Purpose: Cleans up the items in the page when the dialog is being
  331. // closed
  332. //
  333. // Arguments: Standard command parameters
  334. //
  335. // Returns: Standard return
  336. //
  337. LRESULT
  338. CPspStatusMonitorGen::OnClose (
  339. UINT uMsg,
  340. WPARAM wParam,
  341. LPARAM lParam,
  342. BOOL& bHandled)
  343. {
  344. return DestroyWindow();
  345. }
  346. //+---------------------------------------------------------------------------
  347. //
  348. // Member: CPspStatusMonitorGen::OnDestroy
  349. //
  350. // Purpose: Cleans up the items in the page when the dialog is being
  351. // destroyed
  352. //
  353. // Arguments: Standard command parameters
  354. //
  355. // Returns: Standard return
  356. //
  357. LRESULT
  358. CPspStatusMonitorGen::OnDestroy (
  359. UINT uMsg,
  360. WPARAM wParam,
  361. LPARAM lParam,
  362. BOOL& bHandled)
  363. {
  364. TraceFileFunc(ttidStatMon);
  365. HWND hwndIcon = ::GetDlgItem(m_hWnd, IDI_SM_STATUS_ICON);
  366. HICON hOldIcon = reinterpret_cast<HICON>(::SendMessage(
  367. hwndIcon,
  368. STM_GETICON,
  369. 0,
  370. 0));
  371. if (hOldIcon)
  372. {
  373. DestroyIcon(hOldIcon);
  374. }
  375. HRESULT hr = S_OK;
  376. AssertSz(m_pnseStat, "We should have a m_pnseStat");
  377. // Make sure we don't get released during our destroy
  378. //
  379. ::AddRefObj(this);
  380. // Stop our local refresh timer
  381. //
  382. KillTimer (c_unLocalRefreshTimerID);
  383. // Make sure stats are in a happy state
  384. //
  385. if (m_fStats)
  386. {
  387. (VOID) m_pnseStat->StopStatistics();
  388. m_fStats = FALSE;
  389. }
  390. //
  391. // *** Do this last ***
  392. //
  393. // It is very likely this will result in the this page being destroyed
  394. // if it is the window closing
  395. //
  396. m_pnseStat->SetPropsheetWindow(NULL);
  397. // Clean up all the interfaces
  398. //
  399. hr = HrCleanupGenPage();
  400. m_iLastSignalStrength = -100;
  401. ::ReleaseObj(this);
  402. TraceError("CPspStatusMonitorGen::OnDestroy", hr);
  403. return 0;
  404. }
  405. //+---------------------------------------------------------------------------
  406. //
  407. // Member: CPspStatusMonitorGen::HrCleanupGenPage
  408. //
  409. // Purpose: Cleans out all the interfaces that are used by the open page
  410. //
  411. // Arguments: None
  412. //
  413. // Returns: Error code
  414. //
  415. HRESULT
  416. CPspStatusMonitorGen::HrCleanupGenPage (
  417. VOID)
  418. {
  419. TraceFileFunc(ttidStatMon);
  420. HRESULT hr = S_OK;
  421. INetStatisticsEngine* pnseStat = m_pnseStat;
  422. // Only disconnect if we haven't already.
  423. //
  424. if (pnseStat)
  425. {
  426. // Unadvise the interface
  427. //
  428. IConnectionPoint* pcpStat = NULL;
  429. if (m_dwConPointCookie
  430. && (SUCCEEDED(::HrGetPcpFromPnse(pnseStat, &pcpStat))))
  431. {
  432. (VOID) pcpStat->Unadvise(m_dwConPointCookie);
  433. ::ReleaseObj(pcpStat);
  434. // Very important to zero the cookie. This tells
  435. // OnStatisticsChanged that we're no longer interested in updates.
  436. //
  437. m_dwConPointCookie = 0;
  438. }
  439. if (m_psmEngineData)
  440. {
  441. CoTaskMemFree(m_psmEngineData);
  442. m_psmEngineData = NULL;
  443. }
  444. //
  445. // *** Do this last ***
  446. //
  447. // It is very likely this will result in the this page being destroyed
  448. // if it is the window closing
  449. //
  450. m_pnseStat = NULL;
  451. ::ReleaseObj(pnseStat);
  452. }
  453. TraceError("CPspStatusMonitorGen::HrCleanupGenPage", hr);
  454. return hr;
  455. }
  456. //+---------------------------------------------------------------------------
  457. //
  458. // Member: CPspStatusMonitorGen::OnContextMenu
  459. //
  460. // Purpose: When right click a control, bring up help
  461. //
  462. // Arguments: Standard command parameters
  463. //
  464. // Returns: Standard return
  465. //
  466. LRESULT
  467. CPspStatusMonitorGen::OnContextMenu(UINT uMsg,
  468. WPARAM wParam,
  469. LPARAM lParam,
  470. BOOL& fHandled)
  471. {
  472. TraceFileFunc(ttidStatMon);
  473. if (m_adwHelpIDs != NULL)
  474. {
  475. ::WinHelp(m_hWnd,
  476. c_szNetCfgHelpFile,
  477. HELP_CONTEXTMENU,
  478. (ULONG_PTR)m_adwHelpIDs);
  479. }
  480. return 0;
  481. }
  482. //+---------------------------------------------------------------------------
  483. //
  484. // Member: CPspStatusMonitorGen::OnHelp
  485. //
  486. // Purpose: When drag context help icon over a control, bring up help
  487. //
  488. // Arguments: Standard command parameters
  489. //
  490. // Returns: Standard return
  491. //
  492. LRESULT
  493. CPspStatusMonitorGen::OnHelp(UINT uMsg,
  494. WPARAM wParam,
  495. LPARAM lParam,
  496. BOOL& fHandled)
  497. {
  498. TraceFileFunc(ttidStatMon);
  499. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  500. Assert(lphi);
  501. if ((m_adwHelpIDs != NULL) && (HELPINFO_WINDOW == lphi->iContextType))
  502. {
  503. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  504. c_szNetCfgHelpFile,
  505. HELP_WM_HELP,
  506. (ULONG_PTR)m_adwHelpIDs);
  507. }
  508. return 0;
  509. }
  510. //+---------------------------------------------------------------------------
  511. //
  512. // Member: CPspStatusMonitorGen::OnDisconnect
  513. //
  514. // Purpose: When the disconnect button is hit, disconnect the connection
  515. // and closes the dialog
  516. //
  517. // Arguments: Standard notification parameters
  518. //
  519. // Returns: Standard return
  520. //
  521. LRESULT CPspStatusMonitorGen::OnDisconnect(WORD wNotifyCode, WORD wID,
  522. HWND hWndCtl, BOOL& fHandled)
  523. {
  524. TraceFileFunc(ttidStatMon);
  525. HRESULT hr = S_OK;
  526. switch (wNotifyCode)
  527. {
  528. case BN_CLICKED:
  529. case BN_DOUBLECLICKED:
  530. {
  531. hr = HrDisconnectConnection();
  532. }
  533. }
  534. TraceError("CPspStatusMonitorGen::OnDisconnect", hr);
  535. return 0;
  536. }
  537. //+---------------------------------------------------------------------------
  538. //
  539. // Member: CPspStatusMonitorGen::OnRaiseproperties
  540. //
  541. // Purpose: Bring up the property of this connection
  542. //
  543. // Arguments: Standard notification parameters
  544. //
  545. // Returns: Standard return
  546. //
  547. LRESULT CPspStatusMonitorGen::OnRaiseProperties(WORD wNotifyCode, WORD wID,
  548. HWND hWndCtl, BOOL& fHandled)
  549. {
  550. TraceFileFunc(ttidStatMon);
  551. HRESULT hr = S_OK;
  552. switch (wNotifyCode)
  553. {
  554. case BN_CLICKED:
  555. case BN_DOUBLECLICKED:
  556. {
  557. // Addref m_pnseStat object
  558. //
  559. AddRefObj(static_cast<INetStatisticsEngine *>(m_pnseStat));
  560. // Make sure the netshell.dll is not unloaded
  561. //
  562. HINSTANCE hInst = LoadLibrary(c_szNetShellDll);
  563. HANDLE hthrd = NULL;
  564. // Create the property sheet on a different thread
  565. //
  566. if (hInst)
  567. {
  568. DWORD dwThreadId;
  569. hthrd = CreateThread(NULL, STACK_SIZE_TINY,
  570. (LPTHREAD_START_ROUTINE)PropertyThread,
  571. (LPVOID)m_pnseStat, 0, &dwThreadId);
  572. }
  573. if (NULL != hthrd)
  574. {
  575. CloseHandle(hthrd);
  576. }
  577. else
  578. {
  579. /// Release m_pnseStat object on failure
  580. //
  581. ReleaseObj(static_cast<INetStatisticsEngine *>(m_pnseStat));
  582. // release the dll
  583. //
  584. if (hInst)
  585. FreeLibrary(hInst);
  586. hr = HrFromLastWin32Error();
  587. }
  588. }
  589. }
  590. TraceError("CPspStatusMonitorGen::OnRaiseproperties", hr);
  591. return 0;
  592. }
  593. DWORD PropertyThread(CNetStatisticsEngine * pnse)
  594. {
  595. HRESULT hr = S_OK;
  596. // Create a new scope since FreeLibraryAndExitThread will not call destructors on global scope
  597. {
  598. TraceFileFunc(ttidStatMon);
  599. BOOL fUninitCom = TRUE;
  600. // Initialize COM on this thread
  601. //
  602. hr = CoInitializeEx(NULL, COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED);
  603. if (RPC_E_CHANGED_MODE == hr)
  604. {
  605. hr = S_OK;
  606. fUninitCom = FALSE;
  607. }
  608. if (SUCCEEDED(hr))
  609. {
  610. INetConnection* pncMonitor = NULL;
  611. // Get the INetConnection
  612. //
  613. Assert (pnse);
  614. hr = pnse->HrGetConnectionFromBlob(&pncMonitor);
  615. if (SUCCEEDED(hr))
  616. {
  617. hr = HrRaiseConnectionProperties(NULL, pncMonitor);
  618. }
  619. ReleaseObj(pncMonitor);
  620. }
  621. if (fUninitCom)
  622. {
  623. CoUninitialize();
  624. }
  625. // release input interface
  626. ReleaseObj(static_cast<INetStatisticsEngine *>(pnse));
  627. TraceError("PropertyThread", hr);
  628. }
  629. // release the library we loaded
  630. FreeLibraryAndExitThread(GetModuleHandle(c_szNetShellDll), hr);
  631. return 1;
  632. }
  633. //+---------------------------------------------------------------------------
  634. //
  635. // Member: CPspStatusMonitorGen::HrDisconnectConnection
  636. //
  637. // Purpose: disconnect the connection and closes the dialog if succeeded
  638. //
  639. // Arguments: fConfirmed TRUE if the user has confirmed to disconnect the connection
  640. //
  641. // Returns: Standard return
  642. //
  643. HRESULT CPspStatusMonitorGen::HrDisconnectConnection(BOOL fConfirmed)
  644. {
  645. TraceFileFunc(ttidStatMon);
  646. HRESULT hr;
  647. Assert (m_pnseStat);
  648. // Get the INetConnection
  649. //
  650. INetConnection* pncMonitor;
  651. hr = m_pnseStat->HrGetConnectionFromBlob(&pncMonitor);
  652. if (SUCCEEDED(hr))
  653. {
  654. PCONFOLDPIDL pidlConnection;
  655. hr = HrCreateConFoldPidl(WIZARD_NOT_WIZARD, pncMonitor, pidlConnection);
  656. if (SUCCEEDED(hr))
  657. {
  658. CONFOLDENTRY ccfe;
  659. hr = pidlConnection.ConvertToConFoldEntry(ccfe);
  660. if (SUCCEEDED(hr))
  661. {
  662. // Get the pidl for the Connections Folder
  663. //
  664. PCONFOLDPIDLFOLDER pidlFolder;
  665. hr = HrGetConnectionsFolderPidl(pidlFolder);
  666. if (SUCCEEDED(hr))
  667. {
  668. // Get the Connections Folder object
  669. //
  670. LPSHELLFOLDER psfConnections;
  671. hr = HrGetConnectionsIShellFolder(pidlFolder, &psfConnections);
  672. if (SUCCEEDED(hr))
  673. {
  674. hr = HrOnCommandDisconnectInternal(ccfe,
  675. m_hWnd,
  676. psfConnections);
  677. ReleaseObj(psfConnections);
  678. }
  679. }
  680. }
  681. }
  682. // release INetConnection interface
  683. ReleaseObj(pncMonitor);
  684. }
  685. // If anything above failed.
  686. //
  687. if (SUCCEEDED(hr))
  688. {
  689. if (S_OK == hr)
  690. {
  691. // close the property sheet
  692. HWND hwndPS = ::GetParent(m_hWnd);
  693. // Push the Close ("Cancel") button to close dialog
  694. //
  695. ::PostMessage(hwndPS, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0),
  696. (LPARAM)::GetDlgItem(hwndPS, IDCANCEL));
  697. }
  698. else
  699. {
  700. // Disconnect confirmation canceled. Do nothing (don't close
  701. // statmon, anyway).
  702. //
  703. AssertSz(S_FALSE == hr, "Disconnect != S_OK or S_FALSE, but succeeded? What is it then?");
  704. }
  705. }
  706. else
  707. {
  708. TraceError("pncMonitor->Disconnect", hr);
  709. // Warn the user and don't close if we couldn't disconnect
  710. //
  711. ::NcMsgBox( m_hWnd,
  712. IDS_SM_ERROR_CAPTION,
  713. IDS_SM_ERROR_CANNOT_DISCONNECT,
  714. MB_ICONWARNING);
  715. }
  716. TraceError("CPspStatusMonitorGen::HrDisconnectConnection", hr);
  717. return hr;
  718. }
  719. //+---------------------------------------------------------------------------
  720. //
  721. // Member: CPspStatusMonitorGen::OnSetCursor
  722. //
  723. // Purpose: Ensure the mouse cursor over the Property Sheet is an Arrow.
  724. //
  725. // Arguments: Standard command parameters
  726. //
  727. // Returns: Standard return
  728. //
  729. LRESULT
  730. CPspStatusMonitorGen::OnSetCursor (
  731. UINT uMsg,
  732. WPARAM wParam,
  733. LPARAM lParam,
  734. BOOL& bHandled)
  735. {
  736. TraceFileFunc(ttidStatMon);
  737. if (LOWORD(lParam) == HTCLIENT)
  738. {
  739. SetCursor(LoadCursor(NULL, IDC_ARROW));
  740. }
  741. return FALSE;
  742. }
  743. LRESULT
  744. CPspStatusMonitorGen::OnTimer (
  745. UINT uMsg,
  746. WPARAM wParam,
  747. LPARAM lParam,
  748. BOOL& bHandled)
  749. {
  750. TraceFileFunc(ttidStatMon);
  751. // Prevent same-thread re-entrancy. Any Win32 call made while
  752. // processing this event that return control to the message
  753. // loop may cause this timer to fire again.
  754. //
  755. if (!m_fProcessingTimerEvent)
  756. {
  757. m_fProcessingTimerEvent = TRUE;
  758. // If we're within 200 milliseconds of the last time we updated the
  759. // status display, don't bother doing it again. This covers the case
  760. // where our timer coincides with the timer in smcent which would
  761. // would cause us to update the status display twice in rapid
  762. // succession each time the timers fire.
  763. //
  764. DWORD dwTick = GetTickCount ();
  765. if (dwTick > m_dwLastUpdateStatusDisplayTick + 200)
  766. {
  767. OnUpdateStatusDisplay (uMsg, 0, m_dwChangeFlags, bHandled);
  768. }
  769. m_fProcessingTimerEvent = FALSE;
  770. }
  771. return 0;
  772. }
  773. LRESULT
  774. CPspStatusMonitorGen::OnUpdateStatusDisplay(
  775. UINT uMsg,
  776. WPARAM wParam,
  777. LPARAM lParam,
  778. BOOL& bHandled)
  779. {
  780. TraceFileFunc(ttidStatMon);
  781. HRESULT hr = S_OK;
  782. DWORD dwChangeFlags = (DWORD)lParam;
  783. // We may be in the process of disconnecting the statistics page in
  784. // which case m_dwConPointCookie will be zero.
  785. //
  786. if (m_dwConPointCookie)
  787. {
  788. Assert (m_psmEngineData);
  789. STATMON_ENGINEDATA* psmNewData = NULL;
  790. hr = m_pnseStat->GetStatistics(&psmNewData);
  791. if (SUCCEEDED(hr) && psmNewData)
  792. {
  793. if (m_psmEngineData)
  794. {
  795. //
  796. // Display the new stats
  797. //
  798. UpdatePage(m_psmEngineData, psmNewData);
  799. // Update the icon image
  800. //
  801. UpdatePageIcon(dwChangeFlags);
  802. UpdateSignalStrengthIcon(psmNewData->SMED_802_11_SIGNAL_STRENGTH);
  803. // Note the clock tick of when we last updated
  804. // the status display.
  805. //
  806. m_dwLastUpdateStatusDisplayTick = GetTickCount();
  807. // Replace the old data with the new
  808. //
  809. CoTaskMemFree(m_psmEngineData);
  810. }
  811. m_psmEngineData = psmNewData;
  812. }
  813. }
  814. else
  815. {
  816. TraceTag (ttidStatMon,
  817. "CPspStatusMonitorGen::OnStatisticsChanged called but we've "
  818. "been closed. Ignoring.");
  819. }
  820. TraceError("CPspStatusMonitorGen::OnUpdateStatusDisplay", hr);
  821. return 0;
  822. }
  823. //+---------------------------------------------------------------------------
  824. //
  825. // Member: CPspStatusMonitorGen::OnStatisticsChanged
  826. //
  827. // Purpose: This is the callback that tell the property page that the
  828. // data on the page has changed
  829. //
  830. // Arguments: dwCookie - The cookie of the connection that has changed
  831. // dwChangeFlags - What has changed
  832. //
  833. // Returns: Error code
  834. //
  835. STDMETHODIMP
  836. CPspStatusMonitorGen::OnStatisticsChanged(
  837. DWORD dwChangeFlags)
  838. {
  839. TraceFileFunc(ttidStatMon);
  840. ::PostMessage (m_hWnd, PWM_UPDATE_STATUS_DISPLAY, 0, dwChangeFlags);
  841. return S_OK;
  842. }
  843. //+---------------------------------------------------------------------------
  844. //
  845. // Member: CPspStatusMonitorGen::UpdatePage
  846. //
  847. // Purpose: Fill the fields on the page with new data
  848. //
  849. // Arguments: pseOldData - The old stats being displayed on the page
  850. // pseNewData - The new stats being displayed on the page
  851. //
  852. // Returns: Nothing
  853. //
  854. VOID
  855. CPspStatusMonitorGen::UpdatePage (
  856. STATMON_ENGINEDATA* pseOldData,
  857. const STATMON_ENGINEDATA* pseNewData)
  858. {
  859. TraceFileFunc(ttidStatMon);
  860. AssertSz(pseOldData, "We don't have a puiOld");
  861. AssertSz(pseNewData, "We don't have a puiNew");
  862. //
  863. // Update the dialog fields
  864. //
  865. UpdatePageConnectionStatus(pseOldData, pseNewData);
  866. UpdatePageDuration(pseOldData, pseNewData);
  867. UpdatePageSpeed(pseOldData, pseNewData);
  868. // If the StatMon is not getting any bytes (a common problem with net
  869. // cards), display packets instead
  870. //
  871. if (ShouldShowPackets(pseNewData))
  872. {
  873. // Only change the label if we have to
  874. //
  875. if (Stat_Packets != m_iStatTrans)
  876. {
  877. SetDlgItemText(IDC_TXT_SM_BYTES_LABEL, ::SzLoadIds(IDS_SM_PACKETS));
  878. m_iStatTrans = Stat_Packets;
  879. // Force a refresh
  880. //
  881. pseOldData->SMED_PACKETSTRANSMITTING = 0;
  882. pseOldData->SMED_PACKETSRECEIVING = 0;
  883. }
  884. UpdatePageBytesTransmitting(pseOldData, pseNewData, Stat_Packets);
  885. UpdatePageBytesReceiving(pseOldData, pseNewData, Stat_Packets);
  886. }
  887. else
  888. {
  889. // Only change the label if we have to
  890. //
  891. if (Stat_Bytes != m_iStatTrans)
  892. {
  893. SetDlgItemText(IDC_TXT_SM_BYTES_LABEL, ::SzLoadIds(IDS_SM_BYTES));
  894. m_iStatTrans = Stat_Bytes;
  895. // Force a refresh
  896. //
  897. pseOldData->SMED_BYTESTRANSMITTING = 0;
  898. pseOldData->SMED_BYTESRECEIVING = 0;
  899. }
  900. UpdatePageBytesTransmitting(pseOldData, pseNewData, Stat_Bytes);
  901. UpdatePageBytesReceiving(pseOldData, pseNewData, Stat_Bytes);
  902. }
  903. UpdatePageCompTransmitting(pseOldData, pseNewData);
  904. UpdatePageCompReceiving(pseOldData, pseNewData);
  905. UpdatePageErrorsTransmitting(pseOldData, pseNewData);
  906. UpdatePageErrorsReceiving(pseOldData, pseNewData);
  907. }
  908. //+---------------------------------------------------------------------------
  909. //
  910. // Member: CPspStatusMonitorGen::ShouldShowPackets
  911. //
  912. // Purpose: Decided whether to show bytes or packets
  913. //
  914. // Arguments: pseNewData - The new stats being displayed on the page
  915. //
  916. // Returns: Nothing
  917. //
  918. BOOL CPspStatusMonitorGen::ShouldShowPackets(const STATMON_ENGINEDATA* pseNewData)
  919. {
  920. TraceFileFunc(ttidStatMon);
  921. return (0 == pseNewData->SMED_BYTESTRANSMITTING) && (0 == pseNewData->SMED_BYTESRECEIVING);
  922. }
  923. //+---------------------------------------------------------------------------
  924. //
  925. // Member: CPspStatusMonitorGen::UpdatePageSpeed
  926. //
  927. // Purpose: Updates the speed display on the general page
  928. //
  929. // Arguments: pseOldData - The old stats being displayed on the page
  930. // pseNewData - The new stats being displayed on the page
  931. //
  932. // Returns: Nothing
  933. //
  934. VOID
  935. CPspStatusMonitorGen::UpdatePageSpeed(
  936. const STATMON_ENGINEDATA* pseOldData,
  937. const STATMON_ENGINEDATA* pseNewData)
  938. {
  939. TraceFileFunc(ttidStatMon);
  940. AssertSz(pseOldData, "We don't have a pseOldData");
  941. AssertSz(pseNewData, "We don't have a pseNewData");
  942. // Get the data and see if either is different
  943. //
  944. if ((pseOldData->SMED_SPEEDTRANSMITTING != pseNewData->SMED_SPEEDTRANSMITTING)
  945. || (pseOldData->SMED_SPEEDRECEIVING != pseNewData->SMED_SPEEDRECEIVING))
  946. {
  947. WCHAR achBuffer[MAX_PATH];
  948. FormatTransmittingReceivingSpeed (
  949. pseNewData->SMED_SPEEDTRANSMITTING,
  950. pseNewData->SMED_SPEEDRECEIVING,
  951. achBuffer);
  952. // Set the control text.
  953. //
  954. SetDlgItemText(IDC_TXT_SM_SPEED, achBuffer);
  955. }
  956. }
  957. //+---------------------------------------------------------------------------
  958. //
  959. // Member: CPspStatusMonitorGen::UpdatePageConnectionStatus
  960. //
  961. // Purpose: Update the connections field on the property page
  962. //
  963. // Arguments: puiOldData - The old stats being displayed on the page
  964. // puiNewData - The new stats being displayed on the page
  965. //
  966. // Returns: Nothing
  967. //
  968. VOID
  969. CPspStatusMonitorGen::UpdatePageConnectionStatus(
  970. const STATMON_ENGINEDATA* pseOldData,
  971. const STATMON_ENGINEDATA* pseNewData)
  972. {
  973. TraceFileFunc(ttidStatMon);
  974. AssertSz(pseOldData, "We don't have a pseOldData");
  975. AssertSz(pseNewData, "We don't have a pseNewdata");
  976. // Update the Connection Status
  977. //
  978. if ((pseNewData->SMED_CONNECTIONSTATUS == NCS_DISCONNECTED) ||
  979. (pseOldData->SMED_CONNECTIONSTATUS != pseNewData->SMED_CONNECTIONSTATUS))
  980. {
  981. INT idsConnection = IDS_SM_CS_DISCONNECTED;
  982. // Make sure our strings are still intact
  983. AssertSz((((IDS_SM_CS_DISCONNECTED + 1) == IDS_SM_CS_CONNECTING)
  984. && ((IDS_SM_CS_DISCONNECTED + 2) == IDS_SM_CS_CONNECTED)
  985. && ((IDS_SM_CS_DISCONNECTED + 3) == IDS_SM_CS_DISCONNECTING)
  986. && ((IDS_SM_CS_DISCONNECTED + 4) == IDS_SM_CS_HARDWARE_NOT_PRESENT)
  987. && ((IDS_SM_CS_DISCONNECTED + 5) == IDS_SM_CS_HARDWARE_DISABLED)
  988. && ((IDS_SM_CS_DISCONNECTED + 6) == IDS_SM_CS_HARDWARE_MALFUNCTION)),
  989. "Some one has been messing with connection status strings");
  990. idsConnection = (IDS_SM_CS_DISCONNECTED
  991. + pseNewData->SMED_CONNECTIONSTATUS);
  992. if (idsConnection == IDS_SM_CS_DISCONNECTED)
  993. {
  994. // close the property sheet
  995. HWND hwndPS = ::GetParent(m_hWnd);
  996. TraceTag(ttidStatMon, "Closing Status Monitor page because status was: DISCONNECTED");
  997. // Push the Close ("Cancel") button to close dialog
  998. //
  999. ::PostMessage(hwndPS, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0),
  1000. (LPARAM)::GetDlgItem(hwndPS, IDCANCEL));
  1001. }
  1002. else
  1003. {
  1004. SetDlgItemText(IDC_TXT_SM_STATUS, ::SzLoadIds(idsConnection));
  1005. }
  1006. }
  1007. }
  1008. //+---------------------------------------------------------------------------
  1009. //
  1010. // Member: CPspStatusMonitorGen::UpdatePageIcon
  1011. //
  1012. // Purpose: Update the icon on the property page
  1013. //
  1014. // Arguments: dwChangeFlags - The new changed state
  1015. //
  1016. // Returns: Nothing
  1017. //
  1018. VOID
  1019. CPspStatusMonitorGen::UpdatePageIcon (
  1020. DWORD dwChangeFlags)
  1021. {
  1022. TraceFileFunc(ttidStatMon);
  1023. // If either of these have changed, change the icon
  1024. // so we'll know to update the icon
  1025. //
  1026. if (((SMDCF_TRANSMITTING | SMDCF_RECEIVING) & m_dwChangeFlags)
  1027. != ((SMDCF_TRANSMITTING | SMDCF_RECEIVING) & dwChangeFlags))
  1028. {
  1029. HICON hStatusIcon = 0;
  1030. HWND hwndIcon = NULL;
  1031. // Get the new icon
  1032. //
  1033. hStatusIcon = GetCurrentConnectionStatusIconId(m_ncmType, m_ncsmType, m_dwCharacter, dwChangeFlags);
  1034. if (hStatusIcon)
  1035. {
  1036. hwndIcon = ::GetDlgItem(m_hWnd, IDI_SM_STATUS_ICON);
  1037. // Set the icon to the new one
  1038. //
  1039. HICON hOldIcon = reinterpret_cast<HICON>(::SendMessage(
  1040. hwndIcon,
  1041. STM_SETICON,
  1042. (WPARAM)hStatusIcon,
  1043. 0));
  1044. DestroyIcon(hOldIcon);
  1045. }
  1046. }
  1047. // Keep the flags for the next update
  1048. //
  1049. m_dwChangeFlags = dwChangeFlags;
  1050. }
  1051. //+---------------------------------------------------------------------------
  1052. //
  1053. // Member: CPspStatusMonitorGen::UpdateSignalStrengthIcon
  1054. //
  1055. // Purpose: Update the icon on the property page
  1056. //
  1057. // Arguments: iRSSI - The new signal strenghth
  1058. //
  1059. // Returns: Nothing
  1060. //
  1061. inline
  1062. VOID
  1063. CPspStatusMonitorGen::UpdateSignalStrengthIcon (
  1064. INT iRSSI)
  1065. {
  1066. TraceFileFunc(ttidStatMon);
  1067. if (0 == iRSSI)
  1068. {
  1069. if (0 != m_iLastSignalStrength)
  1070. {
  1071. ::ShowWindow(::GetDlgItem(m_hWnd, IDC_TXT_SM_SIGNAL_STRENGTH), SW_HIDE);
  1072. ::ShowWindow(::GetDlgItem(m_hWnd, IDI_SM_SIGNAL_STRENGTH_ICON), SW_HIDE);
  1073. }
  1074. m_iLastSignalStrength = iRSSI;
  1075. return;
  1076. }
  1077. else
  1078. {
  1079. if (0 == m_iLastSignalStrength)
  1080. {
  1081. ::ShowWindow(::GetDlgItem(m_hWnd, IDC_TXT_SM_SIGNAL_STRENGTH), SW_SHOW);
  1082. ::ShowWindow(::GetDlgItem(m_hWnd, IDI_SM_SIGNAL_STRENGTH_ICON), SW_SHOW);
  1083. }
  1084. }
  1085. INT idStatusIcon = 0;
  1086. m_iLastSignalStrength = iRSSI;
  1087. // Get the new icon
  1088. //
  1089. idStatusIcon = IDI_802_11_LEVEL0 + MapRSSIToWirelessSignalStrength(iRSSI);
  1090. HWND hwndSignalStrength = ::GetDlgItem(m_hWnd, IDI_SM_SIGNAL_STRENGTH_ICON);
  1091. Assert(hwndSignalStrength);
  1092. if (hwndSignalStrength)
  1093. {
  1094. HDC hdcSignalStrength = ::GetDC(hwndSignalStrength);
  1095. Assert(hdcSignalStrength);
  1096. if (hdcSignalStrength)
  1097. {
  1098. HICON hIconSignalStrength = LoadIconTile(_Module.GetResourceInstance(), MAKEINTRESOURCE(idStatusIcon));
  1099. Assert(hIconSignalStrength);
  1100. if (hIconSignalStrength)
  1101. {
  1102. ::DrawIconEx(hdcSignalStrength,
  1103. c_iSignalStrengthIconXOffset,
  1104. c_iSignalStrengthIconYOffset,
  1105. hIconSignalStrength,
  1106. 48, 48, 0, NULL, DI_IMAGE | DI_MASK);
  1107. DestroyIcon(hIconSignalStrength);
  1108. }
  1109. ::ReleaseDC(hwndSignalStrength, hdcSignalStrength);
  1110. }
  1111. }
  1112. }
  1113. //+---------------------------------------------------------------------------
  1114. //
  1115. // Member: CPspStatusMonitorGen::UpdateSignalStrengthIcon
  1116. //
  1117. // Purpose: Update the icon on the property page
  1118. //
  1119. // Arguments: iRSSI - The new signal strenghth
  1120. //
  1121. // Returns: Nothing
  1122. //
  1123. LRESULT CPspStatusMonitorGen::OnPaint (
  1124. UINT uMsg,
  1125. WPARAM wParam,
  1126. LPARAM lParam,
  1127. BOOL& bHandled)
  1128. {
  1129. TraceFileFunc(ttidStatMon);
  1130. PAINTSTRUCT ps;
  1131. BeginPaint(&ps);
  1132. UpdateSignalStrengthIcon(m_iLastSignalStrength);
  1133. EndPaint(&ps);
  1134. bHandled = TRUE;
  1135. return 0;
  1136. }
  1137. //+---------------------------------------------------------------------------
  1138. //
  1139. // Member: CPspStatusMonitorGen::UpdatePageDuration
  1140. //
  1141. // Purpose: Updates the duration display on the general page
  1142. //
  1143. // Arguments: pseOldData - The old stats being displayed on the page
  1144. // pseNewData - The new stats being displayed on the page
  1145. //
  1146. // Returns: Nothing
  1147. //
  1148. VOID
  1149. CPspStatusMonitorGen::UpdatePageDuration(
  1150. const STATMON_ENGINEDATA* pseOldData,
  1151. const STATMON_ENGINEDATA* pseNewData)
  1152. {
  1153. TraceFileFunc(ttidStatMon);
  1154. AssertSz(pseOldData, "We don't have a pseOldData");
  1155. AssertSz(pseNewData, "We don't have a pseNewData");
  1156. // Get the see if either is different
  1157. //
  1158. if (pseOldData->SMED_DURATION != pseNewData->SMED_DURATION)
  1159. {
  1160. tstring strDuration;
  1161. // Format the time duration as a string
  1162. //
  1163. FormatTimeDuration(pseNewData->SMED_DURATION, &strDuration);
  1164. // Set the control
  1165. //
  1166. SetDlgItemText(IDC_TXT_SM_DURATION, strDuration.c_str());
  1167. }
  1168. }
  1169. //+---------------------------------------------------------------------------
  1170. //
  1171. // Member: CPspStatusMonitorGen::UpdatePageBytesTransmitting
  1172. //
  1173. // Purpose: Updates the bytes Transmitting display on the general page
  1174. //
  1175. // Arguments: pseOldData - The old stats being displayed on the page
  1176. // pseNewData - The new stats being displayed on the page
  1177. // iStat - The which stats to display
  1178. //
  1179. // Returns: Nothing
  1180. //
  1181. VOID
  1182. CPspStatusMonitorGen::UpdatePageBytesTransmitting(
  1183. const STATMON_ENGINEDATA* pseOldData,
  1184. const STATMON_ENGINEDATA* pseNewData,
  1185. StatTrans iStat)
  1186. {
  1187. TraceFileFunc(ttidStatMon);
  1188. AssertSz(pseOldData, "We don't have a pseOldData");
  1189. AssertSz(pseNewData, "We don't have a pseNewData");
  1190. AssertSz(((Stat_Packets == iStat) || (Stat_Bytes == iStat)), "We have an invalid iStat");
  1191. UINT64 ui64Old;
  1192. UINT64 ui64New;
  1193. if (Stat_Bytes == iStat)
  1194. {
  1195. ui64Old = pseOldData->SMED_BYTESTRANSMITTING;
  1196. ui64New = pseNewData->SMED_BYTESTRANSMITTING;
  1197. }
  1198. else
  1199. {
  1200. ui64Old = pseOldData->SMED_PACKETSTRANSMITTING;
  1201. ui64New = pseNewData->SMED_PACKETSTRANSMITTING;
  1202. }
  1203. // See if either is different
  1204. //
  1205. if (ui64Old != ui64New)
  1206. {
  1207. SetDlgItemFormatted64bitInteger(
  1208. m_hWnd,
  1209. IDC_TXT_SM_BYTES_TRANS,
  1210. ui64New, FALSE);
  1211. }
  1212. }
  1213. //+---------------------------------------------------------------------------
  1214. //
  1215. // Member: CPspStatusMonitorGen::UpdatePageBytesReceiving
  1216. //
  1217. // Purpose: Updates the bytes receiving display on the general page
  1218. //
  1219. // Arguments: puiOld - The old stats being displayed on the page
  1220. // puiNew - The new stats being displayed on the page
  1221. // iStat - The which stats to display
  1222. //
  1223. // Returns: Nothing
  1224. //
  1225. VOID
  1226. CPspStatusMonitorGen::UpdatePageBytesReceiving(
  1227. const STATMON_ENGINEDATA* pseOldData,
  1228. const STATMON_ENGINEDATA* pseNewData,
  1229. StatTrans iStat)
  1230. {
  1231. TraceFileFunc(ttidStatMon);
  1232. AssertSz(pseOldData, "We don't have a puiOld");
  1233. AssertSz(pseNewData, "We don't have a puiNew");
  1234. AssertSz(((Stat_Packets == iStat) || (Stat_Bytes == iStat)), "We have an invalid iStat");
  1235. UINT64 ui64Old;
  1236. UINT64 ui64New;
  1237. if (Stat_Bytes == iStat)
  1238. {
  1239. ui64Old = pseOldData->SMED_BYTESRECEIVING;
  1240. ui64New = pseNewData->SMED_BYTESRECEIVING;
  1241. }
  1242. else
  1243. {
  1244. ui64Old = pseOldData->SMED_PACKETSRECEIVING;
  1245. ui64New = pseNewData->SMED_PACKETSRECEIVING;
  1246. }
  1247. // See if either is different
  1248. //
  1249. if (ui64Old != ui64New)
  1250. {
  1251. SetDlgItemFormatted64bitInteger(
  1252. m_hWnd,
  1253. IDC_TXT_SM_BYTES_RCVD,
  1254. ui64New, FALSE);
  1255. }
  1256. }
  1257. //+---------------------------------------------------------------------------
  1258. //
  1259. // Member: CPspStatusMonitorGen::UpdatePageCompTransmitting
  1260. //
  1261. // Purpose: Updates the compression transmitting display on the general
  1262. // page
  1263. //
  1264. // Arguments: pseOldData - The old stats being displayed on the page
  1265. // pseNewData - The new stats being displayed on the page
  1266. //
  1267. // Returns: Nothing
  1268. //
  1269. VOID
  1270. CPspStatusMonitorGen::UpdatePageCompTransmitting(
  1271. const STATMON_ENGINEDATA* pseOldData,
  1272. const STATMON_ENGINEDATA* pseNewData)
  1273. {
  1274. TraceFileFunc(ttidStatMon);
  1275. AssertSz(pseOldData, "We don't have a pseOldData");
  1276. AssertSz(pseNewData, "We don't have a pseNewData");
  1277. // See if either is different
  1278. //
  1279. if (pseOldData->SMED_COMPRESSIONTRANSMITTING
  1280. != pseNewData->SMED_COMPRESSIONTRANSMITTING)
  1281. {
  1282. WCHAR achBuf[20];
  1283. CompressionToSz(pseNewData->SMED_COMPRESSIONTRANSMITTING, achBuf);
  1284. SetDlgItemText(IDC_TXT_SM_COMP_TRANS, achBuf);
  1285. }
  1286. }
  1287. //+---------------------------------------------------------------------------
  1288. //
  1289. // Member: CPspStatusMonitorGen::UpdatePageCompReceiving
  1290. //
  1291. // Purpose: Updates the compression receiving display on the general page
  1292. //
  1293. // Arguments: pseOldData - The old stats being displayed on the page
  1294. // pseNewData - The new stats being displayed on the page
  1295. //
  1296. // Returns: Nothing
  1297. //
  1298. VOID
  1299. CPspStatusMonitorGen::UpdatePageCompReceiving(
  1300. const STATMON_ENGINEDATA* pseOldData,
  1301. const STATMON_ENGINEDATA* pseNewData)
  1302. {
  1303. TraceFileFunc(ttidStatMon);
  1304. AssertSz(pseOldData, "We don't have a puiOld");
  1305. AssertSz(pseNewData, "We don't have a puiNew");
  1306. // see if either is different
  1307. //
  1308. if (pseOldData->SMED_COMPRESSIONRECEIVING != pseNewData->SMED_COMPRESSIONRECEIVING)
  1309. {
  1310. WCHAR achBuf[20];
  1311. CompressionToSz(pseNewData->SMED_COMPRESSIONRECEIVING, achBuf);
  1312. SetDlgItemText(IDC_TXT_SM_COMP_RCVD, achBuf);
  1313. }
  1314. }
  1315. //+---------------------------------------------------------------------------
  1316. //
  1317. // Member: CPspStatusMonitorGen::UpdatePageErrorsTransmitting
  1318. //
  1319. // Purpose: Updates the compression transmitting display on the general
  1320. // page
  1321. //
  1322. // Arguments: pseOldData - The old stats being displayed on the page
  1323. // pseNewData - The new stats being displayed on the page
  1324. //
  1325. // Returns: Nothing
  1326. //
  1327. VOID
  1328. CPspStatusMonitorGen::UpdatePageErrorsTransmitting(
  1329. const STATMON_ENGINEDATA* pseOldData,
  1330. const STATMON_ENGINEDATA* pseNewData)
  1331. {
  1332. TraceFileFunc(ttidStatMon);
  1333. AssertSz(pseOldData, "We don't have a pseOldData");
  1334. AssertSz(pseNewData, "We don't have a pseNewData");
  1335. // See if either is different
  1336. //
  1337. if (pseOldData->SMED_ERRORSTRANSMITTING
  1338. != pseNewData->SMED_ERRORSTRANSMITTING)
  1339. {
  1340. SetDlgItemFormatted32bitInteger (
  1341. m_hWnd,
  1342. IDC_TXT_SM_ERROR_TRANS,
  1343. pseNewData->SMED_ERRORSTRANSMITTING,
  1344. FALSE);
  1345. }
  1346. }
  1347. //+---------------------------------------------------------------------------
  1348. //
  1349. // Member: CPspStatusMonitorGen::UpdatePageErrorsReceiving
  1350. //
  1351. // Purpose: Updates the compression receiving display on the general page
  1352. //
  1353. // Arguments: pseOldData - The old stats being displayed on the page
  1354. // pseNewData - The new stats being displayed on the page
  1355. //
  1356. // Returns: Nothing
  1357. //
  1358. VOID
  1359. CPspStatusMonitorGen::UpdatePageErrorsReceiving(
  1360. const STATMON_ENGINEDATA* pseOldData,
  1361. const STATMON_ENGINEDATA* pseNewData)
  1362. {
  1363. TraceFileFunc(ttidStatMon);
  1364. AssertSz(pseOldData, "We don't have a pseOldData");
  1365. AssertSz(pseNewData, "We don't have a pseNewData");
  1366. // see if either is different
  1367. //
  1368. if (pseOldData->SMED_ERRORSRECEIVING != pseNewData->SMED_ERRORSRECEIVING)
  1369. {
  1370. SetDlgItemFormatted32bitInteger (
  1371. m_hWnd,
  1372. IDC_TXT_SM_ERROR_RECV,
  1373. pseNewData->SMED_ERRORSRECEIVING,
  1374. FALSE);
  1375. }
  1376. }
  1377. //+---------------------------------------------------------------------------
  1378. //
  1379. // Function: CompressionToSz
  1380. //
  1381. // Purpose: To format nicely BPS into a readable string
  1382. //
  1383. // Arguments: uiCompression - The amount of compression
  1384. // pchBuffer - The Buffer to receive the string
  1385. //
  1386. // Returns: Nothing
  1387. //
  1388. VOID
  1389. CompressionToSz (
  1390. UINT uiCompression,
  1391. WCHAR* pchBuffer)
  1392. {
  1393. TraceFileFunc(ttidStatMon);
  1394. AssertSz((((INT)uiCompression >= 0) && ((INT)uiCompression <= 100)),
  1395. "Invalid compression");
  1396. wsprintfW(pchBuffer, L"%lu %%", uiCompression);
  1397. }
  1398. //+---------------------------------------------------------------------------
  1399. //
  1400. // Function: FIsShowLanErrorRegKeySet
  1401. //
  1402. // Purpose: Check if the registry key is set:
  1403. // System\CurrentControlSet\Control\Network\Connections\StatMon\ShowLanErrors
  1404. //
  1405. // Arguments:
  1406. //
  1407. // Returns: Nothing
  1408. //
  1409. BOOL CPspStatusMonitorGen::FIsShowLanErrorRegKeySet()
  1410. {
  1411. TraceFileFunc(ttidStatMon);
  1412. BOOL fRet = FALSE;
  1413. HKEY hkeyStatmonRoot = NULL;
  1414. HRESULT hr = S_OK;
  1415. // "System\\CurrentControlSet\\Control\\Network\\Connections\\StatMon\\ShowLanErrors"
  1416. hr = ::HrRegOpenKeyEx(
  1417. HKEY_LOCAL_MACHINE,
  1418. c_szRegKeyStatmonRoot,
  1419. KEY_READ,
  1420. &hkeyStatmonRoot);
  1421. if (SUCCEEDED(hr))
  1422. {
  1423. Assert(hkeyStatmonRoot);
  1424. DWORD dwValue =0;
  1425. hr = HrRegQueryDword(hkeyStatmonRoot, c_szShowLanErrors, &dwValue);
  1426. if SUCCEEDED(hr)
  1427. {
  1428. fRet = !!dwValue;
  1429. }
  1430. RegCloseKey(hkeyStatmonRoot);
  1431. }
  1432. return fRet;
  1433. }