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.

361 lines
9.9 KiB

  1. /*****************************************************************************
  2. *
  3. * SetEdit.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. * Hon-Wah Chan
  13. *
  14. ****************************************************************************/
  15. //==========================================================================//
  16. // Includes //
  17. //==========================================================================//
  18. #undef NOSYSCOMMANDS
  19. // DEFINE_GLOBALS will define all the globals listed in globals.h
  20. #define DEFINE_GLOBALS
  21. #include "setedit.h"
  22. #include "command.h"
  23. #include "graph.h"
  24. #include "grafdata.h" // for QuerySaveChart
  25. #include "legend.h"
  26. #include "init.h"
  27. #include "perfmops.h"
  28. #include "toolbar.h" // for CreateToolbar
  29. #include "status.h" // for CreatePMStatusWindow
  30. #include "utils.h"
  31. #include "fileopen.h" // for FileOpen
  32. #ifdef DEBUGDUMP
  33. #include "debug.h"
  34. #endif
  35. #define dwToolbarStyle (WS_CHILD | WS_VISIBLE | TBS_NOCAPTION)
  36. extern TCHAR szInternational[] ;
  37. //==========================================================================//
  38. // Message Handlers //
  39. //==========================================================================//
  40. void static OnSize (HWND hWnd,
  41. WORD xWidth,
  42. WORD yHeight)
  43. /*
  44. Effect: Perform any actions needed when the main window is
  45. resized. In particular, size the four data windows,
  46. only one of which is visible right now.
  47. */
  48. { // OnSize
  49. SizePerfmonComponents () ;
  50. }
  51. void static OnCreate (HWND hWnd)
  52. /*
  53. Effect: Perform all actions needed when the main window is
  54. created. In particular, create the three data windows,
  55. and show one of them.
  56. To Do: Check for proper creation. If not possible, we will
  57. need to abort creation of the program.
  58. Called By: MainWndProc only, in response to a WM_CREATE message.
  59. */
  60. { // OnCreate
  61. hWndGraph = CreateGraphWindow (hWnd) ;
  62. hWndStatus = CreatePMStatusWindow (hWnd) ;
  63. CreateToolbarWnd (hWnd) ;
  64. MinimumSize += WindowHeight (hWndToolbar) ;
  65. Options.bMenubar = TRUE ;
  66. Options.bToolbar = TRUE ;
  67. Options.bStatusbar = TRUE;
  68. Options.bAlwaysOnTop = FALSE ;
  69. // initialize to chart view - HWC
  70. iPerfmonView = IDM_VIEWCHART;
  71. ShowWindow (PerfmonViewWindow (), SW_SHOWNORMAL) ;
  72. } // OnCreate
  73. //==========================================================================//
  74. // Exported Functions //
  75. //==========================================================================//
  76. void MenuBarHit (WPARAM wParam)
  77. {
  78. if (wParam == MENUCLOSING) {
  79. StatusLineReady (hWndStatus) ;
  80. dwCurrentMenuID = 0 ;
  81. } else if (HIWORD(wParam) & MF_SYSMENU) {
  82. WORD SystemMenuItem = 0 ;
  83. switch (LOWORD (wParam)) {
  84. case SC_RESTORE:
  85. SystemMenuItem = IDM_SYSTEMRESTORE ;
  86. break ;
  87. case SC_SIZE:
  88. SystemMenuItem = IDM_SYSTEMSIZE ;
  89. break ;
  90. case SC_MOVE:
  91. SystemMenuItem = IDM_SYSTEMMOVE ;
  92. break ;
  93. case SC_MINIMIZE:
  94. SystemMenuItem = IDM_SYSTEMMINIMIZE ;
  95. break ;
  96. case SC_MAXIMIZE:
  97. SystemMenuItem = IDM_SYSTEMMAXIMIZE ;
  98. break ;
  99. case SC_CLOSE:
  100. SystemMenuItem = IDM_SYSTEMCLOSE ;
  101. break ;
  102. case SC_TASKLIST:
  103. SystemMenuItem = IDM_SYSTEMSWITCHTO ;
  104. break ;
  105. }
  106. if (SystemMenuItem) {
  107. StatusLine (hWndStatus, SystemMenuItem) ;
  108. dwCurrentMenuID = MenuIDToHelpID (SystemMenuItem) ;
  109. }
  110. } else {
  111. StatusLine (hWndStatus, LOWORD (wParam)) ;
  112. }
  113. }
  114. void OnDropFile (WPARAM wParam)
  115. {
  116. TCHAR FileName [FilePathLen + 1] ;
  117. LPTSTR pFileNameStart ;
  118. HANDLE hFindFile ;
  119. WIN32_FIND_DATA FindFileInfo ;
  120. int NameOffset ;
  121. int NumOfFiles = 0 ;
  122. NumOfFiles = DragQueryFile ((HDROP) wParam, 0xffffffff, NULL, 0) ;
  123. if (NumOfFiles > 0) {
  124. // we only open the first file for now
  125. DragQueryFile((HDROP) wParam, 0, FileName, FilePathLen) ;
  126. pFileNameStart = ExtractFileName (FileName) ;
  127. NameOffset = (int)(pFileNameStart - FileName) ;
  128. // convert short filename to long NTFS filename if necessary
  129. hFindFile = FindFirstFile (FileName, &FindFileInfo) ;
  130. if (hFindFile && hFindFile != INVALID_HANDLE_VALUE) {
  131. // append the file name back to the path name
  132. lstrcpy (&FileName[NameOffset], FindFileInfo.cFileName) ;
  133. FindClose (hFindFile) ;
  134. }
  135. FileOpen (hWndMain, (int)0, (LPTSTR)FileName) ;
  136. PrepareMenu (GetMenu (hWndMain));
  137. }
  138. DragFinish ((HDROP) wParam) ;
  139. }
  140. LRESULT
  141. APIENTRY
  142. MainWndProc (
  143. HWND hWnd,
  144. UINT message,
  145. WPARAM wParam,
  146. LPARAM lParam
  147. )
  148. {
  149. LRESULT lRetCode = 0L ;
  150. BOOL bCallDefWinProc = FALSE ;
  151. switch (LOWORD (message)) { // switch
  152. case WM_COMMAND:
  153. if (PerfmonCommand (hWnd,wParam,lParam))
  154. return(0);
  155. else
  156. bCallDefWinProc = TRUE ;
  157. break;
  158. case WM_MENUSELECT:
  159. MenuBarHit (wParam) ;
  160. break ;
  161. case WM_SHOWWINDOW:
  162. PrepareMenu (GetMenu (hWnd)) ;
  163. break ;
  164. case WM_SIZE:
  165. OnSize (hWnd, LOWORD (lParam), HIWORD (lParam)) ;
  166. break ;
  167. case WM_GETMINMAXINFO:
  168. {
  169. MINMAXINFO *pMinMax ;
  170. pMinMax = (MINMAXINFO *) lParam ;
  171. pMinMax->ptMinTrackSize.x = MinimumSize ;
  172. pMinMax->ptMinTrackSize.y = MinimumSize ;
  173. }
  174. break ;
  175. case WM_CREATE:
  176. OnCreate (hWnd) ;
  177. ViewChart (hWnd) ;
  178. PrepareMenu (GetMenu (hWnd)) ;
  179. break ;
  180. case WM_DESTROY:
  181. WinHelp (hWndMain, pszHelpFile, HELP_QUIT, 0) ;
  182. PostQuitMessage (0);
  183. break ;
  184. case WM_QUERYENDSESSION:
  185. // please shut it down
  186. return (1) ;
  187. break ;
  188. case WM_ENDSESSION:
  189. if (wParam == TRUE) {
  190. // close any log file before closing down
  191. PerfmonClose (hWnd) ;
  192. return (1) ;
  193. } else
  194. bCallDefWinProc = TRUE ;
  195. break ;
  196. case WM_CLOSE:
  197. if (QuerySaveChart (hWnd, pGraphs)) {
  198. PerfmonClose (hWnd) ;
  199. }
  200. break ;
  201. case WM_ACTIVATE:
  202. {
  203. int fActivate = LOWORD (wParam) ;
  204. bPerfmonIconic = (BOOL) HIWORD (wParam) ;
  205. if (bPerfmonIconic == 0 && fActivate != WA_INACTIVE) {
  206. // set focus on the Legend window
  207. SetFocus (hWndGraphLegend) ;
  208. }
  209. }
  210. break ;
  211. case WM_SYSCOLORCHANGE:
  212. DeletePerfmonSystemObjects () ;
  213. CreatePerfmonSystemObjects () ;
  214. WindowInvalidate (PerfmonViewWindow()) ;
  215. break ;
  216. case WM_DROPFILES:
  217. OnDropFile (wParam) ;
  218. return (0) ;
  219. break ;
  220. default:
  221. bCallDefWinProc = TRUE ;
  222. break;
  223. } // switch
  224. if (bCallDefWinProc) {
  225. lRetCode = DefWindowProc (hWnd, message, wParam, lParam) ;
  226. }
  227. return (lRetCode);
  228. } // MainWndProc
  229. int
  230. PASCAL
  231. WinMain (
  232. HINSTANCE hCurrentInstance,
  233. HINSTANCE hPrevInstance,
  234. LPSTR lpszCmdLine,
  235. int nCmdShow
  236. )
  237. { // WinMain
  238. MSG msg;
  239. if (!PerfmonInitialize (hCurrentInstance, hPrevInstance,
  240. lpszCmdLine, nCmdShow))
  241. return (FALSE) ;
  242. DragAcceptFiles (hWndMain, TRUE) ;
  243. while (GetMessage (&msg, NULL, 0, 0)) {
  244. if (//FIXFIX !ModelessDispatch (hWndLog, &msg) &&
  245. // doesnt work
  246. !TranslateAccelerator(hWndMain, hAccelerators, &msg)) {
  247. TranslateMessage (&msg) ;
  248. DispatchMessage (&msg) ;
  249. }
  250. } // while
  251. return((int)msg.wParam);
  252. }
  253. void
  254. SizePerfmonComponents (void)
  255. {
  256. RECT rectClient ;
  257. int xWidth, yHeight ;
  258. int yToolbarHeight ;
  259. int yStatusHeight ;
  260. int yViewHeight ;
  261. GetClientRect (hWndMain, &rectClient) ;
  262. xWidth = rectClient.right - rectClient.left ;
  263. yHeight = rectClient.bottom - rectClient.top ;
  264. if (Options.bToolbar) {
  265. SendMessage (hWndToolbar, WM_SIZE, 0, 0L) ;
  266. }
  267. yToolbarHeight = Options.bToolbar ? (WindowHeight (hWndToolbar) - 1) : 0 ;
  268. yStatusHeight = Options.bStatusbar ? StatusHeight (hWndStatus) : 0 ;
  269. if (Options.bStatusbar) {
  270. if (yToolbarHeight + yStatusHeight > yHeight) {
  271. // too small to display both toolbar and status bar
  272. // just display part of the status bar
  273. yStatusHeight = yHeight - yToolbarHeight ;
  274. }
  275. MoveWindow (hWndStatus,
  276. 0, yHeight - yStatusHeight, xWidth, yStatusHeight, TRUE) ;
  277. //WindowInvalidate (hWndStatus) ;
  278. }
  279. //WindowInvalidate (hWndMain) ;
  280. WindowShow (hWndStatus, Options.bStatusbar) ;
  281. WindowShow (hWndToolbar, Options.bToolbar) ;
  282. yViewHeight = yHeight - yStatusHeight - yToolbarHeight ;
  283. MoveWindow (hWndGraph,
  284. 0, yToolbarHeight,
  285. xWidth, yViewHeight,
  286. TRUE) ;
  287. } // SizePerfmonComponents