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.

963 lines
25 KiB

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