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.

202 lines
6.7 KiB

  1. #include <windows.h>
  2. #include <ole2.h>
  3. #include "simple.h"
  4. HANDLE hInst; /* current instance */
  5. int PASCAL WinMain(
  6. HANDLE hInstance,
  7. HANDLE hPrevInstance,
  8. LPSTR lpCmdLine,
  9. int nCmdShow
  10. ) {
  11. MSG msg;
  12. HDC hdc;
  13. if (!hPrevInstance) /* Other instances of app running? */
  14. if (!InitApplication(hInstance)) /* Initialize shared things */
  15. return (FALSE); /* Exits if unable to initialize */
  16. /* Perform initializations that apply to a specific instance */
  17. if (!InitInstance(hInstance, nCmdShow))
  18. return (FALSE);
  19. /* Acquire and dispatch messages until a WM_QUIT message is received. */
  20. while ( GetMessage(&msg, NULL, 0,0) ) {
  21. TranslateMessage(&msg);
  22. DispatchMessage(&msg);
  23. }
  24. }
  25. BOOL InitApplication(hInstance)
  26. HANDLE hInstance;
  27. {
  28. WNDCLASS wc;
  29. wc.style = CS_OWNDC; /* Class style(s). */
  30. wc.lpfnWndProc = MainWndProc; /* Function to retrieve messages for */
  31. /* windows of this class. */
  32. wc.cbClsExtra = 0; /* No per-class extra data. */
  33. wc.cbWndExtra = 0; /* No per-window extra data. */
  34. wc.hInstance = hInstance; /* Application that owns the class. */
  35. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  36. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  37. wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  38. wc.lpszMenuName = "SimpleMenu"; /* Name of menu resource in .RC file. */
  39. wc.lpszClassName = "SimpleClass"; /* Name used in call to CreateWindow. */
  40. /* Register the window class and return success/failure code. */
  41. return (RegisterClass(&wc));
  42. }
  43. BOOL InitInstance(hInstance, nCmdShow)
  44. HANDLE hInstance; /* Current instance identifier. */
  45. int nCmdShow; /* Param for first ShowWindow() call. */
  46. {
  47. HWND hWnd; /* Main window handle. */
  48. HWND hWndX;
  49. OFSTRUCT ofFileData;
  50. HANDLE hLogFile;
  51. HDC hDC;
  52. int i;
  53. SIZE size;
  54. int length;
  55. BOOL f;
  56. hInst = hInstance;
  57. /* Create a main window for this application instance. */
  58. hWnd = CreateWindow(
  59. "SimpleClass", /* See RegisterClass() call. */
  60. "OLE 2.0 Simple Thunk Testing", /* Text for window title bar. */
  61. WS_OVERLAPPEDWINDOW, /* Window style. */
  62. 280, /* Default horizontal position. */
  63. 50, /* Default vertical position. */
  64. CW_USEDEFAULT, /* Default width. */
  65. CW_USEDEFAULT, /* Default height. */
  66. NULL, /* Overlapped windows have no parent. */
  67. NULL, /* Use the window class menu. */
  68. hInstance, /* This instance owns this window. */
  69. NULL /* Pointer not needed. */
  70. );
  71. /* If window could not be created, return "failure" */
  72. if (!hWnd)
  73. return (FALSE);
  74. ShowWindow(hWnd, nCmdShow); /* Show the window */
  75. UpdateWindow(hWnd); /* Sends WM_PAINT message */
  76. return (TRUE); /* Returns the value from PostQuitMessage */
  77. }
  78. void LogResult( LPSTR message, HRESULT hr )
  79. {
  80. char text[256];
  81. if ( hr ) {
  82. wsprintf(text,"%s:%08lX\n",message,hr);
  83. OutputDebugString(text);
  84. }
  85. }
  86. LONG FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  87. HWND hWnd; /* window handle */
  88. UINT message; /* type of message */
  89. WPARAM wParam; /* additional information */
  90. LONG lParam; /* additional information */
  91. {
  92. FARPROC lpProcAbout; /* pointer to the "About" function */
  93. PAINTSTRUCT ps;
  94. long rc;
  95. int i;
  96. HRESULT hr;
  97. switch (message) {
  98. case WM_COMMAND: /* message: command from application menu */
  99. switch( wParam ) {
  100. case IDM_ABOUT:
  101. lpProcAbout = MakeProcInstance(About, hInst);
  102. DialogBox(hInst, /* current instance */
  103. "AboutBox", /* resource to use */
  104. hWnd, /* parent handle */
  105. lpProcAbout); /* About() instance address */
  106. FreeProcInstance(lpProcAbout);
  107. break; /* Lets Windows process it */
  108. default:
  109. { char text[100];
  110. HDC hdc;
  111. static int position = 0;
  112. position += 20;
  113. wsprintf(text,"Cmd = %04X",wParam);
  114. hdc = GetDC( hWnd );
  115. TextOut(hdc,100,position,text,lstrlen(text));
  116. ReleaseDC( hWnd, hdc );
  117. }
  118. return (DefWindowProc(hWnd, message, wParam, lParam));
  119. case IDM_COINIT:
  120. hr = CoInitialize(NULL);
  121. LogResult( "CoInitialize", hr );
  122. break;
  123. }
  124. break;
  125. case WM_DESTROY: /* message: window being destroyed */
  126. PostQuitMessage(0);
  127. break;
  128. case WM_PAINT:
  129. {
  130. PAINTSTRUCT ps;
  131. HDC hDC;
  132. char text[100];
  133. hDC = BeginPaint( hWnd, &ps );
  134. EndPaint( hWnd, &ps );
  135. }
  136. break;
  137. default: /* Passes it on if unproccessed */
  138. rc = DefWindowProc(hWnd, message, wParam, lParam);
  139. return( rc );
  140. }
  141. return (NULL);
  142. }
  143. BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
  144. HWND hDlg; /* window handle of the dialog box */
  145. UINT message; /* type of message */
  146. WPARAM wParam; /* message-specific information */
  147. LONG lParam;
  148. {
  149. switch (message) {
  150. case WM_INITDIALOG: /* message: initialize dialog box */
  151. return (TRUE);
  152. case WM_COMMAND: /* message: received a command */
  153. if (wParam == IDOK /* "OK" box selected? */
  154. || wParam == IDCANCEL) { /* System menu close command? */
  155. EndDialog(hDlg, TRUE); /* Exits the dialog box */
  156. return (TRUE);
  157. }
  158. break;
  159. }
  160. return (FALSE); /* Didn't process a message */
  161. }