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.

357 lines
9.8 KiB

  1. //**********************************************************************
  2. // File name: simpsvr.cpp
  3. //
  4. // Main source file for the simple OLE 2.0 server
  5. //
  6. // Functions:
  7. //
  8. // WinMain - Program entry point
  9. // MainWndProc - Processes messages for the frame window
  10. // About - Processes messages for the about dialog
  11. // DocWndProc - Processes messages for the doc window
  12. //
  13. // Copyright (c) 1993 Microsoft Corporation. All rights reserved.
  14. //**********************************************************************
  15. #include "pre.h"
  16. #include "obj.h"
  17. #include "app.h"
  18. #include "doc.h"
  19. #include "icf.h"
  20. // This line is needed for the debug utilities in OLE2UI
  21. extern "C" {
  22. OLEDBGDATA_MAIN("SIMPSVR")
  23. }
  24. CSimpSvrApp FAR * lpCSimpSvrApp;
  25. CClassFactory FAR * lpClassFactory;
  26. BOOL fBeVerbose = FALSE;
  27. extern "C"
  28. void TestDebugOut(LPSTR psz)
  29. {
  30. if (fBeVerbose)
  31. {
  32. OutputDebugString(psz);
  33. }
  34. }
  35. //**********************************************************************
  36. //
  37. // WinMain
  38. //
  39. // Purpose:
  40. //
  41. // Program entry point
  42. //
  43. // Parameters:
  44. //
  45. // HANDLE hInstance - Instance handle for this instance
  46. //
  47. // HANDLE hPrevInstance - Instance handle for the last instance
  48. //
  49. // LPSTR lpCmdLine - Pointer to the command line
  50. //
  51. // int nCmdShow - Window State
  52. //
  53. // Return Value:
  54. //
  55. // msg.wParam
  56. //
  57. // Function Calls:
  58. // Function Location
  59. //
  60. // CSimpSvrApp::CSimpSvrApp APP.CPP
  61. // CSimpSvrApp::fInitApplication APP.CPP
  62. // CSimpSvrApp::fInitInstance APP.CPP
  63. // CSimpSvrApp::HandleAccelerators APP.CPP
  64. // CSimpSvrApp::~CSimpSvrApp APP.CPP
  65. // OleUIInitialize OLE2UI
  66. // OleUIUninitialize OLE2UI
  67. // GetMessage Windows API
  68. // TranslateMessage Windows API
  69. // DispatchMessage Windows API
  70. //
  71. // Comments:
  72. //
  73. //********************************************************************
  74. int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
  75. {
  76. MSG msg;
  77. fBeVerbose = GetProfileInt("OLEUTEST","BeVerbose",0);
  78. if(fBeVerbose == 0)
  79. {
  80. fBeVerbose = GetProfileInt("OLEUTEST","spsvr16",0);
  81. }
  82. // recommended size for OLE apps
  83. SetMessageQueue(96);
  84. lpCSimpSvrApp = new CSimpSvrApp;
  85. lpCSimpSvrApp->AddRef(); // need the app ref. count at 1 to hold the
  86. // app alive.
  87. lpCSimpSvrApp->ParseCmdLine(lpCmdLine);
  88. // app initialization
  89. if (!hPrevInstance)
  90. if (!lpCSimpSvrApp->fInitApplication(hInstance))
  91. return (FALSE);
  92. // instance initialization
  93. if (!lpCSimpSvrApp->fInitInstance(hInstance, nCmdShow, lpClassFactory))
  94. return (FALSE);
  95. /* Initialization required for OLE 2 UI library. This call is
  96. ** needed ONLY if we are using the static link version of the UI
  97. ** library. If we are using the DLL version, we should NOT call
  98. ** this function in our application.
  99. */
  100. if (!OleUIInitialize(hInstance, hPrevInstance))
  101. {
  102. OleDbgOut("Could not initialize OLEUI library\n");
  103. return FALSE;
  104. }
  105. // message loop
  106. while (GetMessage(&msg, NULL, NULL, NULL))
  107. {
  108. if (lpCSimpSvrApp->IsInPlaceActive())
  109. // Only key messages need to be sent to OleTranslateAccelerator. Any other message
  110. // would result in an extra FAR call to occur for that message processing...
  111. if ( (msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST) )
  112. // OleTranslateAccelerator MUST be called, even though this application does
  113. // not have an accelerator table. This has to be done in order for the
  114. // mneumonics for the top level menu items to work properly.
  115. if ( OleTranslateAccelerator ( lpCSimpSvrApp->GetDoc()->GetObj()->GetInPlaceFrame(),
  116. lpCSimpSvrApp->GetDoc()->GetObj()->GetFrameInfo(),
  117. &msg) == NOERROR)
  118. continue;
  119. TranslateMessage(&msg); /* Translates virtual key codes */
  120. DispatchMessage(&msg); /* Dispatches message to window */
  121. }
  122. // De-initialization for UI libraries. Just like OleUIInitialize, this
  123. // funciton is needed ONLY if we are using the static link version of the
  124. // OLE UI library.
  125. OleUIUninitialize();
  126. return (msg.wParam); /* Returns the value from PostQuitMessage */
  127. }
  128. //**********************************************************************
  129. //
  130. // MainWndProc
  131. //
  132. // Purpose:
  133. //
  134. // Processes messages for the frame window
  135. //
  136. // Parameters:
  137. //
  138. // HWND hWnd - Window handle for frame window
  139. //
  140. // UINT message - Message value
  141. //
  142. // WPARAM wParam - Message info
  143. //
  144. // LPARAM lParam - Message info
  145. //
  146. // Return Value:
  147. //
  148. // long
  149. //
  150. // Function Calls:
  151. // Function Location
  152. //
  153. // CSimpSvrApp::lCommandHandler APP.CPP
  154. // CSimpSvrApp::DestroyDocs APP.CPP
  155. // CSimpSvrApp::lCreateDoc APP.CPP
  156. // CSimpSvrApp::lSizeHandler APP.CPP
  157. // CGameDoc::lAddVerbs DOC.CPP
  158. // PostQuitMessage Windows API
  159. // DefWindowProc Windows API
  160. //
  161. // Comments:
  162. //
  163. //********************************************************************
  164. long FAR PASCAL _export MainWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  165. {
  166. switch (message)
  167. {
  168. case WM_CLOSE:
  169. TestDebugOut("*** In WM_CLOSE *** \r\n");
  170. // if there is still a document
  171. if (lpCSimpSvrApp->GetDoc())
  172. // if there is still an object within a document
  173. if (lpCSimpSvrApp->GetDoc()->GetObj()) // this case occurs if there is still
  174. // an outstanding Ref count on the object
  175. // when the app is trying to go away.
  176. // typically this case will occur in
  177. // the "open" editing mode.
  178. // Close the document
  179. lpCSimpSvrApp->GetDoc()->Close();
  180. // hide the app window
  181. lpCSimpSvrApp->HideAppWnd();
  182. // if we were started by ole, unregister the class factory, otherwise
  183. // remove the ref count on our dummy OLE object
  184. if (lpCSimpSvrApp->IsStartedByOle())
  185. CoRevokeClassObject(lpCSimpSvrApp->GetRegisterClass());
  186. else
  187. lpCSimpSvrApp->GetOleObject()->Release();
  188. lpCSimpSvrApp->Release(); // This should close the app.
  189. break;
  190. case WM_COMMAND: // message: command from application menu
  191. return lpCSimpSvrApp->lCommandHandler(hWnd, message, wParam, lParam);
  192. break;
  193. case WM_CREATE:
  194. return lpCSimpSvrApp->lCreateDoc(hWnd, message, wParam, lParam);
  195. break;
  196. case WM_DESTROY: // message: window being destroyed
  197. PostQuitMessage(0);
  198. break;
  199. case WM_SIZE:
  200. return lpCSimpSvrApp->lSizeHandler(hWnd, message, wParam, lParam);
  201. default: // Passes it on if unproccessed
  202. return (DefWindowProc(hWnd, message, wParam, lParam));
  203. }
  204. return (NULL);
  205. }
  206. //**********************************************************************
  207. //
  208. // About
  209. //
  210. // Purpose:
  211. //
  212. // Processes dialog box messages
  213. //
  214. // Parameters:
  215. //
  216. // HWND hWnd - Window handle for dialog box
  217. //
  218. // UINT message - Message value
  219. //
  220. // WPARAM wParam - Message info
  221. //
  222. // LPARAM lParam - Message info
  223. //
  224. // Return Value:
  225. //
  226. // Function Calls:
  227. // Function Location
  228. //
  229. // EndDialog Windows API
  230. //
  231. // Comments:
  232. //
  233. //********************************************************************
  234. BOOL FAR PASCAL _export About(HWND hDlg,unsigned message,WORD wParam,LONG lParam)
  235. {
  236. switch (message) {
  237. case WM_INITDIALOG: /* message: initialize dialog box */
  238. return (TRUE);
  239. case WM_COMMAND: /* message: received a command */
  240. if (wParam == IDOK /* "OK" box selected? */
  241. || wParam == IDCANCEL) { /* System menu close command? */
  242. EndDialog(hDlg, TRUE); /* Exits the dialog box */
  243. return (TRUE);
  244. }
  245. break;
  246. }
  247. return (FALSE); /* Didn't process a message */
  248. }
  249. //**********************************************************************
  250. //
  251. // DocWndProc
  252. //
  253. // Purpose:
  254. //
  255. // Processes dialog box messages
  256. //
  257. // Parameters:
  258. //
  259. // HWND hWnd - Window handle for doc window
  260. //
  261. // UINT message - Message value
  262. //
  263. // WPARAM wParam - Message info
  264. //
  265. // LPARAM lParam - Message info
  266. //
  267. // Return Value:
  268. //
  269. // Function Calls:
  270. // Function Location
  271. //
  272. // CSimpSvrApp::PaintApp APP.CPP
  273. // BeginPaint Windows API
  274. // EndPaint Windows API
  275. // DefWindowProc Windows API
  276. // IOleObject::QueryInterface Object
  277. // IOleInPlaceObject::UIDeactivate Object
  278. // IOleObject::DoVerb Object
  279. // IOleInPlaceObject::Release Object
  280. //
  281. // Comments:
  282. //
  283. //********************************************************************
  284. long FAR PASCAL _export DocWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  285. {
  286. HDC hDC;
  287. PAINTSTRUCT ps;
  288. switch (message) {
  289. case WM_COMMAND: // message: command from application menu
  290. return lpCSimpSvrApp->lCommandHandler(hWnd, message, wParam, lParam);
  291. break;
  292. case WM_PAINT:
  293. hDC = BeginPaint(hWnd, &ps);
  294. // tell the app class to paint itself
  295. if (lpCSimpSvrApp)
  296. lpCSimpSvrApp->PaintApp (hDC);
  297. EndPaint(hWnd, &ps);
  298. break;
  299. case WM_MENUSELECT:
  300. lpCSimpSvrApp->SetStatusText();
  301. break;
  302. default: /* Passes it on if unproccessed */
  303. return (DefWindowProc(hWnd, message, wParam, lParam));
  304. }
  305. return (NULL);
  306. }