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.

360 lines
7.7 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1996 - 1999
  3. Module Name:
  4. MONUI.CPP
  5. Abstract:
  6. Author:
  7. Vlad Sadovsky (vlads) 12-20-96
  8. Revision History:
  9. --*/
  10. #include "precomp.h"
  11. //
  12. // Headers
  13. //
  14. #include "stiexe.h"
  15. #include "device.h"
  16. #include <windowsx.h>
  17. #include <mmsystem.h>
  18. #include "resource.h"
  19. #include "monui.h"
  20. //
  21. // Private defines
  22. //
  23. #define ELAPSE_TIME 20000
  24. extern UINT g_uiDefaultPollTimeout;
  25. CSetTimeout::CSetTimeout(
  26. int DlgID,
  27. HWND hWnd,
  28. HINSTANCE hInst,
  29. UINT uiTimeout
  30. )
  31. : BASECLASS(DlgID, hWnd, hInst),
  32. m_uiOrigTimeout(uiTimeout)
  33. {
  34. m_uiNewTimeOut = m_uiOrigTimeout;
  35. m_fAllChange = FALSE;
  36. m_fValidChange = FALSE;
  37. }
  38. CSetTimeout::~CSetTimeout()
  39. {
  40. }
  41. int CSetTimeout::OnCommand(UINT id,HWND hwndCtl, UINT codeNotify)
  42. {
  43. switch (id) {
  44. case IDOK:
  45. {
  46. CHAR szTimeoutString[10] = {'\0'};
  47. int uiNewValue;
  48. GetWindowTextA(GetDlgItem(IDC_TIMEOUT),szTimeoutString,sizeof(szTimeoutString));
  49. uiNewValue = ::atoi(szTimeoutString);
  50. if (uiNewValue != -1 ) {
  51. m_uiNewTimeOut = uiNewValue*1000;
  52. m_fValidChange = TRUE;
  53. }
  54. m_fAllChange = Button_GetCheck(GetDlgItem(IDC_CHECK_ALLDEVICES));
  55. }
  56. EndDialog(1);
  57. return 1;
  58. break;
  59. case IDCANCEL:
  60. EndDialog(0);
  61. return 1;
  62. break;
  63. }
  64. return 0;
  65. }
  66. void CSetTimeout::OnInit()
  67. {
  68. TCHAR szTimeoutString[10] = {'\0'};
  69. SendMessage(GetDlgItem(IDC_TIMEOUT), EM_LIMITTEXT, (sizeof(szTimeoutString) / sizeof(szTimeoutString[0])) -1, 0);
  70. wsprintf(szTimeoutString,TEXT("%6d"),g_uiDefaultPollTimeout/1000);
  71. Edit_SetText(GetDlgItem(IDC_TIMEOUT),szTimeoutString);
  72. Button_SetCheck(GetDlgItem(IDC_CHECK_ALLDEVICES),FALSE);
  73. }
  74. //
  75. // Dialog for selecting event processor .
  76. // It is invoked when monitor can not identify single event processor
  77. //
  78. CLaunchSelection::CLaunchSelection(
  79. int DlgID,
  80. HWND hWnd,
  81. HINSTANCE hInst,
  82. ACTIVE_DEVICE *pDev,
  83. PDEVICEEVENT pEvent,
  84. STRArray &saProcessors,
  85. StiCString &strSelected
  86. )
  87. : BASECLASS(DlgID, hWnd, hInst,ELAPSE_TIME),
  88. m_saList(saProcessors),
  89. m_strSelected(strSelected),
  90. m_uiCurSelection(0),
  91. m_pDevice(pDev),
  92. m_pEvent(pEvent),
  93. m_hPreviouslyActiveWindow(NULL)
  94. {
  95. //
  96. // Save currently active window and focus
  97. //
  98. m_hPreviouslyActiveWindow = ::GetForegroundWindow();
  99. }
  100. CLaunchSelection::~CLaunchSelection()
  101. {
  102. // Restore previous window
  103. if (IsWindow(m_hPreviouslyActiveWindow)) {
  104. ::SetForegroundWindow(m_hPreviouslyActiveWindow);
  105. }
  106. }
  107. int CLaunchSelection::OnCommand(UINT id,HWND hwndCtl, UINT codeNotify)
  108. {
  109. LRESULT lrSize;
  110. switch (id) {
  111. case IDC_APP_LIST:
  112. //
  113. // Treat double-click on the list box item just like pressing OK button
  114. // Pass through to next case if notification is about it
  115. //
  116. if (codeNotify != LBN_DBLCLK) {
  117. return FALSE;
  118. }
  119. case IDOK:
  120. {
  121. //
  122. // Save currently selected string
  123. //
  124. m_uiCurSelection = ::SendDlgItemMessage(GetWindow(), IDC_APP_LIST, LB_GETCURSEL, 0, (LPARAM) 0);
  125. lrSize = ::SendDlgItemMessage(GetWindow(), IDC_APP_LIST, LB_GETTEXTLEN, m_uiCurSelection, (LPARAM) 0);
  126. if (lrSize) {
  127. ::SendDlgItemMessage(GetWindow(), IDC_APP_LIST, LB_GETTEXT, m_uiCurSelection, (LPARAM) m_strSelected.GetBufferSetLength((INT)lrSize+1));
  128. }
  129. EndDialog(1);
  130. return TRUE;
  131. }
  132. break;
  133. case IDCANCEL:
  134. {
  135. m_strSelected.GetBufferSetLength(0);
  136. EndDialog(0);
  137. return TRUE;
  138. }
  139. break;
  140. }
  141. return FALSE;
  142. }
  143. void CLaunchSelection::OnInit()
  144. {
  145. INT iCount;
  146. //
  147. // Set caption
  148. //
  149. StiCString strCaption;
  150. DEVICE_INFO *pDeviceInfo = m_pDevice->m_DrvWrapper.getDevInfo();
  151. WCHAR *wszDesc = NULL;
  152. //
  153. // Try to get the device's friendly name
  154. //
  155. if (pDeviceInfo) {
  156. wszDesc = pDeviceInfo->wszLocalName;
  157. }
  158. //
  159. // If we don't have a description string yet, use the the device ID
  160. //
  161. if (!wszDesc) {
  162. wszDesc = m_pDevice->GetDeviceID();
  163. }
  164. strCaption.FormatMessage(IDS_APP_CHOICE_CAPTION, wszDesc);
  165. ::SetWindowText(GetWindow(),(LPCTSTR)strCaption);
  166. //
  167. // Fill list box with possible selection
  168. //
  169. if (m_saList.GetSize()) {
  170. for (iCount = 0;iCount < m_saList.GetSize();iCount++) {
  171. ::SendDlgItemMessage( GetWindow(), IDC_APP_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)*m_saList[iCount]) );
  172. }
  173. }
  174. HWND hwndThis = GetWindow();
  175. #ifdef WINNT
  176. DWORD dwProcessId;
  177. //
  178. // On Win2k we need to allow set foreground window
  179. //
  180. ::GetWindowThreadProcessId(hwndThis, &dwProcessId);
  181. ::AllowSetForegroundWindow(dwProcessId);
  182. #endif
  183. //
  184. // Make window active and foreground
  185. //
  186. ::SetActiveWindow(hwndThis);
  187. ::SetForegroundWindow(hwndThis);
  188. ::SetFocus(hwndThis);
  189. //Check: On Win9x can we bring window to top?
  190. //::BringWindowToTop(hwndThis);
  191. #ifdef WINNT
  192. //
  193. // Flash caption
  194. //
  195. FLASHWINFO fwi;
  196. DWORD dwError;
  197. fwi.cbSize = sizeof fwi;
  198. fwi.hwnd = GetWindow();
  199. fwi.dwFlags = FLASHW_ALL;
  200. fwi.uCount = 10;
  201. dwError = FlashWindowEx(&fwi);
  202. #endif
  203. //
  204. // Attract user attention
  205. //
  206. #ifdef PLAYSOUND
  207. ::PlaySound("SystemQuestion",NULL,SND_ALIAS | SND_ASYNC | SND_NOWAIT | SND_NOSTOP);
  208. #endif
  209. }
  210. BOOL
  211. CALLBACK
  212. CLaunchSelection::DlgProc(
  213. HWND hDlg,
  214. UINT uMessage,
  215. WPARAM wParam,
  216. LPARAM lParam
  217. )
  218. {
  219. switch (uMessage) {
  220. case WM_TIMER:
  221. {
  222. return TRUE;
  223. }
  224. break;
  225. }
  226. return FALSE;
  227. }
  228. DWORD
  229. DisplayPopup (
  230. IN DWORD dwMessageId,
  231. IN DWORD dwMessageFlags // = 0
  232. )
  233. /*++
  234. Routine Description:
  235. Puts up a popup for the corresponding message ID.
  236. Arguments:
  237. MessageId - the message ID to display. It is assumed to be in a
  238. resource in this executable.
  239. Return Value:
  240. None.
  241. --*/
  242. {
  243. DWORD cch = NO_ERROR;
  244. LPTSTR messageText = NULL;
  245. DWORD dwError;
  246. StiCString strCaption;
  247. strCaption.LoadString(STIEXE_EVENT_TITLE);
  248. cch = ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  249. FORMAT_MESSAGE_MAX_WIDTH_MASK |
  250. FORMAT_MESSAGE_FROM_HMODULE,
  251. ::GetModuleHandle(NULL) ,
  252. dwMessageId,
  253. 0,
  254. (LPTSTR) &messageText,
  255. 1024,
  256. NULL
  257. );
  258. dwError = GetLastError();
  259. if (!cch || !messageText || !strCaption.GetLength()) {
  260. return 0;
  261. }
  262. dwError = MessageBox(
  263. NULL,
  264. messageText,
  265. (LPCTSTR)strCaption,
  266. dwMessageFlags
  267. #ifdef WINNT
  268. | MB_DEFAULT_DESKTOP_ONLY | MB_SERVICE_NOTIFICATION
  269. #endif
  270. );
  271. LocalFree( messageText );
  272. return dwError;
  273. } // DisplayPopup