Windows NT 4.0 source code leak
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.

511 lines
13 KiB

4 years ago
  1. /*****************************************************************************
  2. *
  3. * Perfmon.c - This is the WinMain module. It creates the main window and
  4. * the threads, and contains the main MainWndProc.
  5. *
  6. * Microsoft Confidential
  7. * Copyright (c) 1992-1993 Microsoft Corporation
  8. *
  9. * Authors -
  10. *
  11. * Russ Blake
  12. * Mike Moskowitz
  13. * Hon-Wah Chan
  14. * Bob Watson
  15. *
  16. ****************************************************************************/
  17. //==========================================================================//
  18. // Includes //
  19. //==========================================================================//
  20. #undef NOSYSCOMMANDS
  21. // DEFINE_GLOBALS will define all the globals listed in globals.h
  22. #define DEFINE_GLOBALS
  23. #include "perfmon.h"
  24. #include <commctrl.h> // for tool tip & tool bar definitions
  25. #include <stdio.h> // just for now
  26. #include "command.h"
  27. #include "graph.h"
  28. #include "log.h"
  29. #include "alert.h"
  30. #include "report.h" // for CreateReportWindow
  31. #include "legend.h"
  32. #include "init.h"
  33. #include "perfmops.h"
  34. #include "toolbar.h" // for CreateToolbar
  35. #include "status.h" // for CreatePMStatusWindow
  36. #include "utils.h"
  37. #include "fileopen.h" // for FileOpen
  38. #define dwToolbarStyle (WS_CHILD | WS_VISIBLE | TBS_NOCAPTION)
  39. extern TCHAR szInternational[] ;
  40. //==========================================================================//
  41. // Message Handlers //
  42. //==========================================================================//
  43. void static OnSize (HWND hWnd,
  44. WORD xWidth,
  45. WORD yHeight)
  46. /*
  47. Effect: Perform any actions needed when the main window is
  48. resized. In particular, size the four data windows,
  49. only one of which is visible right now.
  50. */
  51. { // OnSize
  52. SizePerfmonComponents () ;
  53. }
  54. void static OnCreate (HWND hWnd)
  55. /*
  56. Effect: Perform all actions needed when the main window is
  57. created. In particular, create the three data windows,
  58. and show one of them.
  59. To Do: Check for proper creation. If not possible, we will
  60. need to abort creation of the program.
  61. Called By: MainWndProc only, in response to a WM_CREATE message.
  62. */
  63. { // OnCreate
  64. hWndGraph = CreateGraphWindow (hWnd) ;
  65. #ifdef ADVANCED_PERFMON
  66. hWndLog = CreateLogWindow (hWnd) ;
  67. hWndAlert = CreateAlertWindow (hWnd) ;
  68. hWndReport = CreateReportWindow (hWnd) ;
  69. #endif
  70. hWndStatus = CreatePMStatusWindow (hWnd) ;
  71. CreateToolbarWnd (hWnd) ;
  72. MinimumSize += WindowHeight (hWndToolbar) ;
  73. Options.bMenubar = TRUE ;
  74. Options.bToolbar = TRUE ;
  75. Options.bStatusbar = TRUE;
  76. Options.bAlwaysOnTop = FALSE ;
  77. // initialize to chart view - HWC
  78. iPerfmonView = IDM_VIEWCHART;
  79. ShowWindow (PerfmonViewWindow (), SW_SHOWNORMAL) ;
  80. } // OnCreate
  81. //==========================================================================//
  82. // Exported Functions //
  83. //==========================================================================//
  84. void MenuBarHit (DWORD wParam)
  85. {
  86. if (wParam == MENUCLOSING)
  87. {
  88. StatusLineReady (hWndStatus) ;
  89. dwCurrentMenuID = 0 ;
  90. }
  91. else if (HIWORD(wParam) & MF_SYSMENU)
  92. {
  93. WORD SystemMenuItem = 0 ;
  94. switch (LOWORD (wParam))
  95. {
  96. case SC_RESTORE:
  97. SystemMenuItem = IDM_SYSTEMRESTORE ;
  98. break ;
  99. case SC_SIZE:
  100. SystemMenuItem = IDM_SYSTEMSIZE ;
  101. break ;
  102. case SC_MOVE:
  103. SystemMenuItem = IDM_SYSTEMMOVE ;
  104. break ;
  105. case SC_MINIMIZE:
  106. SystemMenuItem = IDM_SYSTEMMINIMIZE ;
  107. break ;
  108. case SC_MAXIMIZE:
  109. SystemMenuItem = IDM_SYSTEMMAXIMIZE ;
  110. break ;
  111. case SC_CLOSE:
  112. SystemMenuItem = IDM_SYSTEMCLOSE ;
  113. break ;
  114. case SC_TASKLIST:
  115. SystemMenuItem = IDM_SYSTEMSWITCHTO ;
  116. break ;
  117. }
  118. if (SystemMenuItem)
  119. {
  120. StatusLine (hWndStatus, SystemMenuItem) ;
  121. dwCurrentMenuID = MenuIDToHelpID (SystemMenuItem) ;
  122. }
  123. }
  124. else
  125. {
  126. StatusLine (hWndStatus, LOWORD (wParam)) ;
  127. }
  128. }
  129. void OnDropFile (DWORD wParam)
  130. {
  131. TCHAR FileName [FilePathLen + 1] ;
  132. LPTSTR pFileNameStart ;
  133. HANDLE hFindFile ;
  134. WIN32_FIND_DATA FindFileInfo ;
  135. int NameOffset ;
  136. int NumOfFiles = 0 ;
  137. NumOfFiles = DragQueryFile ((HDROP) wParam, 0xffffffff, NULL, 0) ;
  138. if (NumOfFiles > 0)
  139. {
  140. // we only open the first file for now
  141. DragQueryFile((HDROP) wParam, 0, FileName, FilePathLen) ;
  142. pFileNameStart = ExtractFileName (FileName) ;
  143. NameOffset = pFileNameStart - FileName ;
  144. // convert short filename to long NTFS filename if necessary
  145. hFindFile = FindFirstFile (FileName, &FindFileInfo) ;
  146. if (hFindFile && hFindFile != INVALID_HANDLE_VALUE)
  147. {
  148. // append the file name back to the path name
  149. lstrcpy (&FileName[NameOffset], FindFileInfo.cFileName) ;
  150. FindClose (hFindFile) ;
  151. }
  152. FileOpen (hWndMain, (int)0, (LPTSTR)FileName) ;
  153. PrepareMenu (GetMenu (hWndMain));
  154. }
  155. DragFinish ((HDROP) wParam) ;
  156. }
  157. LRESULT APIENTRY MainWndProc (HWND hWnd,
  158. UINT message,
  159. DWORD wParam,
  160. LONG lParam)
  161. {
  162. LONG lRetCode = 0L ;
  163. BOOL bCallDefWinProc = FALSE ;
  164. switch (LOWORD (message))
  165. { // switch
  166. case WM_LBUTTONDBLCLK:
  167. ShowPerfmonMenu (!Options.bMenubar) ;
  168. if (Options.bMenubar)
  169. {
  170. PrepareMenu (GetMenu (hWnd)) ;
  171. }
  172. break ;
  173. case WM_COMMAND:
  174. if (PerfmonCommand (hWnd,wParam,lParam))
  175. return(0);
  176. else
  177. bCallDefWinProc = TRUE ;
  178. break;
  179. case WM_MENUSELECT:
  180. MenuBarHit (wParam) ;
  181. break ;
  182. case WM_NCHITTEST:
  183. /* if we have no title/menu bar, clicking and dragging the client
  184. * area moves the window. To do this, return HTCAPTION.
  185. * Note dragging not allowed if window maximized, or if caption
  186. * bar is present.
  187. */
  188. wParam = DefWindowProc(hWnd, message, wParam, lParam);
  189. if (!Options.bMenubar &&
  190. (wParam == HTCLIENT) &&
  191. !IsZoomed (hWndMain))
  192. return HTCAPTION ;
  193. else
  194. return wParam ;
  195. break ;
  196. case WM_SHOWWINDOW:
  197. PrepareMenu (GetMenu (hWnd)) ;
  198. break ;
  199. case WM_SIZE:
  200. OnSize (hWnd, LOWORD (lParam), HIWORD (lParam)) ;
  201. break ;
  202. case WM_GETMINMAXINFO:
  203. {
  204. MINMAXINFO *pMinMax ;
  205. pMinMax = (MINMAXINFO *) lParam ;
  206. pMinMax->ptMinTrackSize.x = MinimumSize ;
  207. pMinMax->ptMinTrackSize.y = MinimumSize ;
  208. }
  209. break ;
  210. case WM_NOTIFY:
  211. {
  212. LPTOOLTIPTEXT lpTTT = (LPTOOLTIPTEXT)lParam;
  213. if (lpTTT->hdr.code == TTN_NEEDTEXT) {
  214. LoadString (hInstance, lpTTT->hdr.idFrom, lpTTT->szText,
  215. sizeof(lpTTT->szText)/sizeof(TCHAR));
  216. return TRUE;
  217. } else {
  218. bCallDefWinProc = FALSE ;
  219. break;
  220. }
  221. }
  222. case WM_F1DOWN:
  223. if (dwCurrentDlgID)
  224. {
  225. CallWinHelp (dwCurrentDlgID) ;
  226. }
  227. else if (dwCurrentMenuID)
  228. {
  229. CallWinHelp (dwCurrentMenuID) ;
  230. dwCurrentMenuID = 0 ;
  231. }
  232. break ;
  233. case WM_CREATE:
  234. OnCreate (hWnd) ;
  235. ViewChart (hWnd) ;
  236. PrepareMenu (GetMenu (hWnd)) ;
  237. break ;
  238. case WM_DESTROY:
  239. WinHelp (hWndMain, pszHelpFile, HELP_QUIT, 0) ;
  240. PostQuitMessage (0);
  241. break ;
  242. case WM_QUERYENDSESSION:
  243. // please shut it down
  244. return (1) ;
  245. break ;
  246. case WM_ENDSESSION:
  247. if (wParam == TRUE)
  248. {
  249. // close any log file before closing down
  250. PerfmonClose (hWnd) ;
  251. return (1) ;
  252. }
  253. else
  254. bCallDefWinProc = TRUE ;
  255. break ;
  256. case WM_CLOSE:
  257. PerfmonClose (hWnd) ;
  258. break ;
  259. case WM_ACTIVATE:
  260. {
  261. int fActivate = LOWORD (wParam) ;
  262. bPerfmonIconic = (BOOL) HIWORD (wParam) ;
  263. if (bPerfmonIconic == 0 && fActivate != WA_INACTIVE)
  264. {
  265. // set focus on the Legend window
  266. if (iPerfmonView == IDM_VIEWCHART)
  267. {
  268. SetFocus (hWndGraphLegend) ;
  269. }
  270. else if (iPerfmonView == IDM_VIEWALERT)
  271. {
  272. SetFocus (hWndAlertLegend) ;
  273. }
  274. else if (iPerfmonView == IDM_VIEWLOG)
  275. {
  276. SetFocus (hWndLogEntries) ;
  277. }
  278. else if (iPerfmonView == IDM_VIEWREPORT)
  279. {
  280. SetFocus (hWndReport) ;
  281. }
  282. }
  283. }
  284. break ;
  285. case WM_SYSCOLORCHANGE:
  286. DeletePerfmonSystemObjects () ;
  287. CreatePerfmonSystemObjects () ;
  288. WindowInvalidate (PerfmonViewWindow()) ;
  289. break ;
  290. case WM_WININICHANGE:
  291. if (!lParam || strsamei((LPTSTR)lParam, szInternational))
  292. {
  293. GetDateTimeFormats () ;
  294. }
  295. break ;
  296. case WM_DROPFILES:
  297. OnDropFile (wParam) ;
  298. return (0) ;
  299. break ;
  300. default:
  301. bCallDefWinProc = TRUE ;
  302. break;
  303. } // switch
  304. if (bCallDefWinProc)
  305. {
  306. lRetCode = DefWindowProc (hWnd, message, wParam, lParam) ;
  307. }
  308. return (lRetCode);
  309. } // MainWndProc
  310. int PASCAL WinMain (HINSTANCE hCurrentInstance,
  311. HINSTANCE hPrevInstance,
  312. LPSTR lpszCmdLine,
  313. int nCmdShow)
  314. { // WinMain
  315. MSG msg;
  316. if (!PerfmonInitialize (hCurrentInstance, hPrevInstance,
  317. lpszCmdLine, nCmdShow))
  318. return (FALSE) ;
  319. DragAcceptFiles (hWndMain, TRUE) ;
  320. while (GetMessage (&msg, NULL, 0, 0))
  321. {
  322. if (!TranslateAccelerator(hWndMain, hAccelerators, &msg))
  323. {
  324. TranslateMessage (&msg) ;
  325. DispatchMessage (&msg) ;
  326. }
  327. } // while
  328. return(msg.wParam);
  329. }
  330. DWORD FAR PASCAL MessageFilterProc (int nCode,
  331. WPARAM wParam,
  332. LPARAM lParam)
  333. {
  334. LPMSG lpMsg = (LPMSG)lParam ;
  335. extern HHOOK lpMsgFilterProc ;
  336. if (nCode < 0)
  337. {
  338. return FALSE ;
  339. }
  340. if (nCode == MSGF_DIALOGBOX || nCode == MSGF_MENU)
  341. {
  342. if (lpMsg->message == WM_KEYDOWN && lpMsg->wParam == VK_F1)
  343. {
  344. PostMessage (hWndMain, WM_F1DOWN, nCode, 0L) ;
  345. return TRUE ;
  346. }
  347. }
  348. return (DefHookProc (nCode, wParam,
  349. (DWORD)lpMsg,
  350. &lpMsgFilterProc)) ;
  351. }
  352. #if 0
  353. /***************************************/
  354. VOID ErrorExit(LPTSTR pszError,HWND hwnd)
  355. /***************************************/
  356. {
  357. // NOTE: make sure all lgraph calls set StopQuerying.
  358. if (hwnd)
  359. {
  360. MessageBox(NULL, pszError, nm_buf, MB_ICONHAND | MB_OK | MB_SYSTEMMODAL);
  361. DestroyWindow(hwnd);
  362. }
  363. return;
  364. }
  365. #endif
  366. void SizePerfmonComponents (void)
  367. {
  368. RECT rectClient ;
  369. int xWidth, yHeight ;
  370. int yToolbarHeight ;
  371. int yStatusHeight ;
  372. int yViewHeight ;
  373. GetClientRect (hWndMain, &rectClient) ;
  374. xWidth = rectClient.right - rectClient.left ;
  375. yHeight = rectClient.bottom - rectClient.top ;
  376. if (Options.bToolbar)
  377. {
  378. SendMessage (hWndToolbar, WM_SIZE, 0, 0L) ;
  379. }
  380. yToolbarHeight = Options.bToolbar ? (WindowHeight (hWndToolbar) - 1) : 0 ;
  381. yStatusHeight = Options.bStatusbar ? StatusHeight (hWndStatus) : 0 ;
  382. if (Options.bStatusbar)
  383. {
  384. if (yToolbarHeight + yStatusHeight > yHeight)
  385. {
  386. // too small to display both toolbar and status bar
  387. // just display part of the status bar
  388. yStatusHeight = yHeight - yToolbarHeight ;
  389. }
  390. MoveWindow (hWndStatus,
  391. 0, yHeight - yStatusHeight, xWidth, yStatusHeight, TRUE) ;
  392. //WindowInvalidate (hWndStatus) ;
  393. }
  394. //WindowInvalidate (hWndMain) ;
  395. WindowShow (hWndStatus, Options.bStatusbar) ;
  396. WindowShow (hWndToolbar, Options.bToolbar) ;
  397. yViewHeight = yHeight - yStatusHeight - yToolbarHeight ;
  398. MoveWindow (hWndGraph,
  399. 0, yToolbarHeight,
  400. xWidth, yViewHeight,
  401. TRUE) ;
  402. MoveWindow (hWndAlert,
  403. 0, yToolbarHeight,
  404. xWidth, yViewHeight,
  405. TRUE) ;
  406. MoveWindow (hWndLog,
  407. 0, yToolbarHeight,
  408. xWidth, yViewHeight,
  409. TRUE) ;
  410. MoveWindow (hWndReport,
  411. 0, yToolbarHeight,
  412. xWidth, yViewHeight,
  413. TRUE) ;
  414. } // SizePerfmonComponents