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.

212 lines
5.2 KiB

  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 "showperf.h"
  15. #include "resource.h"
  16. #define NUM_BUFS 4
  17. // variable definition
  18. static WORD wHelpContextId = IDH_CONTENTS;
  19. LPCWSTR
  20. GetStringResource(
  21. HANDLE hInstance,
  22. UINT nId
  23. )
  24. /*++
  25. Routine Description:
  26. look up string resource and return string
  27. Arguments:
  28. IN UINT nId
  29. Resource ID of string to look up
  30. Return Value:
  31. pointer to string referenced by ID in arg list
  32. --*/
  33. {
  34. static WCHAR szBufArray[NUM_BUFS][SMALL_BUFFER_SIZE];
  35. static DWORD dwIndex;
  36. LPWSTR szBuffer;
  37. DWORD dwLength;
  38. HANDLE hMod;
  39. hMod = (hInstance != NULL) ? (hInstance) : (GetModuleHandle(NULL));
  40. dwIndex ++;
  41. dwIndex %= NUM_BUFS;
  42. szBuffer = & szBufArray[dwIndex][0];
  43. // clear previous contents
  44. ZeroMemory(szBuffer, SMALL_BUFFER_SIZE * sizeof(WCHAR));
  45. dwLength = LoadStringW(hMod, nId, szBuffer, SMALL_BUFFER_SIZE);
  46. return (LPCWSTR) szBuffer;
  47. }
  48. VOID
  49. SetHelpContextId(
  50. WORD wId
  51. )
  52. {
  53. wHelpContextId = wId;
  54. return;
  55. }
  56. WORD
  57. GetHelpContextId(
  58. )
  59. {
  60. return wHelpContextId;
  61. }
  62. int
  63. DisplayMessageBox(
  64. HWND hWnd,
  65. UINT nMessageId,
  66. UINT nTitleId,
  67. UINT nStyle
  68. )
  69. /*++
  70. Routine Description:
  71. Displays a message box displaying text from the resource file, as
  72. opposed to literal strings.
  73. Arguments:
  74. IN HWND hWnd window handle to parent window
  75. IN UINT nMessageId String Resource ID of message text to display
  76. IN UINT nTitleId String Resource ID of title text to display
  77. IN UINT nStyle MB style bits (see MessageBox function)
  78. Return Value:
  79. ID of button pressed to exit message box
  80. --*/
  81. {
  82. LPWSTR szMessageText = NULL;
  83. LPWSTR szTitleText = NULL;
  84. HINSTANCE hInst = GET_INSTANCE(hWnd);
  85. int nReturn;
  86. szMessageText = MemoryAllocate(sizeof(WCHAR) * (SMALL_BUFFER_SIZE + 1));
  87. szTitleText = MemoryAllocate(sizeof(WCHAR) * (SMALL_BUFFER_SIZE + 1));
  88. if ((szMessageText != NULL) && (szTitleText != NULL)) {
  89. LoadStringW(hInst, ((nTitleId != 0) ? nTitleId : IDS_APP_TITLE), szTitleText, SMALL_BUFFER_SIZE - 1);
  90. LoadStringW(hInst, nMessageId, szMessageText, SMALL_BUFFER_SIZE - 1);
  91. nReturn = MessageBoxW(hWnd, szMessageText, szTitleText, nStyle);
  92. }
  93. else {
  94. nReturn = IDCANCEL;
  95. }
  96. MemoryFree(szMessageText);
  97. MemoryFree(szTitleText);
  98. return nReturn;
  99. }
  100. BOOL
  101. UpdateSystemMenu(
  102. HWND hWnd // window handle
  103. )
  104. /*++
  105. Routine Description:
  106. modifies the system menu by:
  107. Removing the "Restore", "Size", "Minimize" and "Maximize" entries
  108. Arguments:
  109. IN HWND hWnd
  110. window handle of window containing the system menu to modify
  111. Return Value:
  112. TRUE if successfully made changes, otherwise
  113. FALSE if error occurred
  114. --*/
  115. {
  116. UNREFERENCED_PARAMETER(hWnd);
  117. return TRUE;
  118. }
  119. BOOL
  120. ShowAppHelp(
  121. HWND hWnd
  122. )
  123. /*++
  124. Routine Description:
  125. Generic routine to call WinHelp engine for displaying application
  126. help. wContext parameter is used for context.
  127. Arguments:
  128. IN HWND hWnd
  129. window handle of calling window
  130. Return Value:
  131. TRUE if help called successfully
  132. --*/
  133. {
  134. return WinHelpW(hWnd,
  135. GetStringResource(GET_INSTANCE(hWnd), IDS_HELP_FILENAME),
  136. HELP_CONTEXT,
  137. (DWORD) GetHelpContextId());
  138. }
  139. int APIENTRY
  140. WinMain(
  141. IN HINSTANCE hInstance,
  142. IN HINSTANCE hPrevInstance,
  143. IN LPSTR szCmdLine,
  144. IN int nCmdShow
  145. )
  146. /*++
  147. Routine Description:
  148. Program entry point for LoadAccount application. Initializes Windows
  149. data structures and begins windows message processing loop.
  150. Arguments:
  151. Standard WinMain arguments
  152. ReturnValue:
  153. 0 if unable to initialize correctly, or
  154. wParam from WM_QUIT message if messages processed
  155. --*/
  156. {
  157. HWND hWnd; // Main window handle.
  158. MSG msg;
  159. int iReturn = ERROR_CAN_NOT_COMPLETE;
  160. UNREFERENCED_PARAMETER(nCmdShow);
  161. UNREFERENCED_PARAMETER(szCmdLine);
  162. UNREFERENCED_PARAMETER(hPrevInstance);
  163. if (RegisterMainWindowClass(hInstance)) {
  164. hWnd = CreateMainWindow(hInstance);
  165. if (hWnd != NULL) {
  166. // Acquire and dispatch messages until a
  167. // WM_QUIT message is received.
  168. while (GetMessage(& msg, // message structure
  169. NULL, // handle of window receiving the message
  170. 0, // lowest message to examine
  171. 0)) { // highest message to examine
  172. // process this message
  173. TranslateMessage(& msg);// Translates virtual key codes
  174. DispatchMessage(& msg); // Dispatches message to window
  175. }
  176. iReturn = (int)(msg.wParam); // Returns the value from PostQuitMessage
  177. }
  178. }
  179. return iReturn;
  180. }