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.

186 lines
4.6 KiB

  1. // WMICtrSysmonDlg.cpp : Implementation of CWMICtrSysmonDlg
  2. #include "precomp.h"
  3. #include "WMICtrSysmonDlg.h"
  4. /////////////////////////////////////////////////////////////////////////////
  5. // CWMICtrSysmonDlg
  6. CWMICtrSysmonDlg::CWMICtrSysmonDlg()
  7. {
  8. _tcscpy(m_strMachineName,_T(""));
  9. m_eStatus = Status_Success;
  10. m_hWndBusy = new HWND;
  11. }
  12. CWMICtrSysmonDlg::CWMICtrSysmonDlg(LPCTSTR strMachName)
  13. {
  14. _tcsncpy(m_strMachineName,strMachName, ARRAYSIZE(m_strMachineName));
  15. m_eStatus = Status_Success;
  16. m_hWndBusy = new HWND;
  17. }
  18. CWMICtrSysmonDlg::~CWMICtrSysmonDlg()
  19. {
  20. if(m_hWndBusy != NULL)
  21. {
  22. SendMessage(*(m_hWndBusy),WM_CLOSE_BUSY_DLG,0,0);
  23. delete m_hWndBusy;
  24. }
  25. }
  26. LRESULT CWMICtrSysmonDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  27. {
  28. CWmiCtrsDlg pDlg;
  29. DisplayBusyDialog();
  30. TCHAR strCtr[1024];
  31. ISystemMonitor *pSysMon = NULL;
  32. HRESULT hr = GetDlgControl(IDC_SYSMON_OCX,__uuidof(ISystemMonitor)/*IID_ISystemMonitor*/,(void **)&pSysMon);
  33. if(SUCCEEDED(hr))
  34. {
  35. ICounters *pCounters = NULL;
  36. pCounters = pSysMon->GetCounters();
  37. try
  38. {
  39. _tcscpy(strCtr,m_strMachineName);
  40. _tcscat(strCtr,_T("\\WINMGMT Counters\\Connections"));
  41. pCounters->Add(strCtr);
  42. _tcscpy(strCtr,m_strMachineName);
  43. _tcscat(strCtr,_T("\\WINMGMT Counters\\Delivery Backup (Bytes)"));
  44. pCounters->Add(strCtr);
  45. _tcscpy(strCtr,m_strMachineName);
  46. _tcscat(strCtr,_T("\\WINMGMT Counters\\Internal Objects"));
  47. pCounters->Add(strCtr);
  48. _tcscpy(strCtr,m_strMachineName);
  49. _tcscat(strCtr,_T("\\WINMGMT Counters\\Internal Sinks"));
  50. pCounters->Add(strCtr);
  51. _tcscpy(strCtr,m_strMachineName);
  52. _tcscat(strCtr,_T("\\WINMGMT Counters\\Tasks In Progress"));
  53. pCounters->Add(strCtr);
  54. _tcscpy(strCtr,m_strMachineName);
  55. _tcscat(strCtr,_T("\\WINMGMT Counters\\Tasks Waiting"));
  56. pCounters->Add(strCtr);
  57. _tcscpy(strCtr,m_strMachineName);
  58. _tcscat(strCtr,_T("\\WINMGMT Counters\\Total API calls"));
  59. pCounters->Add(strCtr);
  60. _tcscpy(strCtr,m_strMachineName);
  61. _tcscat(strCtr,_T("\\WINMGMT Counters\\Users"));
  62. pCounters->Add(strCtr);
  63. CloseBusyDialog();
  64. }
  65. catch(...)
  66. {
  67. m_eStatus = Status_CounterNotFound;
  68. CloseBusyDialog();
  69. EndDialog(0);
  70. }
  71. }
  72. /* else
  73. {
  74. MessageBox(_T("Could not get the Interface Pointer"),_T("Failure"));
  75. }
  76. */
  77. return 1; // Let the system set the focus
  78. }
  79. LRESULT CWMICtrSysmonDlg::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  80. {
  81. EndDialog(wID);
  82. return 0;
  83. }
  84. LRESULT CWMICtrSysmonDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  85. {
  86. EndDialog(wID);
  87. return 0;
  88. }
  89. void CWMICtrSysmonDlg::DisplayBusyDialog()
  90. {
  91. DWORD dwThreadId;
  92. m_hThread = CreateThread(NULL,0,BusyThread,(LPVOID)this,0,&dwThreadId);
  93. }
  94. DWORD WINAPI BusyThread(LPVOID lpParameter)
  95. {
  96. CWMICtrSysmonDlg *pDlg = (CWMICtrSysmonDlg *)lpParameter;
  97. INT_PTR ret = DialogBoxParam(_Module.GetModuleInstance(),
  98. MAKEINTRESOURCE(IDD_ANIMATE),
  99. NULL, BusyAVIDlgProc,
  100. (LPARAM)pDlg);
  101. return (DWORD) ret;
  102. }
  103. void CWMICtrSysmonDlg::CloseBusyDialog()
  104. {
  105. if(m_hWndBusy != NULL)
  106. {
  107. //Now close the busy Dialog
  108. ::SendMessage(*(m_hWndBusy),WM_CLOSE_BUSY_DLG,0,0);
  109. }
  110. ::SetForegroundWindow(this->m_hWnd);
  111. }
  112. INT_PTR CALLBACK BusyAVIDlgProc(HWND hwndDlg,
  113. UINT uMsg,
  114. WPARAM wParam,
  115. LPARAM lParam)
  116. {
  117. BOOL retval = FALSE;
  118. switch(uMsg)
  119. {
  120. case WM_INITDIALOG:
  121. {//BEGIN
  122. //lParam = ANIMCONFIG *
  123. CWMICtrSysmonDlg *pDlg = (CWMICtrSysmonDlg *)lParam;
  124. SetWindowLongPtr(hwndDlg, DWLP_USER, (LPARAM)pDlg);
  125. *(pDlg->m_hWndBusy) = hwndDlg;
  126. HWND hAnim = GetDlgItem(hwndDlg, IDC_ANIMATE);
  127. HWND hMsg = GetDlgItem(hwndDlg, IDC_MSG);
  128. Animate_Open(hAnim, MAKEINTRESOURCE(IDR_AVIWAIT));
  129. TCHAR caption[100] = {0}, msg[256] = {0};
  130. ::LoadString(_Module.GetModuleInstance(), IDS_DISPLAY_NAME, caption, 100);
  131. ::LoadString(_Module.GetModuleInstance(), IDS_CONNECTING, msg, 256);
  132. SetWindowText(hwndDlg, caption);
  133. SetWindowText(hMsg, msg);
  134. retval = TRUE;
  135. break;
  136. }
  137. case WM_CLOSE_BUSY_DLG:
  138. {
  139. EndDialog(hwndDlg, IDCANCEL);
  140. break;
  141. }
  142. case WM_COMMAND:
  143. {
  144. // they're only one button.
  145. if(HIWORD(wParam) == BN_CLICKED)
  146. {
  147. EndDialog(hwndDlg, IDCANCEL);
  148. }
  149. retval = TRUE; // I processed it.
  150. break;
  151. }
  152. case WM_DESTROY:
  153. {// BEGIN
  154. retval = TRUE; // I processed it.
  155. break;
  156. } //END
  157. default:
  158. {
  159. retval = FALSE; // I did NOT process this msg.
  160. break;
  161. }
  162. } //endswitch uMsg
  163. return retval;
  164. }