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.

169 lines
3.8 KiB

  1. /*++
  2. *
  3. * Hello.c
  4. * Simple 16-bit Windows App
  5. *
  6. * Copyright (c) 1991, Microsoft Corporation
  7. *
  8. * History:
  9. * Created 27-Jan-1991 by Jeff Parsons (jeffpar)
  10. * From "Programming Windows" by C. Petzold, p.16-19
  11. *
  12. * Updated 02-May-1991 by Jeff Parsons (jeffpar)
  13. * To serve as a bare-bones shell (user-friendly of course)
  14. --*/
  15. #include <windows.h>
  16. #include "hello.h"
  17. #define BUTTON_REVERSI 1 // button IDs
  18. #define BUTTON_WIDTH 80 // width and height for all buttons
  19. #define BUTTON_HEIGHT 20
  20. BOOL FAR PASCAL EnumWindowFunc(HWND hwnd, DWORD lParam)
  21. {
  22. char achTmp[80];
  23. wsprintf(achTmp, "HELLO: Window %04x enumerated\n", hwnd);
  24. OutputDebugString(achTmp);
  25. return TRUE; // return non-zero to continue enumeration
  26. }
  27. LONG FAR PASCAL WndProc(HWND hwnd, WORD wMsg, int wParam, LONG lParam)
  28. {
  29. HDC hdc;
  30. PAINTSTRUCT ps;
  31. HANDLE hTask;
  32. char achTmp[80];
  33. static char achTextOut[] = "The User-Friendly WOW Shell";
  34. switch(wMsg) {
  35. case WM_CREATE:
  36. CreateWindow("Button",
  37. "Reversi",
  38. WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  39. 8,
  40. 8 + BUTTON_REVERSI*24,
  41. BUTTON_WIDTH,
  42. BUTTON_HEIGHT,
  43. hwnd,
  44. BUTTON_REVERSI,
  45. ((LPCREATESTRUCT)lParam)->hInstance, NULL);
  46. return 0;
  47. case WM_PAINT:
  48. hdc = BeginPaint(hwnd, &ps);
  49. TextOut(hdc, 8, 8, achTextOut, sizeof(achTextOut)-1);
  50. EndPaint(hwnd, &ps);
  51. return 0;
  52. case WM_COMMAND:
  53. // See if the command is from a menu
  54. if (LOWORD(lParam) == 0) {
  55. switch(wParam) {
  56. case IDM_BREAKPOINT:
  57. _asm int 3
  58. // Hokey timing test -JTP
  59. GetParent(hwnd);
  60. {
  61. int i;
  62. for (i=0; i<10000; i++)
  63. GetParent(hwnd);
  64. }
  65. return 0;
  66. case IDM_ENUMWINDOWS:
  67. OutputDebugString("HELLO: Enumerating windows\n");
  68. EnumWindows(EnumWindowFunc, 0x10000001);
  69. return 0;
  70. case IDM_ENUMCHILDWINDOWS:
  71. wsprintf(achTmp, "HELLO: Enumerating child windows for hwnd %04x\n", hwnd);
  72. OutputDebugString(achTmp);
  73. EnumChildWindows(hwnd, EnumWindowFunc, 0x10000002);
  74. return 0;
  75. case IDM_ENUMTASKWINDOWS:
  76. hTask = GetCurrentTask();
  77. wsprintf(achTmp, "HELLO: Enumerating task windows for task %04x\n", hTask);
  78. OutputDebugString(achTmp);
  79. EnumTaskWindows(hTask, EnumWindowFunc, 0x10000003);
  80. return 0;
  81. }
  82. }
  83. // The command must be a button notification
  84. // (or something else I'm too ignorant to know about -JTP)
  85. else {
  86. if (wParam == BUTTON_REVERSI) {
  87. // _asm int 3
  88. WinExec("REVERSI.EXE", SW_SHOWNORMAL);
  89. // _asm int 3
  90. }
  91. return 0;
  92. }
  93. break;
  94. case WM_DESTROY:
  95. PostQuitMessage(0);
  96. return 0;
  97. }
  98. return DefWindowProc(hwnd, wMsg, wParam, lParam);
  99. }
  100. int PASCAL WinMain(HANDLE hInstance,
  101. HANDLE hPrevInstance, LPSTR lpszCmd, int iCmd)
  102. {
  103. HWND hwnd;
  104. MSG msg;
  105. WNDCLASS wc;
  106. static char szApp[] = "WOW";
  107. if (!hPrevInstance) {
  108. wc.style = CS_HREDRAW | CS_VREDRAW;
  109. wc.lpfnWndProc = WndProc;
  110. wc.cbClsExtra = 0;
  111. wc.cbWndExtra = 0;
  112. wc.hInstance = hInstance;
  113. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  114. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  115. wc.hbrBackground= GetStockObject(WHITE_BRUSH);
  116. wc.lpszMenuName = szApp;
  117. wc.lpszClassName= szApp;
  118. if (!RegisterClass(&wc))
  119. return 0;
  120. }
  121. hwnd = CreateWindow(
  122. szApp, // window class name
  123. szApp, // window caption
  124. (WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME) | WS_VISIBLE,
  125. 50, 50, 250, 128,
  126. NULL, // parent window handle
  127. NULL, // window menu handle
  128. hInstance, // program instance handle
  129. NULL // creation parameters
  130. );
  131. if (!hwnd)
  132. return 0;
  133. while (GetMessage(&msg, NULL, 0, 0)) {
  134. TranslateMessage(&msg);
  135. DispatchMessage(&msg);
  136. }
  137. return msg.wParam;
  138. }