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.

1060 lines
30 KiB

  1. //**********************************************************************
  2. // File name: app.cpp
  3. //
  4. // Implementation file for the CSimpleApp Class
  5. //
  6. // Functions:
  7. //
  8. // See app.h for a list of member functions.
  9. //
  10. // Copyright (c) 1992 - 1993 Microsoft Corporation. All rights reserved.
  11. //**********************************************************************
  12. #include "pre.h"
  13. #include "iocs.h"
  14. #include "ias.h"
  15. #include "ioipf.h"
  16. #include "ioips.h"
  17. #include "app.h"
  18. #include "site.h"
  19. #include "doc.h"
  20. #include <testmess.h>
  21. extern void DeactivateIfActive(HWND hWnd);
  22. #ifdef WIN32
  23. extern INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam,
  24. LPARAM lParam);
  25. #endif
  26. //**********************************************************************
  27. //
  28. // CSimpleApp::CSimpleApp()
  29. //
  30. // Purpose:
  31. //
  32. // Constructor for CSimpleApp
  33. //
  34. // Parameters:
  35. //
  36. // None
  37. //
  38. // Return Value:
  39. //
  40. // None
  41. //
  42. // Function Calls:
  43. // Function Location
  44. //
  45. // TestDebugOut Windows API
  46. // SetRectEmpty Windows API
  47. //
  48. // Comments:
  49. //
  50. // CSimpleApp has a contained COleInPlaceFrame. On construction
  51. // of CSimpleApp, we explicitly call the constructor of this
  52. // contained class and pass a copy of the this pointer, so that
  53. // COleInPlaceFrame can refer back to this class
  54. //
  55. //********************************************************************
  56. #pragma warning(disable : 4355) // turn off this warning. This warning
  57. // tells us that we are passing this in
  58. // an initializer, before "this" is through
  59. // initializing. This is ok, because
  60. // we just store the ptr in the other
  61. // constructor
  62. CSimpleApp::CSimpleApp() : m_OleInPlaceFrame(this)
  63. #pragma warning (default : 4355) // Turn the warning back on
  64. {
  65. TestDebugOut(TEXT("In CSimpleApp's Constructor \r\n"));
  66. // Set Ref Count
  67. m_nCount = 0;
  68. // clear members
  69. m_hAppWnd = NULL;
  70. m_hInst = NULL;
  71. m_lpDoc = NULL;
  72. // Make sure we don't think we are deactivating
  73. m_fDeactivating = FALSE;
  74. // We haven't got a unit test accelerator so ...
  75. m_fGotUtestAccelerator = FALSE;
  76. // clear flags
  77. m_fInitialized = FALSE;
  78. m_fCSHMode = FALSE;
  79. m_fMenuMode = FALSE;
  80. // used for inplace
  81. SetRectEmpty(&nullRect);
  82. }
  83. //**********************************************************************
  84. //
  85. // CSimpleApp::~CSimpleApp()
  86. //
  87. // Purpose:
  88. //
  89. // Destructor for CSimpleApp Class.
  90. //
  91. // Parameters:
  92. //
  93. // None
  94. //
  95. // Return Value:
  96. //
  97. // None
  98. //
  99. // Function Calls:
  100. // Function Location
  101. //
  102. // TestDebugOut Windows API
  103. // DeleteObject Windows API
  104. // OleUninitialize OLE API
  105. //
  106. //
  107. //********************************************************************
  108. CSimpleApp::~CSimpleApp()
  109. {
  110. TestDebugOut(TEXT("In CSimpleApp's Destructor\r\n"));
  111. if (m_hStdPal)
  112. DeleteObject(m_hStdPal);
  113. // need to uninit the library...
  114. if (m_fInitialized)
  115. OleUninitialize();
  116. }
  117. //**********************************************************************
  118. //
  119. // CSimpleApp::DestroyDocs()
  120. //
  121. // Purpose:
  122. //
  123. // Destroys all of the open documents in the application (Only one
  124. // since this is an SDI app, but could easily be modified to
  125. // support MDI).
  126. //
  127. // Parameters:
  128. //
  129. // None
  130. //
  131. // Return Value:
  132. //
  133. // None
  134. //
  135. // Function Calls:
  136. // Function Location
  137. // CSimpDoc::Close DOC.CPP
  138. //
  139. //
  140. //********************************************************************
  141. void CSimpleApp::DestroyDocs()
  142. {
  143. m_lpDoc->Close(); // we have only 1 document
  144. }
  145. //**********************************************************************
  146. //
  147. // CSimpleApp::QueryInterface
  148. //
  149. // Purpose:
  150. //
  151. // Used for interface negotiation at the application level.
  152. //
  153. // Parameters:
  154. //
  155. // REFIID riid - A reference to the interface that is
  156. // being queried.
  157. //
  158. // LPVOID FAR* ppvObj - An out parameter to return a pointer to
  159. // the interface.
  160. //
  161. // Return Value:
  162. //
  163. // S_OK - The interface is supported.
  164. // E_NOINTERFACE - The interface is not supported
  165. //
  166. // Function Calls:
  167. // Function Location
  168. //
  169. // TestDebugOut Windows API
  170. // IsEqualIID OLE API
  171. // ResultFromScode OLE API
  172. // COleInPlaceFrame::AddRef IOIPF.CPP
  173. // CSimpleApp::AddRef APP.CPP
  174. //
  175. // Comments:
  176. //
  177. // Note that this QueryInterface is associated with the frame.
  178. // Since the application could potentially have multiple documents
  179. // and multiple objects, a lot of the interfaces are ambiguous.
  180. // (ie. which IOleObject is returned?). For this reason, only
  181. // pointers to interfaces associated with the frame are returned.
  182. // In this implementation, Only IOleInPlaceFrame (or one of the
  183. // interfaces it is derived from) can be returned.
  184. //
  185. //********************************************************************
  186. STDMETHODIMP CSimpleApp::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  187. {
  188. TestDebugOut(TEXT("In CSimpleApp::QueryInterface\r\n"));
  189. *ppvObj = NULL; // must set out pointer parameters to NULL
  190. // looking for IUnknown
  191. if ( IsEqualIID(riid, IID_IUnknown))
  192. {
  193. AddRef();
  194. *ppvObj = this;
  195. return ResultFromScode(S_OK);
  196. }
  197. // looking for IOleWindow
  198. if ( IsEqualIID(riid, IID_IOleWindow))
  199. {
  200. m_OleInPlaceFrame.AddRef();
  201. *ppvObj=&m_OleInPlaceFrame;
  202. return ResultFromScode(S_OK);
  203. }
  204. // looking for IOleInPlaceUIWindow
  205. if ( IsEqualIID(riid, IID_IOleInPlaceUIWindow))
  206. {
  207. m_OleInPlaceFrame.AddRef();
  208. *ppvObj=&m_OleInPlaceFrame;
  209. return ResultFromScode(S_OK);
  210. }
  211. // looking for IOleInPlaceFrame
  212. if ( IsEqualIID(riid, IID_IOleInPlaceFrame))
  213. {
  214. m_OleInPlaceFrame.AddRef();
  215. *ppvObj=&m_OleInPlaceFrame;
  216. return ResultFromScode(S_OK);
  217. }
  218. // Not a supported interface
  219. return ResultFromScode(E_NOINTERFACE);
  220. }
  221. //**********************************************************************
  222. //
  223. // CSimpleApp::AddRef
  224. //
  225. // Purpose:
  226. //
  227. // Adds to the reference count at the Application level.
  228. //
  229. // Parameters:
  230. //
  231. // None
  232. //
  233. // Return Value:
  234. //
  235. // ULONG - The new reference count of the application.
  236. //
  237. // Function Calls:
  238. // Function Location
  239. //
  240. // TestDebugOut Windows API
  241. //
  242. // Comments:
  243. //
  244. // Due to the reference counting model that is used in this
  245. // implementation, this reference count is the sum of the
  246. // reference counts on all interfaces of all objects open
  247. // in the application.
  248. //
  249. //********************************************************************
  250. STDMETHODIMP_(ULONG) CSimpleApp::AddRef()
  251. {
  252. TestDebugOut(TEXT("In CSimpleApp::AddRef\r\n"));
  253. return ++m_nCount;
  254. }
  255. //**********************************************************************
  256. //
  257. // CSimpleApp::Release
  258. //
  259. // Purpose:
  260. //
  261. // Decrements the reference count at this level
  262. //
  263. // Parameters:
  264. //
  265. // None
  266. //
  267. // Return Value:
  268. //
  269. // ULONG - The new reference count of the application.
  270. //
  271. // Function Calls:
  272. // Function Location
  273. //
  274. // TestDebugOut Windows API
  275. //
  276. //
  277. //********************************************************************
  278. STDMETHODIMP_(ULONG) CSimpleApp::Release()
  279. {
  280. TestDebugOut(TEXT("In CSimpleApp::Release\r\n"));
  281. if (--m_nCount == 0)
  282. {
  283. delete this;
  284. return 0;
  285. }
  286. return m_nCount;
  287. }
  288. //**********************************************************************
  289. //
  290. // CSimpleApp::fInitApplication
  291. //
  292. // Purpose:
  293. //
  294. // Initializes the application
  295. //
  296. // Parameters:
  297. //
  298. // HANDLE hInstance - Instance handle of the application.
  299. //
  300. // Return Value:
  301. //
  302. // TRUE - Application was successfully initialized.
  303. // FALSE - Application could not be initialized
  304. //
  305. // Function Calls:
  306. // Function Location
  307. //
  308. // LoadIcon Windows API
  309. // LoadCursor Windows API
  310. // GetStockObject Windows API
  311. // RegisterClass Windows API
  312. //
  313. //
  314. //********************************************************************
  315. BOOL CSimpleApp::fInitApplication(HANDLE hInstance)
  316. {
  317. // Initialize our accelerator table
  318. if ((m_hAccel = LoadAccelerators((HINSTANCE) hInstance,
  319. TEXT("SimpcntrAccel"))) == NULL)
  320. {
  321. // Load failed so abort
  322. TestDebugOut(TEXT("ERROR: Accelerator Table Load FAILED\r\n"));
  323. return FALSE;
  324. }
  325. WNDCLASS wc;
  326. // Fill in window class structure with parameters that describe the
  327. // main window.
  328. wc.style = NULL; // Class style(s).
  329. wc.lpfnWndProc = MainWndProc; // Function to retrieve messages for
  330. // windows of this class.
  331. wc.cbClsExtra = 0; // No per-class extra data.
  332. wc.cbWndExtra = 0; // No per-window extra data.
  333. wc.hInstance = (HINSTANCE) hInstance; // Application that owns the
  334. // class.
  335. wc.hIcon = LoadIcon((HINSTANCE) hInstance, TEXT("SimpCntr"));
  336. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  337. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  338. wc.lpszMenuName = TEXT("SIMPLEMENU"); // Name of menu resource in
  339. // .RC file.
  340. wc.lpszClassName = TEXT("SimpCntrAppWClass"); // Name used in
  341. // CreateWindow call
  342. if (!RegisterClass(&wc))
  343. return FALSE;
  344. wc.style = CS_DBLCLKS; // Class style(s). allow DBLCLK's
  345. wc.lpfnWndProc = DocWndProc; // Function to retrieve messages for
  346. // windows of this class.
  347. wc.cbClsExtra = 0; // No per-class extra data.
  348. wc.cbWndExtra = 0; // No per-window extra data.
  349. wc.hInstance = (HINSTANCE) hInstance; // Application that owns
  350. // the class.
  351. wc.hIcon = NULL;
  352. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  353. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  354. wc.lpszMenuName = NULL;
  355. wc.lpszClassName = TEXT("SimpCntrDocWClass"); // Name used in
  356. // CreateWindow call.
  357. // Register the window class and return success/failure code.
  358. return (RegisterClass(&wc));
  359. }
  360. //**********************************************************************
  361. //
  362. // CSimpleApp::fInitInstance
  363. //
  364. // Purpose:
  365. //
  366. // Instance initialization.
  367. //
  368. // Parameters:
  369. //
  370. // HANDLE hInstance - App. Instance Handle.
  371. //
  372. // int nCmdShow - Show parameter from WinMain
  373. //
  374. // Return Value:
  375. //
  376. // TRUE - Initialization Successful
  377. // FALSE - Initialization Failed.
  378. //
  379. //
  380. // Function Calls:
  381. // Function Location
  382. //
  383. // CreateWindow Windows API
  384. // ShowWindow Windows API
  385. // UpdateWindow Windows API
  386. // OleBuildVersion OLE API
  387. // OleInitialize OLE API
  388. //
  389. // Comments:
  390. //
  391. // Note that successful Initalization of the OLE libraries
  392. // is remembered so the UnInit is only called if needed.
  393. //
  394. //********************************************************************
  395. BOOL CSimpleApp::fInitInstance (HANDLE hInstance, int nCmdShow)
  396. {
  397. LPMALLOC lpMalloc = NULL;
  398. #ifndef WIN32
  399. /* Since OLE is part of the operating system in Win32, we don't need to
  400. * check the version number in Win32.
  401. */
  402. DWORD dwVer = OleBuildVersion();
  403. // check to see if we are compatible with this version of the libraries
  404. if (HIWORD(dwVer) != rmm || LOWORD(dwVer) < rup)
  405. {
  406. #ifdef _DEBUG
  407. TestDebugOut(TEXT("WARNING:Incompatible OLE library version\r\n"));
  408. #else
  409. return FALSE;
  410. #endif
  411. }
  412. #endif // WIN32
  413. #if defined( _DEBUG )
  414. /* OLE2NOTE: Use a special debug allocator to help track down
  415. ** memory leaks.
  416. */
  417. OleStdCreateDbAlloc(0, &lpMalloc);
  418. #endif
  419. // We try passing in our own allocator first - if that fails we
  420. // try without overriding the allocator.
  421. if (SUCCEEDED(OleInitialize(lpMalloc)) ||
  422. SUCCEEDED(OleInitialize(NULL)))
  423. {
  424. m_fInitialized = TRUE;
  425. }
  426. #if defined( _DEBUG )
  427. /* OLE2NOTE: release the special debug allocator so that only OLE is
  428. ** holding on to it. later when OleUninitialize is called, then
  429. ** the debug allocator object will be destroyed. when the debug
  430. ** allocator object is destoyed, it will report (to the Output
  431. ** Debug Terminal) whether there are any memory leaks.
  432. */
  433. if (lpMalloc) lpMalloc->Release();
  434. #endif
  435. m_hInst = (HINSTANCE) hInstance;
  436. // Create the "application" windows
  437. m_hAppWnd = CreateWindow (TEXT("SimpCntrAppWClass"),
  438. TEXT("Simple OLE 2.0 In-Place Container"),
  439. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  440. CW_USEDEFAULT,
  441. CW_USEDEFAULT,
  442. CW_USEDEFAULT,
  443. CW_USEDEFAULT,
  444. NULL,
  445. NULL,
  446. (HINSTANCE) hInstance,
  447. NULL);
  448. if (!m_hAppWnd)
  449. return FALSE;
  450. m_hStdPal = OleStdCreateStandardPalette();
  451. ShowWindow (m_hAppWnd, nCmdShow);
  452. UpdateWindow (m_hAppWnd);
  453. // if we have been launched by the test driver, tell it our window handle
  454. if( m_hDriverWnd )
  455. {
  456. PostMessage(m_hDriverWnd, WM_TESTREG, (WPARAM)m_hAppWnd, 0);
  457. }
  458. return m_fInitialized;
  459. }
  460. //**********************************************************************
  461. //
  462. // CSimpleApp::lCommandHandler
  463. //
  464. // Purpose:
  465. //
  466. // Handles the processing of WM_COMMAND.
  467. //
  468. // Parameters:
  469. //
  470. // HWND hWnd - Handle to the application Window
  471. //
  472. // UINT message - message (always WM_COMMAND)
  473. //
  474. // WPARAM wParam - Same as passed to the WndProc
  475. //
  476. // LPARAM lParam - Same as passed to the WndProc
  477. //
  478. // Return Value:
  479. //
  480. // NULL
  481. //
  482. // Function Calls:
  483. // Function Location
  484. //
  485. // IOleInPlaceActiveObject::QueryInterface Object
  486. // IOleInPlaceObject::ContextSensitiveHelp Object
  487. // IOleInPlaceObject::Release Object
  488. // IOleObject::DoVerb Object
  489. // MessageBox Windows API
  490. // DialogBox Windows API
  491. // MakeProcInstance Windows API
  492. // FreeProcInstance Windows API
  493. // SendMessage Windows API
  494. // DefWindowProc Windows API
  495. // CSimpleDoc::InsertObject DOC.CPP
  496. // CSimpleSite::GetObjRect SITE.CPP
  497. // CSimpleApp::lCreateDoc APP.CPP
  498. //
  499. //
  500. //********************************************************************
  501. long CSimpleApp::lCommandHandler (HWND hWnd, UINT message,
  502. WPARAM wParam, LPARAM lParam)
  503. {
  504. RECT rect;
  505. // Win32 uses high word to tell were command came from so we dump it.
  506. wParam = LOWORD(wParam);
  507. // context sensitive help...
  508. if (m_fMenuMode || m_fCSHMode)
  509. {
  510. if (m_fCSHMode)
  511. {
  512. // clear context sensitive help flag
  513. m_fCSHMode = FALSE;
  514. // if there is an InPlace active object, call its context
  515. // sensitive help method with the FALSE parameter to bring the
  516. // object out of the csh state. See the technotes for details.
  517. if (m_lpDoc->m_lpActiveObject)
  518. {
  519. LPOLEINPLACEOBJECT lpInPlaceObject;
  520. m_lpDoc->m_lpActiveObject->QueryInterface(
  521. IID_IOleInPlaceObject,
  522. (LPVOID FAR *)&lpInPlaceObject);
  523. lpInPlaceObject->ContextSensitiveHelp(FALSE);
  524. lpInPlaceObject->Release();
  525. }
  526. }
  527. // see the technotes for details on implementing context sensitive
  528. // help
  529. if (m_fMenuMode)
  530. {
  531. m_fMenuMode = FALSE;
  532. if (m_lpDoc->m_lpActiveObject)
  533. m_lpDoc->m_lpActiveObject->ContextSensitiveHelp(FALSE);
  534. }
  535. // if we provided help, we would do it here...
  536. MessageBox (hWnd, TEXT("Help"), TEXT("Help"), MB_OK);
  537. return NULL;
  538. }
  539. // see if the command is a verb selections
  540. if (wParam >= IDM_VERB0)
  541. {
  542. // get the rectangle of the object
  543. m_lpDoc->m_lpSite->GetObjRect(&rect);
  544. m_lpDoc->m_lpSite->m_lpOleObject->DoVerb(wParam - IDM_VERB0, NULL,
  545. &m_lpDoc->m_lpSite->m_OleClientSite,
  546. -1, m_lpDoc->m_hDocWnd, &rect);
  547. }
  548. else
  549. {
  550. switch (wParam)
  551. {
  552. // bring up the About box
  553. case IDM_ABOUT:
  554. {
  555. #ifdef WIN32
  556. DialogBox(m_hInst, // current instance
  557. TEXT("AboutBox"), // resource to use
  558. m_hAppWnd, // parent handle
  559. About); // About() instance address
  560. #else
  561. FARPROC lpProcAbout = MakeProcInstance((FARPROC)About,
  562. m_hInst);
  563. DialogBox(m_hInst, // current instance
  564. TEXT("AboutBox"), // resource to use
  565. m_hAppWnd, // parent handle
  566. lpProcAbout); // About() instance address
  567. FreeProcInstance(lpProcAbout);
  568. #endif
  569. break;
  570. }
  571. // bring up the InsertObject Dialog
  572. case IDM_INSERTOBJECT:
  573. m_lpDoc->InsertObject();
  574. break;
  575. // exit the application
  576. case IDM_EXIT:
  577. SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0L);
  578. break;
  579. case IDM_NEW:
  580. m_lpDoc->Close();
  581. m_lpDoc = NULL;
  582. lCreateDoc(hWnd, 0, 0, 0);
  583. break;
  584. case IDM_DEACTIVATE:
  585. DeactivateIfActive(hWnd);
  586. break;
  587. case IDM_UTEST:
  588. m_fGotUtestAccelerator = TRUE;
  589. break;
  590. default:
  591. return (DefWindowProc(hWnd, message, wParam, lParam));
  592. } // end of switch
  593. } // end of else
  594. return NULL;
  595. }
  596. //**********************************************************************
  597. //
  598. // CSimpleApp::lSizeHandler
  599. //
  600. // Purpose:
  601. //
  602. // Handles the WM_SIZE message
  603. //
  604. // Parameters:
  605. //
  606. // HWND hWnd - Handle to the application Window
  607. //
  608. // UINT message - message (always WM_SIZE)
  609. //
  610. // WPARAM wParam - Same as passed to the WndProc
  611. //
  612. // LPARAM lParam - Same as passed to the WndProc
  613. //
  614. // Return Value:
  615. //
  616. // LONG - returned from the "document" resizing
  617. //
  618. // Function Calls:
  619. // Function Location
  620. //
  621. // GetClientRect Windows API
  622. // CSimpleDoc::lResizeDoc DOC.CPP
  623. //
  624. //
  625. //********************************************************************
  626. long CSimpleApp::lSizeHandler (HWND hWnd, UINT message, WPARAM wParam,
  627. LPARAM lParam)
  628. {
  629. RECT rect;
  630. GetClientRect(m_hAppWnd, &rect);
  631. return m_lpDoc->lResizeDoc(&rect);
  632. }
  633. //**********************************************************************
  634. //
  635. // CSimpleApp::lCreateDoc
  636. //
  637. // Purpose:
  638. //
  639. // Handles the creation of a document.
  640. //
  641. // Parameters:
  642. //
  643. // HWND hWnd - Handle to the application Window
  644. //
  645. // UINT message - message (always WM_CREATE)
  646. //
  647. // WPARAM wParam - Same as passed to the WndProc
  648. //
  649. // LPARAM lParam - Same as passed to the WndProc
  650. //
  651. // Return Value:
  652. //
  653. // NULL
  654. //
  655. // Function Calls:
  656. // Function Location
  657. //
  658. // GetClientRect Windows API
  659. // CSimpleDoc::CSimpleDoc DOC.CPP
  660. //
  661. //
  662. //********************************************************************
  663. long CSimpleApp::lCreateDoc (HWND hWnd, UINT message, WPARAM wParam,
  664. LPARAM lParam)
  665. {
  666. RECT rect;
  667. GetClientRect(hWnd, &rect);
  668. m_lpDoc = CSimpleDoc::Create(this, &rect, hWnd);
  669. return NULL;
  670. }
  671. //**********************************************************************
  672. //
  673. // CSimpleApp::AddFrameLevelUI
  674. //
  675. // Purpose:
  676. //
  677. // Used during InPlace negotiation.
  678. //
  679. // Parameters:
  680. //
  681. // None
  682. //
  683. // Return Value:
  684. //
  685. // None
  686. //
  687. // Function Calls:
  688. // Function Location
  689. //
  690. // COleInPlaceFrame::SetMenu IOIPF.CPP
  691. // CSimpleApp::AddFrameLevelTools APP.CPP
  692. //
  693. // Comments:
  694. //
  695. // Be sure to read the Technotes included in the OLE 2.0 toolkit
  696. //
  697. //********************************************************************
  698. void CSimpleApp::AddFrameLevelUI()
  699. {
  700. m_OleInPlaceFrame.SetMenu(NULL, NULL, NULL);
  701. AddFrameLevelTools();
  702. }
  703. //**********************************************************************
  704. //
  705. // CSimpleApp::AddFrameLevelTools
  706. //
  707. // Purpose:
  708. //
  709. // Used during InPlace negotiation.
  710. //
  711. // Parameters:
  712. //
  713. // None
  714. //
  715. // Return Value:
  716. //
  717. // None
  718. //
  719. // Function Calls:
  720. // Function Location
  721. //
  722. // COleInPlaceFrame::SetBorderSpace IOIPF.CPP
  723. // InvalidateRect Windows API
  724. //
  725. // Comments:
  726. //
  727. // Be sure to read the Technotes included in the OLE 2.0 toolkit
  728. //
  729. //********************************************************************
  730. void CSimpleApp::AddFrameLevelTools()
  731. {
  732. m_OleInPlaceFrame.SetBorderSpace(&nullRect);
  733. InvalidateRect(m_hAppWnd, NULL, TRUE);
  734. }
  735. //**********************************************************************
  736. //
  737. // CSimpleApp::HandleAccelerators
  738. //
  739. // Purpose:
  740. //
  741. // To properly handle accelerators in the Message Loop
  742. //
  743. // Parameters:
  744. //
  745. // LPMSG lpMsg - A pointer to the message structure.
  746. //
  747. // Return Value:
  748. //
  749. // TRUE - The accelerator was handled
  750. // FALSE - The accelerator was not handled
  751. //
  752. // Function Calls:
  753. // Function Location
  754. //
  755. // IOleInPlaceActiveObject::TranslateAccelerator Object
  756. //
  757. // Comments:
  758. //
  759. // If an object is InPlace active, it gets the first shot at
  760. // handling the accelerators.
  761. //
  762. //********************************************************************
  763. BOOL CSimpleApp::HandleAccelerators(LPMSG lpMsg)
  764. {
  765. HRESULT hResult;
  766. BOOL retval = FALSE;
  767. // The following is what you would do if this were an inproc DLL.
  768. // A local server will be passing us commands to process
  769. #if 0
  770. // if we have an InPlace Active Object
  771. if (m_lpDoc->m_lpActiveObject)
  772. {
  773. // Pass the accelerator on...
  774. hResult = m_lpDoc->m_lpActiveObject->TranslateAccelerator(lpMsg);
  775. if (hResult == NOERROR)
  776. retval = TRUE;
  777. }
  778. #endif
  779. // We process our accelerators
  780. return TranslateAccelerator(m_hAppWnd, m_hAccel, lpMsg);
  781. }
  782. //**********************************************************************
  783. //
  784. // CSimpleApp::PaintApp
  785. //
  786. // Purpose:
  787. //
  788. // Handles the painting of the doc window.
  789. //
  790. //
  791. // Parameters:
  792. //
  793. // HDC hDC - hDC to the Doc Window.
  794. //
  795. // Return Value:
  796. //
  797. // None
  798. //
  799. // Function Calls:
  800. // Function Location
  801. //
  802. // CSimpleDoc::PaintDoc DOC.CPP
  803. //
  804. // Comments:
  805. //
  806. // This is an app level function in case we want to do palette
  807. // management.
  808. //
  809. //********************************************************************
  810. void CSimpleApp::PaintApp (HDC hDC)
  811. {
  812. // at this level, we could enumerate through all of the
  813. // visible objects in the application, so that a palette
  814. // that best fits all of the objects can be built.
  815. // This app is designed to take on the same palette
  816. // functionality that was provided in OLE 1.0, the palette
  817. // of the last object drawn is realized. Since we only
  818. // support one object at a time, it shouldn't be a big
  819. // deal.
  820. // if we supported multiple documents, we would enumerate
  821. // through each of the open documents and call paint.
  822. if (m_lpDoc)
  823. m_lpDoc->PaintDoc(hDC);
  824. }
  825. //**********************************************************************
  826. //
  827. // CSimpleApp::ContextSensitiveHelp
  828. //
  829. // Purpose:
  830. // Used in supporting context sensitive help at the app level.
  831. //
  832. //
  833. // Parameters:
  834. //
  835. // BOOL fEnterMode - Entering/Exiting Context Sensitive
  836. // help mode.
  837. //
  838. // Return Value:
  839. //
  840. // None
  841. //
  842. // Function Calls:
  843. // Function Location
  844. //
  845. // IOleInPlaceActiveObject::QueryInterface Object
  846. // IOleInPlaceObject::ContextSensitiveHelp Object
  847. // IOleInPlaceObject::Release Object
  848. //
  849. // Comments:
  850. //
  851. // This function isn't used because we don't support Shift+F1
  852. // context sensitive help. Be sure to look at the technotes
  853. // in the OLE 2.0 toolkit.
  854. //
  855. //********************************************************************
  856. void CSimpleApp::ContextSensitiveHelp (BOOL fEnterMode)
  857. {
  858. if (m_fCSHMode != fEnterMode)
  859. {
  860. m_fCSHMode = fEnterMode;
  861. // this code "trickles" the context sensitive help via shift+f1
  862. // to the inplace active object. See the technotes for implementation
  863. // details.
  864. if (m_lpDoc->m_lpActiveObject)
  865. {
  866. LPOLEINPLACEOBJECT lpInPlaceObject;
  867. m_lpDoc->m_lpActiveObject->QueryInterface(IID_IOleInPlaceObject,
  868. (LPVOID FAR *)&lpInPlaceObject);
  869. lpInPlaceObject->ContextSensitiveHelp(fEnterMode);
  870. lpInPlaceObject->Release();
  871. }
  872. }
  873. }
  874. /* OLE2NOTE: forward the WM_QUERYNEWPALETTE message (via
  875. ** SendMessage) to UIActive in-place object if there is one.
  876. ** this gives the UIActive object the opportunity to select
  877. ** and realize its color palette as the FOREGROUND palette.
  878. ** this is optional for in-place containers. if a container
  879. ** prefers to force its color palette as the foreground
  880. ** palette then it should NOT forward the this message. or
  881. ** the container can give the UIActive object priority; if
  882. ** the UIActive object returns 0 from the WM_QUERYNEWPALETTE
  883. ** message (ie. it did not realize its own palette), then
  884. ** the container can realize its palette.
  885. ** (see ContainerDoc_ForwardPaletteChangedMsg for more info)
  886. **
  887. ** (It is a good idea for containers to use the standard
  888. ** palette even if they do not use colors themselves. this
  889. ** will allow embedded object to get a good distribution of
  890. ** colors when they are being drawn by the container)
  891. **
  892. */
  893. //**********************************************************************
  894. //
  895. // CSimpleApp::QueryNewPalette
  896. //
  897. // Purpose:
  898. // See above
  899. //
  900. //
  901. // Parameters:
  902. //
  903. // None
  904. //
  905. // Return Value:
  906. //
  907. // 0 if the handle to palette (m_hStdPal) is NULL,
  908. // 1 otherwise
  909. //
  910. // Function Calls:
  911. // Function Location
  912. //
  913. // SendMessage Windows API
  914. //
  915. //
  916. //********************************************************************
  917. LRESULT CSimpleApp::QueryNewPalette(void)
  918. {
  919. if (m_hwndUIActiveObj)
  920. {
  921. if (SendMessage(m_hwndUIActiveObj, WM_QUERYNEWPALETTE,
  922. (WPARAM)0, (LPARAM)0))
  923. {
  924. /* Object selected its palette as foreground palette */
  925. return (LRESULT)1;
  926. }
  927. }
  928. return wSelectPalette(m_hAppWnd, m_hStdPal, FALSE/*fBackground*/);
  929. }
  930. /* This is just a helper routine */
  931. LRESULT wSelectPalette(HWND hWnd, HPALETTE hPal, BOOL fBackground)
  932. {
  933. HDC hdc;
  934. HPALETTE hOldPal;
  935. UINT iPalChg = 0;
  936. if (hPal == 0)
  937. return (LRESULT)0;
  938. hdc = GetDC(hWnd);
  939. hOldPal = SelectPalette(hdc, hPal, fBackground);
  940. iPalChg = RealizePalette(hdc);
  941. SelectPalette(hdc, hOldPal, TRUE /*fBackground*/);
  942. ReleaseDC(hWnd, hdc);
  943. if (iPalChg > 0)
  944. InvalidateRect(hWnd, NULL, TRUE);
  945. return (LRESULT)1;
  946. }