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.

522 lines
16 KiB

  1. //**********************************************************************
  2. // File name: Simple.cpp
  3. //
  4. // Main source file for the Simple OLE 2.0 object container
  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) 1992 - 1993 Microsoft Corporation. All rights reserved.
  14. //**********************************************************************
  15. #include "pre.h"
  16. #include "iocs.h"
  17. #include "ias.h"
  18. #include "ioipf.h"
  19. #include "ioips.h"
  20. #include "app.h"
  21. #include "site.h"
  22. #include "doc.h"
  23. #include "tests.h"
  24. // This line is needed for the debug utilities in OLE2UI
  25. extern "C" {
  26. OLEDBGDATA_MAIN(TEXT("SIMPCNTR"))
  27. }
  28. CSimpleApp FAR * lpCSimpleApp;
  29. void DeactivateIfActive(HWND hWnd)
  30. {
  31. LPOLEINPLACEOBJECT lpObject;
  32. MSG msg;
  33. msg.message = WM_LBUTTONDOWN;
  34. if (lpCSimpleApp->m_lpDoc->m_fInPlaceActive)
  35. {
  36. // We are in the process of deactiving the in place object
  37. lpCSimpleApp->m_fDeactivating = TRUE;
  38. lpCSimpleApp->m_lpDoc->m_lpSite->m_lpOleObject->QueryInterface(
  39. IID_IOleInPlaceObject, (LPVOID FAR *)&lpObject);
  40. lpObject->UIDeactivate();
  41. // this code is needed because we don't support inside out.
  42. RECT rect;
  43. lpCSimpleApp->m_lpDoc->m_lpSite->GetObjRect(&rect);
  44. lpCSimpleApp->m_lpDoc->m_lpSite->m_lpOleObject->DoVerb(
  45. OLEIVERB_HIDE,
  46. &msg,
  47. &lpCSimpleApp->m_lpDoc->m_lpSite->m_OleClientSite,
  48. -1, hWnd, &rect);
  49. lpObject->Release();
  50. // We are done deactiving
  51. lpCSimpleApp->m_fDeactivating = FALSE;
  52. }
  53. }
  54. BOOL fBeVerbose = FALSE;
  55. extern "C"
  56. void TestDebugOut(LPSTR psz)
  57. {
  58. if (fBeVerbose)
  59. {
  60. OutputDebugStringA(psz);
  61. }
  62. }
  63. //**********************************************************************
  64. //
  65. // WinMain
  66. //
  67. // Purpose:
  68. //
  69. // Program entry point
  70. //
  71. // Parameters:
  72. //
  73. // HANDLE hInstance - Instance handle for this instance
  74. //
  75. // HANDLE hPrevInstance - Instance handle for the last instance
  76. //
  77. // LPSTR lpCmdLine - Pointer to the command line
  78. //
  79. // int nCmdShow - Window State
  80. //
  81. // Return Value:
  82. //
  83. // msg.wParam
  84. //
  85. // Function Calls:
  86. // Function Location
  87. //
  88. // CSimpleApp::CSimpleApp APP.CPP
  89. // CSimpleApp::AddRef APP.CPP
  90. // CSimpleApp::Release APP.CPP
  91. // CSimpleApp::fInitApplication APP.CPP
  92. // CSimpleApp::fInitInstance APP.CPP
  93. // CSimpleApp::HandleAccelerators APP.CPP
  94. // CSimpleApp::~CSimpleApp APP.CPP
  95. // OleUIInitialize OLE2UI
  96. // OleUIUninitialize OLE2UI
  97. // GetMessage Windows API
  98. // TranslateMessage Windows API
  99. // DispatchMessage Windows API
  100. //
  101. //********************************************************************
  102. int PASCAL WinMain
  103. #ifdef WIN32
  104. (HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
  105. #else
  106. (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  107. #endif
  108. {
  109. MSG msg;
  110. // needed for LRPC to work properly...
  111. SetMessageQueue(96);
  112. lpCSimpleApp = new CSimpleApp;
  113. fBeVerbose = GetProfileInt("OLEUTEST","BeVerbose",0);
  114. if(fBeVerbose == 0)
  115. {
  116. fBeVerbose = GetProfileInt("OLEUTEST","simpcntr",0);
  117. }
  118. if (!lpCSimpleApp)
  119. {
  120. /* memory allocation error. cannot carry on.
  121. */
  122. return(FALSE);
  123. }
  124. // we will add one ref count on our App. later when we want to destroy
  125. // the App object we will release this ref count. when the App's ref
  126. // count goes to 0, it will be deleted.
  127. lpCSimpleApp->AddRef();
  128. char *pszTemp;
  129. // process the command line
  130. if( (pszTemp = strstr(lpCmdLine, "-driver")) )
  131. {
  132. //we were launched by the test driver
  133. lpCSimpleApp->m_hDriverWnd = (HWND)strtoul(pszTemp+8, NULL, 10);
  134. }
  135. // app initialization
  136. if (!hPrevInstance)
  137. if (!lpCSimpleApp->fInitApplication(hInstance))
  138. {
  139. lpCSimpleApp->Release();
  140. return (FALSE);
  141. }
  142. // instance initialization
  143. if (!lpCSimpleApp->fInitInstance(hInstance, nCmdShow))
  144. {
  145. lpCSimpleApp->Release();
  146. return (FALSE);
  147. }
  148. /* Initialization required for OLE 2 UI library. This call is
  149. ** needed ONLY if we are using the static link version of the UI
  150. ** library. If we are using the DLL version, we should NOT call
  151. ** this function in our application.
  152. ** The 3rd and 4th parameters passed the OleUIInitialize
  153. ** function are strings which are used to name two custom
  154. ** control classes used by the OLE2UI library. These strings
  155. ** must be unique for each application that uses the OLE2UI
  156. ** library. These strings are typically composed by combining
  157. ** the APPNAME with a suffix in order to be unique for a
  158. ** particular application. The special symbols "SZCLASSICONBOX"
  159. ** and "SZCLASSRESULTIMAGE" are used define these strings. These
  160. ** symbols must be defined in a header file that is included
  161. ** both in this file AND the resource file that included the
  162. ** "OLE2UI.RC" resoure file. These symbols should be used in the
  163. ** call to OleUIInitialize and are referenced in the INSOBJ.DLG
  164. ** and PASTESPL.DLG resouce files of the OLE2UI library.
  165. */
  166. #if 0 // We use the DLL form of OLE2U32A
  167. if (!OleUIInitialize(hInstance, hPrevInstance, TEXT(SZCLASSICONBOX),
  168. TEXT(SZCLASSRESULTIMAGE)))
  169. {
  170. OleDbgOut(TEXT("Could not initialize OLEUI library\n"));
  171. lpCSimpleApp->Release();
  172. return FALSE;
  173. }
  174. #endif
  175. // message loop
  176. while (GetMessage(&msg, NULL, NULL, NULL))
  177. if (!lpCSimpleApp->HandleAccelerators(&msg))
  178. {
  179. TranslateMessage(&msg); /* Translates virtual key codes */
  180. DispatchMessage(&msg); /* Dispatches message to window */
  181. }
  182. #if 0 // We use the DLL form of OLE2U32A
  183. // De-initialization for UI libraries. Just like OleUIInitialize, this
  184. // funciton is needed ONLY if we are using the static link version of the
  185. // OLE UI library.
  186. OleUIUninitialize();
  187. #endif
  188. // Release the ref count added on the App above. this will make
  189. // the App's ref count go to 0, and the App object will be deleted.
  190. lpCSimpleApp->Release();
  191. return (msg.wParam); /* Returns the value from PostQuitMessage */
  192. }
  193. //**********************************************************************
  194. //
  195. // MainWndProc
  196. //
  197. // Purpose:
  198. //
  199. // Processes messages for the frame window
  200. //
  201. // Parameters:
  202. //
  203. // HWND hWnd - Window handle for frame window
  204. //
  205. // UINT message - Message value
  206. //
  207. // WPARAM wParam - Message info
  208. //
  209. // LPARAM lParam - Message info
  210. //
  211. // Return Value:
  212. //
  213. // long
  214. //
  215. // Function Calls:
  216. // Function Location
  217. //
  218. // CSimpleApp::lCommandHandler APP.CPP
  219. // CSimpleApp::DestroyDocs APP.CPP
  220. // CSimpleApp::lCreateDoc APP.CPP
  221. // CSimpleApp::lSizeHandler APP.CPP
  222. // CSimpleDoc::lAddVerbs DOC.CPP
  223. // CSimpleDoc::QueryNewPalette APP.CPP
  224. // SendMessage Windows API
  225. // PostQuitMessage Windows API
  226. // DefWindowProc Windows API
  227. //
  228. //
  229. //********************************************************************
  230. LRESULT FAR PASCAL EXPORT MainWndProc(HWND hWnd, UINT message,
  231. WPARAM wParam, LPARAM lParam)
  232. {
  233. switch (message)
  234. {
  235. case WM_CLOSE:
  236. DestroyWindow(lpCSimpleApp->m_hAppWnd);
  237. break;
  238. case WM_TEST1:
  239. // Do the unit test
  240. Test1(lpCSimpleApp);
  241. break;
  242. case WM_SETFOCUS:
  243. // If we have an inplace application it needs to get the focus
  244. if (lpCSimpleApp->m_lpDoc->m_fInPlaceActive
  245. && !lpCSimpleApp->m_fDeactivating)
  246. {
  247. SetFocus(lpCSimpleApp->m_hwndUIActiveObj);
  248. break;
  249. }
  250. // Othewise default behavior is enough
  251. return (DefWindowProc(hWnd, message, wParam, lParam));
  252. case WM_COMMAND: // message: command from application menu
  253. return lpCSimpleApp->lCommandHandler(hWnd, message,
  254. wParam, lParam);
  255. break;
  256. case WM_CREATE:
  257. return lpCSimpleApp->lCreateDoc(hWnd, message, wParam, lParam);
  258. break;
  259. case WM_DESTROY: // message: window being destroyed
  260. lpCSimpleApp->DestroyDocs(); // need to destroy the doc...
  261. PostQuitMessage(0);
  262. break;
  263. case WM_INITMENUPOPUP:
  264. // is this the edit menu?
  265. if ( LOWORD(lParam) == 1)
  266. return lpCSimpleApp->m_lpDoc->lAddVerbs();
  267. break;
  268. // this code is needed for 256 color objects to work properly.
  269. case WM_QUERYNEWPALETTE:
  270. if (! lpCSimpleApp->m_fAppActive)
  271. return 0L;
  272. return lpCSimpleApp->QueryNewPalette();
  273. case WM_PALETTECHANGED:
  274. {
  275. HWND hWndPalChg = (HWND) wParam;
  276. if (hWnd != hWndPalChg)
  277. wSelectPalette(hWnd, lpCSimpleApp->m_hStdPal,
  278. TRUE/*fBackground*/);
  279. /* OLE2NOTE: always forward the WM_PALETTECHANGED message (via
  280. ** SendMessage) to any in-place objects that currently have
  281. ** their window visible. this gives these objects the chance
  282. ** to select their palettes. this is
  283. ** REQUIRED by all in-place containers independent of
  284. ** whether they use color palettes themselves--their objects
  285. ** may use color palettes.
  286. ** (see ContainerDoc_ForwardPaletteChangedMsg for more info)
  287. */
  288. if (lpCSimpleApp->m_lpDoc && lpCSimpleApp->m_lpDoc->m_lpSite &&
  289. lpCSimpleApp->m_lpDoc->m_lpSite->m_hwndIPObj)
  290. {
  291. SendMessage(lpCSimpleApp->m_lpDoc->m_lpSite->m_hwndIPObj,
  292. WM_PALETTECHANGED, wParam, lParam);
  293. }
  294. return 0L;
  295. }
  296. case WM_ACTIVATEAPP:
  297. if ((lpCSimpleApp->m_fAppActive = (BOOL)wParam) == TRUE)
  298. lpCSimpleApp->QueryNewPalette();
  299. if (lpCSimpleApp->m_lpDoc->m_lpActiveObject)
  300. {
  301. lpCSimpleApp->m_lpDoc->m_lpActiveObject->OnFrameWindowActivate(
  302. (BOOL)wParam);
  303. }
  304. break;
  305. case WM_SIZE:
  306. return lpCSimpleApp->lSizeHandler(hWnd, message, wParam, lParam);
  307. default: // Passes it on if unproccessed
  308. return (DefWindowProc(hWnd, message, wParam, lParam));
  309. }
  310. return (NULL);
  311. }
  312. //**********************************************************************
  313. //
  314. // About
  315. //
  316. // Purpose:
  317. //
  318. // Processes dialog box messages
  319. //
  320. // Parameters:
  321. //
  322. // HWND hWnd - Window handle for dialog box
  323. //
  324. // UINT message - Message value
  325. //
  326. // WPARAM wParam - Message info
  327. //
  328. // LPARAM lParam - Message info
  329. //
  330. // Return Value:
  331. // TRUE if message processed, FALSE otherwise
  332. //
  333. // Function Calls:
  334. // Function Location
  335. //
  336. // EndDialog Windows API
  337. //
  338. //
  339. //********************************************************************
  340. INT_PTR FAR PASCAL EXPORT About(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
  341. {
  342. switch (message)
  343. {
  344. case WM_INITDIALOG: /* message: initialize dialog box */
  345. return (TRUE);
  346. case WM_COMMAND: /* message: received a command */
  347. if (wParam == IDOK /* "OK" box selected? */
  348. || wParam == IDCANCEL) /* System menu close command? */
  349. {
  350. EndDialog(hDlg, TRUE); /* Exits the dialog box */
  351. return (TRUE);
  352. }
  353. break;
  354. }
  355. return (FALSE); /* Didn't process a message */
  356. }
  357. //**********************************************************************
  358. //
  359. // DocWndProc
  360. //
  361. // Purpose:
  362. //
  363. // Processes dialog box messages
  364. //
  365. // Parameters:
  366. //
  367. // HWND hWnd - Window handle for doc window
  368. //
  369. // UINT message - Message value
  370. //
  371. // WPARAM wParam - Message info
  372. //
  373. // LPARAM lParam - Message info
  374. //
  375. // Return Value:
  376. // NULL
  377. //
  378. // Function Calls:
  379. // Function Location
  380. //
  381. // CSimpleApp::PaintApp APP.CPP
  382. // BeginPaint Windows API
  383. // EndPaint Windows API
  384. // DefWindowProc Windows API
  385. // PtInRect Windows API
  386. // CSimpleSite::GetObjRect SITE.CPP
  387. // IOleObject::QueryInterface Object
  388. // IOleInPlaceObject::UIDeactivate Object
  389. // IOleObject::DoVerb Object
  390. // IOleInPlaceObject::Release Object
  391. //
  392. //
  393. //********************************************************************
  394. LRESULT FAR PASCAL EXPORT DocWndProc(HWND hWnd, UINT message,
  395. WPARAM wParam, LPARAM lParam)
  396. {
  397. HDC hDC;
  398. PAINTSTRUCT ps;
  399. switch (message)
  400. {
  401. case WM_SETFOCUS:
  402. // If we have an inplace application it needs to get the focus
  403. if (lpCSimpleApp->m_lpDoc->m_fInPlaceActive
  404. && !lpCSimpleApp->m_fDeactivating)
  405. {
  406. SetFocus(lpCSimpleApp->m_hwndUIActiveObj);
  407. break;
  408. }
  409. // Otherwise default behavior is enough
  410. return (DefWindowProc(hWnd, message, wParam, lParam));
  411. case WM_PAINT:
  412. hDC = BeginPaint(hWnd, &ps);
  413. if (lpCSimpleApp)
  414. lpCSimpleApp->PaintApp (hDC);
  415. EndPaint(hWnd, &ps);
  416. break;
  417. case WM_LBUTTONDBLCLK:
  418. {
  419. POINT pt;
  420. pt.x = (int)(short)LOWORD (lParam );
  421. pt.y = (int)(short)HIWORD (lParam );
  422. if (lpCSimpleApp->m_lpDoc->m_lpSite &&
  423. lpCSimpleApp->m_lpDoc->m_lpSite->m_lpOleObject)
  424. {
  425. RECT rect;
  426. lpCSimpleApp->m_lpDoc->m_lpSite->GetObjRect(&rect);
  427. if ( PtInRect(&rect, pt) )
  428. {
  429. // Execute object's default verb
  430. lpCSimpleApp->m_lpDoc->m_lpSite->m_lpOleObject->DoVerb(
  431. OLEIVERB_PRIMARY, (LPMSG)&message,
  432. &lpCSimpleApp->m_lpDoc->m_lpSite->m_OleClientSite,
  433. -1, hWnd, &rect);
  434. }
  435. }
  436. }
  437. break;
  438. // no code is added to WM_LBUTTONDOWN for context sensitive help, because
  439. // this app does not do context sensitive help.
  440. case WM_LBUTTONDOWN:
  441. DeactivateIfActive(hWnd);
  442. break;
  443. default: /* Passes it on if unproccessed */
  444. return (DefWindowProc(hWnd, message, wParam, lParam));
  445. }
  446. return (NULL);
  447. }