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.

314 lines
5.8 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. ShowPerf.c
  5. Abstract:
  6. Provides a GUI interface to display the contents of a perf data
  7. block
  8. Author:
  9. Bob Watson (a-robw)
  10. Revision History:
  11. 23 Nov 94
  12. --*/
  13. #include <windows.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include "showperf.h"
  17. #include "resource.h"
  18. #include "mainwnd.h"
  19. #include "maindlg.h"
  20. #define NUM_BUFS 4
  21. // variable definition
  22. static WORD wHelpContextId = IDH_CONTENTS;
  23. LPCTSTR
  24. GetStringResource (
  25. IN HANDLE hInstance,
  26. IN UINT nId
  27. )
  28. /*++
  29. Routine Description:
  30. look up string resource and return string
  31. Arguments:
  32. IN UINT nId
  33. Resource ID of string to look up
  34. Return Value:
  35. pointer to string referenced by ID in arg list
  36. --*/
  37. {
  38. static TCHAR szBufArray[NUM_BUFS][SMALL_BUFFER_SIZE];
  39. static DWORD dwIndex;
  40. LPTSTR szBuffer;
  41. DWORD dwLength;
  42. HANDLE hMod;
  43. if (hInstance != NULL) {
  44. hMod = hInstance;
  45. } else {
  46. hMod = GetModuleHandle(NULL);
  47. }
  48. dwIndex++;
  49. dwIndex %= NUM_BUFS;
  50. szBuffer = &szBufArray[dwIndex][0];
  51. // clear previous contents
  52. memset (szBuffer, 0, (SMALL_BUFFER_SIZE * sizeof(TCHAR)));
  53. dwLength = LoadString (
  54. hMod,
  55. nId,
  56. szBuffer,
  57. SMALL_BUFFER_SIZE);
  58. return (LPCTSTR)szBuffer;
  59. }
  60. VOID
  61. SetHelpContextId (
  62. WORD wId
  63. )
  64. {
  65. wHelpContextId = wId;
  66. return;
  67. }
  68. WORD
  69. GetHelpContextId (
  70. )
  71. {
  72. return wHelpContextId;
  73. }
  74. int
  75. DisplayMessageBox (
  76. IN HWND hWnd,
  77. IN UINT nMessageId,
  78. IN UINT nTitleId,
  79. IN UINT nStyle
  80. )
  81. /*++
  82. Routine Description:
  83. Displays a message box displaying text from the resource file, as
  84. opposed to literal strings.
  85. Arguments:
  86. IN HWND hWnd window handle to parent window
  87. IN UINT nMessageId String Resource ID of message text to display
  88. IN UINT nTitleId String Resource ID of title text to display
  89. IN UINT nStyle MB style bits (see MessageBox function)
  90. Return Value:
  91. ID of button pressed to exit message box
  92. --*/
  93. {
  94. LPTSTR szMessageText = NULL;
  95. LPTSTR szTitleText = NULL;
  96. HINSTANCE hInst;
  97. int nReturn;
  98. hInst = GET_INSTANCE(hWnd);
  99. szMessageText = GLOBAL_ALLOC (SMALL_BUFFER_BYTES);
  100. szTitleText = GLOBAL_ALLOC (SMALL_BUFFER_BYTES);
  101. if ((szMessageText != NULL) &&
  102. (szTitleText != NULL)) {
  103. LoadString (hInst,
  104. ((nTitleId != 0) ? nTitleId : IDS_APP_TITLE),
  105. szTitleText,
  106. SMALL_BUFFER_SIZE -1);
  107. LoadString (hInst,
  108. nMessageId,
  109. szMessageText,
  110. SMALL_BUFFER_SIZE - 1);
  111. nReturn = MessageBox (
  112. hWnd,
  113. szMessageText,
  114. szTitleText,
  115. nStyle);
  116. } else {
  117. nReturn = IDCANCEL;
  118. }
  119. GLOBAL_FREE_IF_ALLOC (szMessageText);
  120. GLOBAL_FREE_IF_ALLOC (szTitleText);
  121. return nReturn;
  122. }
  123. BOOL
  124. UpdateSystemMenu (
  125. IN HWND hWnd // window handle
  126. )
  127. /*++
  128. Routine Description:
  129. modifies the system menu by:
  130. Removing the "Restore", "Size", "Minimize" and "Maximize" entries
  131. Arguments:
  132. IN HWND hWnd
  133. window handle of window containing the system menu to modify
  134. Return Value:
  135. TRUE if successfully made changes, otherwise
  136. FALSE if error occurred
  137. --*/
  138. {
  139. return TRUE;
  140. }
  141. BOOL
  142. ShowAppHelp (
  143. IN HWND hWnd
  144. )
  145. /*++
  146. Routine Description:
  147. Generic routine to call WinHelp engine for displaying application
  148. help. wContext parameter is used for context.
  149. Arguments:
  150. IN HWND hWnd
  151. window handle of calling window
  152. Return Value:
  153. TRUE if help called successfully
  154. --*/
  155. {
  156. return WinHelp (hWnd,
  157. GetStringResource(GET_INSTANCE(hWnd), IDS_HELP_FILENAME),
  158. HELP_CONTEXT,
  159. (DWORD)GetHelpContextId());
  160. }
  161. static
  162. LRESULT
  163. NYIMsgBox (
  164. IN HWND hWnd
  165. )
  166. /*++
  167. Routine Description:
  168. Displays error message box for features that have not been implemented.
  169. in DEBUG builds, this is a message box, in RELEASE builds, this is
  170. only a beep.
  171. Arguments:
  172. hWnd Window handle to main window
  173. Return Value:
  174. ERROR_SUCCESS
  175. --*/
  176. {
  177. #ifdef DBG
  178. DisplayMessageBox (
  179. hWnd,
  180. IDS_NIY,
  181. IDS_APP_ERROR,
  182. MBOK_EXCLAIM);
  183. #else
  184. MessageBeep (BEEP_EXCLAMATION);
  185. #endif
  186. return ERROR_SUCCESS;
  187. }
  188. int APIENTRY
  189. WinMain(
  190. IN HINSTANCE hInstance,
  191. IN HINSTANCE hPrevInstance,
  192. IN LPSTR szCmdLine,
  193. IN int nCmdShow
  194. )
  195. /*++
  196. Routine Description:
  197. Program entry point for LoadAccount application. Initializes Windows
  198. data structures and begins windows message processing loop.
  199. Arguments:
  200. Standard WinMain arguments
  201. ReturnValue:
  202. 0 if unable to initialize correctly, or
  203. wParam from WM_QUIT message if messages processed
  204. --*/
  205. {
  206. HWND hWnd; // Main window handle.
  207. HWND hPrevWnd; // previously openend app main window
  208. MSG msg;
  209. HACCEL hAccel;
  210. if (RegisterMainWindowClass(hInstance)) {
  211. hWnd = CreateMainWindow (hInstance);
  212. if (hWnd != NULL) {
  213. // Acquire and dispatch messages until a
  214. // WM_QUIT message is received.
  215. while (GetMessage(&msg, // message structure
  216. NULL, // handle of window receiving the message
  217. 0, // lowest message to examine
  218. 0)) // highest message to examine
  219. {
  220. // process this message
  221. TranslateMessage(&msg);// Translates virtual key codes
  222. DispatchMessage(&msg); // Dispatches message to window
  223. }
  224. return (msg.wParam); // Returns the value from PostQuitMessage
  225. } else {
  226. return (ERROR_CAN_NOT_COMPLETE);
  227. }
  228. } else {
  229. return (ERROR_CAN_NOT_COMPLETE);
  230. }
  231. }