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.

204 lines
5.1 KiB

  1. //+-------------------------------------------------------------------
  2. // File: testsrv.cxx
  3. //
  4. // Contents:
  5. //
  6. // Classes: CBasicSrvCF - IUnknown IClassFactory
  7. // CBasicSrv - IUnknown IPersist IPersistFile IParseDisplayName
  8. //
  9. // Notes: This code is written based on OLE2.0 code. Therefore
  10. // all error codes, defines etc are OLE style rather than Cairo
  11. //
  12. // History: 24-Nov-92 DeanE Created
  13. //---------------------------------------------------------------------
  14. #pragma optimize("",off)
  15. #include <windows.h>
  16. #include <ole2.h>
  17. #include <csrvapp.hxx>
  18. #include <embed.hxx>
  19. #include <stdio.h>
  20. // BUGBUG - memory allocation hacks need these so new and delete don't
  21. // break us
  22. //
  23. #include <malloc.h>
  24. #include <dos.h>
  25. #define IDM_DEBUG 0x100
  26. extern "C" LRESULT FAR PASCAL MainWndProc(HWND, UINT, WPARAM, LPARAM);
  27. void ReportMessage(HWND, WORD);
  28. // This is global because we're still in $%E#$#K 16-bit world
  29. HWND g_hwndMain = NULL;
  30. // Note constructor cannot fail
  31. CTestServerApp tsaMain;
  32. //+--------------------------------------------------------------
  33. // Function: WinMain
  34. //
  35. // Synopsis: Initializes application and controls message pump.
  36. //
  37. // Returns: Exits with exit code 0 if success, non-zero otherwise
  38. //
  39. // History: 25-Nov-92 DeanE Created
  40. //---------------------------------------------------------------
  41. int PASCAL WinMain(
  42. HINSTANCE hInstance,
  43. HINSTANCE hPrevInstance,
  44. LPSTR lpszCmdline,
  45. int nCmdShow)
  46. {
  47. static TCHAR szAppName[] = TEXT("OleServer");
  48. MSG msg;
  49. WNDCLASS wndclass;
  50. if (!hPrevInstance)
  51. {
  52. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  53. wndclass.lpfnWndProc = MainWndProc;
  54. wndclass.cbClsExtra = 0;
  55. wndclass.cbWndExtra = 0;
  56. wndclass.hInstance = hInstance;
  57. wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(125));
  58. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  59. wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
  60. wndclass.lpszMenuName = NULL;
  61. wndclass.lpszClassName = szAppName;
  62. if (0==RegisterClass(&wndclass))
  63. {
  64. // Error! Clean up and exit
  65. return(LOG_ABORT);
  66. }
  67. }
  68. g_hwndMain = CreateWindow(
  69. szAppName,
  70. TEXT("OLE Server"),
  71. WS_OVERLAPPEDWINDOW | WS_VSCROLL,
  72. GetSystemMetrics(SM_CXSCREEN)/12, // Init X pos
  73. GetSystemMetrics(SM_CYSCREEN)/12, // Init Y pos
  74. GetSystemMetrics(SM_CXSCREEN)*2/3, // width
  75. GetSystemMetrics(SM_CYSCREEN)*2/3, // height
  76. NULL,
  77. NULL,
  78. hInstance,
  79. NULL);
  80. if (NULL==g_hwndMain)
  81. {
  82. // Error! Clean up and exit
  83. return(LOG_ABORT);
  84. }
  85. // Add debug option to system menu
  86. HMENU hmenu = GetSystemMenu(g_hwndMain, FALSE);
  87. AppendMenu(hmenu, MF_SEPARATOR, 0, NULL);
  88. AppendMenu(hmenu, MF_STRING | MF_ENABLED, IDM_DEBUG, TEXT("Debug"));
  89. // Initialize Application
  90. if (S_OK != tsaMain.InitApp(lpszCmdline))
  91. {
  92. tsaMain.CloseApp();
  93. return(LOG_ABORT);
  94. }
  95. if (tsaMain.GetEmbeddedFlag())
  96. {
  97. // We're running as an embedded app
  98. // Don't show the main window unless we're instructed to do so
  99. // BUGBUG - In-place editing is NYI
  100. ShowWindow(g_hwndMain, SW_SHOWMINIMIZED);
  101. }
  102. else
  103. {
  104. // We are not running as an embedded app - show the main window
  105. ShowWindow(g_hwndMain, nCmdShow);
  106. }
  107. UpdateWindow(g_hwndMain);
  108. // message loop
  109. while (GetMessage(&msg, NULL, 0, 0))
  110. {
  111. TranslateMessage(&msg);
  112. DispatchMessage(&msg);
  113. }
  114. // Clean up and exit
  115. // BUGBUG - check return code?
  116. tsaMain.CloseApp();
  117. return(0);
  118. }
  119. //+--------------------------------------------------------------
  120. // Function: MainWndProc
  121. //
  122. // Synopsis: Callback for the server window
  123. //
  124. // Returns: Varies dependent on message received.
  125. //
  126. // History: 25-Nov-92 DeanE Created
  127. //---------------------------------------------------------------
  128. extern "C" LRESULT FAR PASCAL MainWndProc(
  129. HWND hwnd,
  130. UINT wMsg,
  131. WPARAM wParam,
  132. LPARAM lParam)
  133. {
  134. switch(wMsg)
  135. {
  136. case WM_DESTROY:
  137. PostQuitMessage(0);
  138. return(0);
  139. case WM_USER:
  140. DestroyWindow(hwnd);
  141. return 0;
  142. case WM_SYSCOMMAND:
  143. if (wParam == IDM_DEBUG)
  144. {
  145. // Request for a debug breakpoint!
  146. DebugBreak();
  147. }
  148. default:
  149. break;
  150. }
  151. return(DefWindowProc(hwnd, wMsg, wParam, lParam));
  152. }
  153. void ReportMessage(HWND hwnd, WORD wParam)
  154. {
  155. TCHAR szBuffer[MAX_PATH];
  156. szBuffer[0] = '\0';
  157. switch (wParam)
  158. {
  159. case MB_SHOWVERB:
  160. lstrcpy(szBuffer, TEXT("OLEIVERB_SHOW Received"));
  161. break;
  162. case MB_PRIMVERB:
  163. lstrcpy(szBuffer, TEXT("OLEIVERB_PRIMARY Received"));
  164. break;
  165. default:
  166. lstrcpy(szBuffer, TEXT("Unrecognized ReportMessage code"));
  167. break;
  168. }
  169. MessageBox(hwnd, szBuffer, TEXT("OLE Server"), MB_ICONINFORMATION | MB_OK);
  170. }