OBJ.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:31k
源码类别:

Windows编程

开发平台:

Visual C++

  1. //**********************************************************************
  2. // File name: obj.cpp
  3. //
  4. //    Implementation file for the CSimpSvrApp Class
  5. //
  6. // Functions:
  7. //
  8. //    See obj.h for a list of member functions.
  9. //
  10. // Copyright (c) 1993-1997 Microsoft Corporation. All rights reserved.
  11. //**********************************************************************
  12. #include "pre.h"
  13. #include "obj.h"
  14. #include "ioo.h"
  15. #include "ido.h"
  16. #include "ips.h"
  17. #include "icf.h"
  18. #include "ioipao.h"
  19. #include "ioipo.h"
  20. #include "app.h"
  21. #include "doc.h"
  22. //**********************************************************************
  23. //
  24. // CSimpSvrObj::QueryInterface
  25. //
  26. // Purpose:
  27. //
  28. //      Used for interface negotiation at the "Object" level.
  29. //
  30. // Parameters:
  31. //
  32. //      REFIID riid         -   A reference to the interface that is
  33. //                              being queried.
  34. //
  35. //      LPVOID FAR* ppvObj  -   An out parameter to return a pointer to
  36. //                              the interface.
  37. //
  38. // Return Value:
  39. //
  40. //      S_OK          -   The interface is supported.
  41. //      E_NOINTERFACE -   The interface is not supported
  42. //
  43. // Function Calls:
  44. //      Function                    Location
  45. //
  46. //      OutputDebugString           Windows API
  47. //                   OLE API
  48. //      IUnknown::AddRef            OBJ.CPP, IOO.CPP, IDO.CPP, IPS.CPP
  49. //                                  IOIPO.CPP, IOIPAO.CPP
  50. //
  51. // Comments:
  52. //
  53. //
  54. //********************************************************************
  55. STDMETHODIMP CSimpSvrObj::QueryInterface ( REFIID riid, LPVOID FAR* ppvObj)
  56. {
  57.         OutputDebugString("In CSimpSvrObj::QueryInterfacern");
  58.         SCODE sc = S_OK;
  59.         if (riid == IID_IUnknown)
  60.                 *ppvObj = this;
  61.         else if (riid == IID_IOleObject)
  62.                 *ppvObj = &m_OleObject;
  63.         else if (riid == IID_IDataObject)
  64.                 *ppvObj = &m_DataObject;
  65.         else if ( (riid == IID_IPersistStorage) || (riid == IID_IPersist) )
  66.                 *ppvObj = &m_PersistStorage;
  67.         else if (riid == IID_IOleInPlaceObject)
  68.                 *ppvObj = &m_OleInPlaceObject;
  69.         else if (riid == IID_IOleInPlaceActiveObject)
  70.                 *ppvObj = &m_OleInPlaceActiveObject;
  71.         else if (riid == IID_IExternalConnection)
  72.                  *ppvObj = &m_ExternalConnection;
  73.         else
  74.                 {
  75.                 *ppvObj = NULL;
  76.                 sc = E_NOINTERFACE;
  77.                 }
  78.         if (*ppvObj)
  79.                 ((LPUNKNOWN)*ppvObj)->AddRef();
  80.         return  sc ;
  81. };
  82. //**********************************************************************
  83. //
  84. // CSimpSvrObj::AddRef
  85. //
  86. // Purpose:
  87. //
  88. //      Adds to the reference count at the Object level.
  89. //
  90. // Parameters:
  91. //
  92. //      None
  93. //
  94. // Return Value:
  95. //
  96. //      ULONG   -   The new reference count of the Object.
  97. //
  98. // Function Calls:
  99. //      Function                    Location
  100. //
  101. //      OutputDebugString           Windows API
  102. //
  103. // Comments:
  104. //
  105. //      Due to the reference counting model that is used in this
  106. //      implementation, this reference count is the sum of the
  107. //      reference counts on all interfaces
  108. //
  109. //********************************************************************
  110. STDMETHODIMP_(ULONG) CSimpSvrObj::AddRef ()
  111. {
  112.         OutputDebugString("In CSimpSvrObj::AddRefrn");
  113.         m_lpDoc->AddRef();
  114.         return ++m_nCount;
  115. };
  116. //**********************************************************************
  117. //
  118. // CSimpSvrObj::Release
  119. //
  120. // Purpose:
  121. //
  122. //      Decrements the reference count at this level
  123. //
  124. // Parameters:
  125. //
  126. //      None
  127. //
  128. // Return Value:
  129. //
  130. //      ULONG   -   The new reference count of the object.
  131. //
  132. // Function Calls:
  133. //      Function                    Location
  134. //
  135. //      OutputDebugString           Windows API
  136. //
  137. // Comments:
  138. //
  139. //      Due to the reference counting model that is used in this
  140. //      implementation, this reference count is the sum of the
  141. //      reference counts on all interfaces
  142. //
  143. //********************************************************************
  144. STDMETHODIMP_(ULONG) CSimpSvrObj::Release ()
  145. {
  146.         OutputDebugString("In CSimpSvrObj::Releasern");
  147.         m_lpDoc->Release();
  148.         if (--m_nCount == 0) {
  149.                 delete this;
  150.         return 0;
  151.     }
  152.         return m_nCount;
  153. };
  154. //**********************************************************************
  155. //
  156. // CSimpSvrObj::CSimpSvrObj
  157. //
  158. // Purpose:
  159. //
  160. //      Constructor for CSimpSvrObj
  161. //
  162. // Parameters:
  163. //
  164. //      CSimpSvrDoc FAR * lpSimpSvrDoc - ptr to the doc object
  165. //
  166. // Return Value:
  167. //
  168. //      None
  169. //
  170. // Function Calls:
  171. //      Function                    Location
  172. //
  173. //
  174. // Comments:
  175. //
  176. //
  177. //********************************************************************
  178. #pragma warning (disable : 4355) // "this" used in base initializer list warning.  This
  179.                                                                  // can be disabled because we are not using "this" in
  180.                                                                  // the constructor for these objects, rather we are
  181.                                                                  // just storing it for future use...
  182. CSimpSvrObj::CSimpSvrObj(CSimpSvrDoc FAR * lpSimpSvrDoc) : m_OleObject(this),
  183.                                                                                                                    m_DataObject(this),
  184.                                                                                                                    m_PersistStorage(this),
  185.                                                                                                                    m_OleInPlaceActiveObject(this),
  186.                                                                                                                    m_OleInPlaceObject(this),
  187.                                                                                                                    m_ExternalConnection(this)
  188. #pragma warning (default : 4355) // Turn the warning back on
  189. {
  190.         m_lpDoc = lpSimpSvrDoc;
  191.         m_nCount = 0;
  192.         m_fInPlaceActive = FALSE;
  193.         m_fInPlaceVisible = FALSE;
  194.         m_fUIActive = FALSE;
  195.         m_hmenuShared = NULL;
  196.         m_hOleMenu = NULL;
  197.         m_dwRegister = 0;
  198.         m_lpFrame = NULL;
  199.         m_lpCntrDoc = NULL;
  200.         m_lpStorage = NULL;
  201.         m_lpColorStm = NULL;
  202.         m_lpSizeStm = NULL;
  203.         m_lpOleClientSite = NULL;
  204.         m_lpOleAdviseHolder = NULL;
  205.         m_lpDataAdviseHolder = NULL;
  206.         m_lpIPSite = NULL;
  207.         m_red = 128;
  208.         m_green = 0;
  209.         m_blue = 0;
  210.         m_size.x = 100;
  211.         m_size.y = 100;
  212.         m_xOffset = 0;
  213.         m_yOffset = 0;
  214.         m_scale = (float) 1.0;
  215.         m_fSaveWithSameAsLoad = FALSE;
  216.         m_fNoScribbleMode = FALSE;
  217. }
  218. //**********************************************************************
  219. //
  220. // CSimpSvrObj::~CSimpSvrObj
  221. //
  222. // Purpose:
  223. //
  224. //      Destructor for CSimpSvrObj
  225. //
  226. // Parameters:
  227. //
  228. //      None
  229. //
  230. // Return Value:
  231. //
  232. //
  233. //
  234. // Function Calls:
  235. //      Function                    Location
  236. //
  237. //      OutputDebugString           Windows API
  238. //      PostMessage                 Windows API
  239. //      CSimpSvrDoc::GetApp         DOC.H
  240. //      CSimpSvrDoc::GethAppWnd     DOC.H
  241. //      CSimpSvrDoc::ClearObj       DOC.H
  242. //      CSimpSvrApp::IsStartedByOle APP.CPP
  243. //
  244. // Comments:
  245. //
  246. //
  247. //********************************************************************
  248. CSimpSvrObj::~CSimpSvrObj()
  249. {
  250.         OutputDebugString("In CSimpSvrObj's Destructor rn");
  251.         // if we were started by ole, post ourselves a close message
  252.         if (m_lpDoc->GetApp()->IsStartedByOle())
  253.                 PostMessage(m_lpDoc->GethAppWnd(), WM_SYSCOMMAND, SC_CLOSE, 0L);
  254.         // clear the OBJ ptr in the doc class
  255.         m_lpDoc->ClearObj();
  256. }
  257. //**********************************************************************
  258. //
  259. // CSimpSvrObj::Draw
  260. //
  261. // Purpose:
  262. //
  263. //      Draws the object into an arbitrary DC
  264. //
  265. // Parameters:
  266. //
  267. //      HDC hDC - DC to draw into
  268. //
  269. // Return Value:
  270. //
  271. //      NONE
  272. //
  273. // Function Calls:
  274. //      Function                    Location
  275. //
  276. //      OutputDebugString           Windows API
  277. //      CreateBrushIndirect         Windows API
  278. //      SelectObject                Windows API
  279. //      Rectangle                   Windows API
  280. //      DeleteObject                Windows API
  281. //
  282. // Comments:
  283. //
  284. //
  285. //********************************************************************
  286. void CSimpSvrObj::Draw (HDC hDC, BOOL m_fMeta)
  287. {
  288.         LOGBRUSH lb;
  289.         OutputDebugString("In CSimpSvrObj::Drawrn");
  290.         char szBuffer[255];
  291.         wsprintf(szBuffer,"Drawing Scale %3drn",m_scale);
  292.         OutputDebugString(szBuffer);
  293.         if (!m_fMeta)
  294.                 {
  295.                 SetMapMode(hDC, MM_ANISOTROPIC);
  296.                 //@@WTK WIN32, UNICODE
  297.                 //SetWindowOrg(hDC, (int)(m_xOffset/m_scale), (int)(m_yOffset/m_scale));
  298.                 SetWindowOrgEx(hDC, (int)(m_xOffset/m_scale),
  299.                         (int)(m_yOffset/m_scale), NULL);
  300.                 //@@WTK WIN32, UNICODE
  301.                 //SetWindowExt(hDC, m_size.x, m_size.y);
  302.                 SetWindowExtEx(hDC, m_size.x, m_size.y, NULL);
  303.                 //@@WTK WIN32, UNICODE
  304.                 //SetViewportExt(hDC, (int)(m_size.x*m_scale), (int)(m_size.y*m_scale));
  305.                 SetViewportExtEx(hDC, (int)(m_size.x*m_scale),
  306.                         (int)(m_size.y*m_scale), NULL);
  307.                 }
  308.         // fill out a LOGBRUSH
  309.         lb.lbStyle = BS_SOLID;
  310.         lb.lbColor = RGB(m_red, m_green, m_blue);
  311.         lb.lbHatch = 0;
  312.         // create the brush
  313.         HBRUSH hBrush = CreateBrushIndirect(&lb);
  314.         // select the brush
  315.         HBRUSH hOldBrush = (HBRUSH) SelectObject(hDC, hBrush);
  316.         HPEN hPen = CreatePen(PS_INSIDEFRAME, 6, RGB(0, 0, 0));
  317.         HPEN hOldPen = (HPEN) SelectObject(hDC, hPen);
  318.         // draw the rectangle
  319.         Rectangle (hDC, 0, 0, m_size.x, m_size.y);
  320.         // restore the pen
  321.         hPen = (HPEN) SelectObject(hDC, hOldPen);
  322.         // free the pen
  323.         DeleteObject(hPen);
  324.         // restore the old brush
  325.         hBrush = (HBRUSH) SelectObject(hDC, hOldBrush);
  326.         // free the brush
  327.         DeleteObject(hBrush);
  328. }
  329. //**********************************************************************
  330. //
  331. // CSimpSvrObj::GetMetaFilePict
  332. //
  333. // Purpose:
  334. //
  335. //      Returns a handle to a metafile representation of the object.
  336. //
  337. // Parameters:
  338. //
  339. //      None
  340. //
  341. // Return Value:
  342. //
  343. //      Handle to the metafile.
  344. //
  345. // Function Calls:
  346. //      Function                        Location
  347. //
  348. //      OutputDebugString               Windows API
  349. //      GlobalAlloc                     Windows API
  350. //      GlobalLock                      Windows API
  351. //      SetWindowOrg                    Windows API
  352. //      SetWindowExt                    Windows API
  353. //      CreateMetaFile                  Windows API
  354. //      CloseMetaFile                   Windows API
  355. //      GlobalUnlock                    Windows API
  356. //      XformWidthInPixelsToHimetric    OLESTD
  357. //      XformHeightInPixelsToHimetric   OLESTD
  358. //      CSimpSvrObj::Draw               OBJ.CPP
  359. //
  360. // Comments:
  361. //
  362. //
  363. //********************************************************************
  364. HANDLE CSimpSvrObj::GetMetaFilePict()
  365. {
  366.         HANDLE hMFP;
  367.         METAFILEPICT FAR * lpMFP;
  368.         POINT pt;
  369.         OutputDebugString("In CSimpSvrObj::GetMetaFilePictrn");
  370.         // allocate the memory for the METAFILEPICT structure
  371.         hMFP = GlobalAlloc (GMEM_SHARE | GHND, sizeof (METAFILEPICT) );
  372.         lpMFP = (METAFILEPICT FAR*) GlobalLock(hMFP);
  373.         // get the size of the object in HIMETRIC
  374.         pt.x = XformWidthInPixelsToHimetric(NULL, m_size.x);
  375.         pt.y = XformHeightInPixelsToHimetric(NULL, m_size.y);
  376.         // fill out the METAFILEPICT structure
  377.         lpMFP->mm = MM_ANISOTROPIC;
  378.         lpMFP->xExt = pt.x;
  379.         lpMFP->yExt = pt.y;
  380.         // Create the metafile
  381.         HDC hDC = CreateMetaFile(NULL);
  382.         //@@WTK WIN32, UNICODE
  383.         //SetWindowOrg (hDC, 0, 0);
  384.         SetWindowOrgEx (hDC, 0, 0, NULL);
  385.         //@@WTK WIN32, UNICODE
  386.         //SetWindowExt (hDC, m_size.x,
  387.         SetWindowExtEx (hDC, m_size.x,
  388.                                            m_size.y, NULL);
  389.         Draw(hDC);
  390.         lpMFP->hMF = CloseMetaFile(hDC);
  391.         // unlock the metafilepict
  392.         GlobalUnlock(hMFP);
  393.         return hMFP;
  394. }
  395. //**********************************************************************
  396. //
  397. // CSimpSvrObj::SaveToStorage
  398. //
  399. // Purpose:
  400. //
  401. //      Saves the object to the passed storage
  402. //
  403. // Parameters:
  404. //
  405. //      LPSTORAGE lpStg - Storage in which to save the object
  406. //
  407. // Return Value:
  408. //
  409. //      None
  410. //
  411. // Function Calls:
  412. //      Function                    Location
  413. //
  414. //      OutputDebugString           Windows API
  415. //      IStorage::CreateStream      OLE
  416. //      IStream::Write              OLE
  417. //      IStream::Release            OLE
  418. //
  419. // Comments:
  420. //
  421. //      A real app will want to do better error checking / returning
  422. //
  423. //********************************************************************
  424. void CSimpSvrObj::SaveToStorage (LPSTORAGE lpStg, BOOL fSameAsLoad)
  425. {
  426.         OutputDebugString("In CSimpSvrObj::SaveToStoragern");
  427.         LPSTREAM lpTempColor, lpTempSize;
  428.         if (!fSameAsLoad)
  429.                 m_PersistStorage.CreateStreams( lpStg, &lpTempColor, &lpTempSize);
  430.         else
  431.                 {
  432.                 lpTempColor = m_lpColorStm;
  433.                 lpTempColor->AddRef();
  434.                 lpTempSize = m_lpSizeStm;
  435.                 lpTempSize->AddRef();
  436.                 }
  437.         ULARGE_INTEGER uli;
  438.         uli.LowPart = 0;
  439.         uli.HighPart = 0;
  440.         lpTempColor->SetSize(uli);
  441.         lpTempSize->SetSize(uli);
  442.         LARGE_INTEGER li;
  443.         li.LowPart = 0;
  444.         li.HighPart = 0;
  445.         lpTempColor->Seek(li, STREAM_SEEK_SET, NULL);
  446.         lpTempSize->Seek(li, STREAM_SEEK_SET, NULL);
  447.         // write the colors to the stream
  448.         lpTempColor->Write(&m_red, sizeof(m_red), NULL);
  449.         lpTempColor->Write(&m_green, sizeof(m_green), NULL);
  450.         lpTempColor->Write(&m_blue, sizeof(m_blue), NULL);
  451.         // write the size to the stream
  452.         lpTempSize->Write(&m_size, sizeof(m_size), NULL);
  453.         lpTempColor->Release();
  454.         lpTempSize->Release();
  455. }
  456. //**********************************************************************
  457. //
  458. // CSimpSvrObj::LoadFromStorage
  459. //
  460. // Purpose:
  461. //
  462. //      Loads the object from the passed storage
  463. //
  464. // Parameters:
  465. //
  466. //      LPSTORAGE lpStg     - Storage in which to load the object from
  467. //
  468. // Return Value:
  469. //
  470. //      None.
  471. //
  472. // Function Calls:
  473. //      Function                    Location
  474. //
  475. //      OutputDebugString           Windows API
  476. //      IStorage::OpenStream        OLE
  477. //      IStream::Read               OLE
  478. //      IStream::Release            OLE
  479. //
  480. // Comments:
  481. //
  482. //
  483. //********************************************************************
  484. void CSimpSvrObj::LoadFromStorage ()
  485. {
  486.         OutputDebugString("In CSimpSvrObj::LoadFromStoragern");
  487.         // Read the colors
  488.         m_lpColorStm->Read(&m_red, sizeof(m_red), NULL);
  489.         m_lpColorStm->Read(&m_green, sizeof(m_green), NULL);
  490.         m_lpColorStm->Read(&m_blue, sizeof(m_blue), NULL);
  491.         // read the size
  492.         m_lpSizeStm->Read(&m_size, sizeof(m_size), NULL);
  493. }
  494. //**********************************************************************
  495. //
  496. // CSimpSvrObj::DoInPlaceActivate
  497. //
  498. // Purpose:
  499. //
  500. //      Does the inplace activation for the object
  501. //
  502. // Parameters:
  503. //
  504. //      LONG lVerb  - Verb that caused this function to be called
  505. //
  506. // Return Value:
  507. //
  508. //      TRUE/FALSE depending on success or failure.
  509. //
  510. // Function Calls:
  511. //      Function                                Location
  512. //
  513. //      IOleClientSite::QueryInterface          Container
  514. //      IOleClientSite::ShowObject              Container
  515. //      IOleInPlaceSite::CanInPlaceActivate     Container
  516. //      IOleInPlaceSite::Release                Container
  517. //      IOleInPlaceSite::OnInPlaceActivate      Container
  518. //      IOleInPlaceSite::GetWindow              Container
  519. //      IOleInPlaceSite::GetWindowContext       Container
  520. //      IOleInPlaceSite::OnUIActivate           Container
  521. //      IOleInPlaceSite::Release                Container
  522. //      IOleInPlaceFrame::SetActiveObject       Container
  523. //      IOleInPlaceUIWindow::SetActiveObject    Container
  524. //      OutputDebugString                       Windows API
  525. //      ShowWindow                              Windows API
  526. //      SetParent                               Windows API
  527. //      IntersectRect                           Windows API
  528. //      OffsetRect                              Windows API
  529. //      MoveWindow                              Windows API
  530. //      CopyRect                                Windows API
  531. //      SetFocus                                Windows API
  532. //      SetHatchWindowSize                      OLE2UI
  533. //      CSimpSvrObj::AssembleMenus              OBJ.CPP
  534. //      CSimpSvrObj::AddFrameLevelUI            OBJ.CPP
  535. //
  536. //
  537. // Comments:
  538. //
  539. //      Be sure to read TECHNOTES.WRI included with the OLE SDK
  540. //      for details on implementing inplace activation.
  541. //
  542. //********************************************************************
  543. BOOL CSimpSvrObj::DoInPlaceActivate (LONG lVerb)
  544. {
  545.         BOOL retval = FALSE;
  546.         RECT posRect, clipRect;
  547.         OutputDebugString("In CSimpSvrObj::DoInPlaceActivatern");
  548.         // if not currently in place active
  549.         if (!m_fInPlaceActive)
  550.                 {
  551.                 // get the inplace site
  552.                 if (m_lpOleClientSite->QueryInterface(IID_IOleInPlaceSite,
  553.                                                                                           (LPVOID FAR *)&m_lpIPSite) != NOERROR)
  554.                         goto error;
  555.                 // if the inplace site could not be obtained, or refuses to inplace
  556.                 // activate then goto error.
  557.                 if (m_lpIPSite == NULL || m_lpIPSite->CanInPlaceActivate() != NOERROR)
  558.                         {
  559.                         if (m_lpIPSite)
  560.                                 m_lpIPSite->Release();
  561.                         m_lpIPSite == NULL;
  562.                         goto error;
  563.                         }
  564.                 // tell the site that we are activating.
  565.                 m_lpIPSite->OnInPlaceActivate();
  566.                 m_fInPlaceActive = TRUE;
  567.                 }
  568.         // if not currently inplace visibl
  569.         if (!m_fInPlaceVisible)
  570.                 {
  571.                 m_fInPlaceVisible = TRUE;
  572.                 // get the window handle of the site
  573.                 m_lpIPSite->GetWindow(&m_hWndParent);
  574.                 // get window context from the container
  575.                 m_lpIPSite->GetWindowContext ( &m_lpFrame,
  576.                                                                          &m_lpCntrDoc,
  577.                                                                          &posRect,
  578.                                                                          &clipRect,
  579.                                                                          &m_FrameInfo);
  580.                 // show the hatch window
  581.                 m_lpDoc->ShowHatchWnd();
  582.                 // Set the parenting
  583.                 SetParent (m_lpDoc->GethHatchWnd(), m_hWndParent);
  584.                 SetParent (m_lpDoc->GethDocWnd(), m_lpDoc->GethHatchWnd());
  585.                 // tell the client site to show the object
  586.                 m_lpOleClientSite->ShowObject();
  587.                 RECT resRect;
  588.                 // figure out the "real" size of the object
  589.                 IntersectRect(&resRect, &posRect, &clipRect);
  590.                 CopyRect(&m_posRect, &posRect);
  591.                 POINT pt;
  592.                 // adjust our hatch window size
  593.                 SetHatchWindowSize ( m_lpDoc->GethHatchWnd(),
  594.                                                          &resRect,
  595.                                                          &posRect,
  596.                                                          &pt);
  597.                 // calculate the actual object rect inside the hatchwnd.
  598.                 OffsetRect (&resRect, pt.x, pt.y);
  599.                 // move the object window
  600.                 MoveWindow(m_lpDoc->GethDocWnd(),
  601.                                    resRect.left,
  602.                                    resRect.top,
  603.                                    resRect.right - resRect.left,
  604.                                    resRect.bottom - resRect.top,
  605.                                    FALSE);
  606.                 // create the combined window
  607.                 AssembleMenus();
  608.                 }
  609.         // if not UIActive
  610.         if (!m_fUIActive)
  611.                 {
  612.                 m_fUIActive = TRUE;
  613.                 // tell the inplace site that we are activating
  614.                 m_lpIPSite->OnUIActivate();
  615.                 // set the focus to our object window
  616.                 SetFocus(m_lpDoc->GethDocWnd());
  617.                 // set the active object on the frame
  618.                 //@@WTK WIN32, UNICODE
  619.                 //m_lpFrame->SetActiveObject(&m_OleInPlaceActiveObject, "Simple OLE 2.0 Server");
  620.                 m_lpFrame->SetActiveObject(&m_OleInPlaceActiveObject, OLESTR("Simple OLE 2.0 Server"));
  621.                 // set the active object on the Doc, if available.
  622.                 if (m_lpCntrDoc)
  623.                         //@@WTK WIN32, UNICODE
  624.                         //m_lpCntrDoc->SetActiveObject(&m_OleInPlaceActiveObject, "Simple OLE 2.0 Server");
  625.                         m_lpCntrDoc->SetActiveObject(&m_OleInPlaceActiveObject, OLESTR("Simple OLE 2.0 Server"));
  626.                 // add the frame level UI.
  627.                 AddFrameLevelUI();
  628.                 }
  629.         retval = TRUE;
  630. error:
  631.         return retval;
  632. }
  633. //**********************************************************************
  634. //
  635. // CSimpSvrObj::AssembleMenus
  636. //
  637. // Purpose:
  638. //
  639. //      Creates the combined menus used during inplace activation.
  640. //
  641. // Parameters:
  642. //
  643. //      None
  644. //
  645. // Return Value:
  646. //
  647. //      None
  648. //
  649. // Function Calls:
  650. //      Function                        Location
  651. //
  652. //      OutputDebugString               Windows API
  653. //      CreateMenu                      Windows API
  654. //      IOleInPlaceFrame::InsertMenus   Container
  655. //      InsertMenu                      Windows API
  656. //      DestroyMenu                     Windows API
  657. //      OleCreateMenuDescriptor         OLE API
  658. //
  659. // Comments:
  660. //
  661. //
  662. //********************************************************************
  663. void CSimpSvrObj::AssembleMenus()
  664. {
  665.         OutputDebugString("In CSimpSvrObj::AssembleMenusrn");
  666.         OLEMENUGROUPWIDTHS menugroupwidths;
  667.         m_hmenuShared = NULL;
  668.         //  Create the menu resource
  669.         m_hmenuShared = CreateMenu();
  670.         // have the contaner insert its menus
  671.         if (m_lpFrame->InsertMenus (m_hmenuShared, &menugroupwidths) == NOERROR)
  672.                 {
  673.                 int nFirstGroup = (int) menugroupwidths.width[0];
  674.                 // insert the server menus
  675.                 //@@WTK WIN32, UNICODE
  676.                 //InsertMenu( m_hmenuShared, nFirstGroup, MF_BYPOSITION | MF_POPUP, m_lpDoc->GetApp()->GetColorMenu(), "&Color");
  677.                 InsertMenu( m_hmenuShared, nFirstGroup, MF_BYPOSITION | MF_POPUP,
  678.                         (UINT)m_lpDoc->GetApp()->GetColorMenu(), "&Color");
  679.                 menugroupwidths.width[1] = 1;
  680.                 menugroupwidths.width[3] = 0;
  681.                 menugroupwidths.width[5] = 0;
  682.                 }
  683.         else
  684.                 {
  685.                 // Destroy the menu resource
  686.                 DestroyMenu(m_hmenuShared);
  687.                 m_hmenuShared = NULL;
  688.                 }
  689.         // tell OLE to create the menu descriptor
  690.         m_hOleMenu = OleCreateMenuDescriptor(m_hmenuShared, &menugroupwidths);
  691. }
  692. //**********************************************************************
  693. //
  694. // CSimpSvrObj::AddFrameLevelUI
  695. //
  696. // Purpose:
  697. //
  698. //      Adds the Frame level user interface
  699. //
  700. // Parameters:
  701. //
  702. //      None
  703. //
  704. // Return Value:
  705. //
  706. //      None
  707. //
  708. // Function Calls:
  709. //      Function                    Location
  710. //
  711. //      OutputDebugString                   Windows API
  712. //      IOleInPlaceFrame::SetMenu           Container
  713. //      IOleInPlaceFrame::SetBorderSpace    Container
  714. //      IOleInPlaceUIWindow::SetBorderSpace Container
  715. //      CSimpSvrDoc::GethDocWnd             DOC.H
  716. //
  717. // Comments:
  718. //
  719. //
  720. //********************************************************************
  721. void CSimpSvrObj::AddFrameLevelUI()
  722. {
  723.         OutputDebugString("In CSimpSvrObj::AddFrameLevelUIrn");
  724.         // add the combined menu
  725.         m_lpFrame->SetMenu(m_hmenuShared, m_hOleMenu, m_lpDoc->GethDocWnd());
  726.         // do hatched border
  727.         SetParent (m_lpDoc->GethHatchWnd(), m_hWndParent);
  728.         SetParent (m_lpDoc->GethDocWnd(), m_lpDoc->GethHatchWnd());
  729.         // set the border space.  Normally we would negotiate for toolbar
  730.         // space at this point.  Since this server doesn't have a toolbar,
  731.         // this isn't needed...
  732.         if (m_lpFrame)
  733.                 m_lpFrame->SetBorderSpace(NULL);
  734.         if (m_lpCntrDoc)
  735.                 m_lpCntrDoc->SetBorderSpace(NULL);
  736. }
  737. //**********************************************************************
  738. //
  739. // CSimpSvrObj::DoInPlaceHide
  740. //
  741. // Purpose:
  742. //
  743. //      Hides the object while inplace actvie
  744. //
  745. // Parameters:
  746. //
  747. //      None
  748. //
  749. // Return Value:
  750. //
  751. //      None
  752. //
  753. // Function Calls:
  754. //      Function                        Location
  755. //
  756. //      OutputDebugString               Windows API
  757. //      SetParent                       Windows API
  758. //      CSimpSvrDoc::GethDocWnd         DOC.H
  759. //      CSimpSvrDoc::GethAppWnd         DOC.H
  760. //      CSimpSvrDoc::GethHatchWnd       DOC.H
  761. //      CSimpSvrObj::DisassembleMenus   OBJ.CPP
  762. //      IOleInPlaceFrame::Release       Container
  763. //      IOleInPlaceUIWindow::Release    Container
  764. //
  765. //
  766. // Comments:
  767. //
  768. //      Be sure to read TECHNOTES.WRI included with the OLE SDK
  769. //      for details on implementing inplace activation.
  770. //
  771. //********************************************************************
  772. void CSimpSvrObj::DoInPlaceHide()
  773. {
  774.         OutputDebugString("In CSimpSvrObj::DoInPlaceHidern");
  775.         // if we aren't inplace visible, then this routine is a NOP,
  776.         if (!m_fInPlaceVisible)
  777.                 return;
  778.         m_fInPlaceVisible = FALSE;
  779.         // change the parenting
  780.         SetParent (m_lpDoc->GethDocWnd(), m_lpDoc->GethAppWnd());
  781.         SetParent (m_lpDoc->GethHatchWnd(),m_lpDoc->GethDocWnd());
  782.         // rip down the combined menus
  783.         DisassembleMenus();
  784.         // release the inplace frame
  785.         m_lpFrame->Release();
  786.         m_lpFrame = NULL;  // only holding one ref. to frame.
  787.         // release the UIWindow if it is there.
  788.         if (m_lpCntrDoc)
  789.                 m_lpCntrDoc->Release();
  790.         m_lpCntrDoc = NULL;
  791. }
  792. //**********************************************************************
  793. //
  794. // CSimpSvrObj::DisassembleMenus
  795. //
  796. // Purpose:
  797. //
  798. //      Disassembles the combined menus used in inplace activation
  799. //
  800. // Parameters:
  801. //
  802. //      None
  803. //
  804. // Return Value:
  805. //
  806. //      None
  807. //
  808. // Function Calls:
  809. //      Function                    Location
  810. //
  811. //      OutputDebugString               Windows API
  812. //      OleDestroyMenuDescriptor        OLE API
  813. //      RemoveMenu                      Windows API
  814. //      IOleInPlaceFrame::RemoveMenus   Container
  815. //      DestroyMenu                     Windows API
  816. //
  817. // Comments:
  818. //
  819. //      Be sure to read TECHNOTES.WRI included with the OLE SDK
  820. //      for details on implementing inplace activation.
  821. //
  822. //********************************************************************
  823. void CSimpSvrObj::DisassembleMenus()
  824. {
  825.         // destroy the menu descriptor
  826.         OleDestroyMenuDescriptor(m_hOleMenu);
  827.         if (m_hmenuShared)
  828.                 {
  829.                 // remove the menus that we added
  830.                 RemoveMenu( m_hmenuShared, 1, MF_BYPOSITION);
  831.                 // have the container remove its menus
  832.                 m_lpFrame->RemoveMenus(m_hmenuShared);
  833.                 // Destroy the menu resource
  834.                 DestroyMenu(m_hmenuShared);
  835.                 m_hmenuShared = NULL;
  836.                 }
  837. }
  838. //**********************************************************************
  839. //
  840. // CSimpSvrObj::SendOnDataChange
  841. //
  842. // Purpose:
  843. //
  844. //      Uses the data advise holder to send a data change, then updates
  845. //      the ROT to note the time of change.
  846. //
  847. // Parameters:
  848. //
  849. //      None
  850. //
  851. // Return Value:
  852. //
  853. //      None
  854. //
  855. // Function Calls:
  856. //      Function                                Location
  857. //
  858. //      IDataAdviseHolder::SendOnDataChange     OLE API
  859. //      GetRunningObjectTable                   OLE API
  860. //      CoFileTimeNow                           OLE API
  861. //      IRunningObjectTable::NoteChangeTime     OLE API
  862. //
  863. // Comments:
  864. //
  865. //
  866. //********************************************************************
  867. void CSimpSvrObj::SendOnDataChange()
  868. {
  869.         if (m_lpDataAdviseHolder)
  870.                 m_lpDataAdviseHolder->SendOnDataChange( (LPDATAOBJECT)&m_DataObject, 0, 0);
  871.         LPRUNNINGOBJECTTABLE lpRot;
  872.         GetRunningObjectTable(0, &lpRot);
  873.         if ( lpRot && m_dwRegister)
  874.                 {
  875.                 FILETIME ft;
  876.                 CoFileTimeNow(&ft);
  877.                 lpRot->NoteChangeTime(m_dwRegister, &ft);
  878.                 lpRot->Release();
  879.                 }
  880. }
  881. //**********************************************************************
  882. //
  883. // CSimpSvrObj::DeactivateUI
  884. //
  885. // Purpose:
  886. //
  887. //      Breaks down the inplace ui
  888. //
  889. // Parameters:
  890. //
  891. //      None
  892. //
  893. // Return Value:
  894. //
  895. //      None
  896. //
  897. // Function Calls:
  898. //      Function                                Location
  899. //
  900. //      SetParent                               Windows API
  901. //      IOleInPlaceUIWindow::SetActiveObject    Container
  902. //      IOleInPlaceFrame::SetActiveObject       Container
  903. //      IOleInPlaceSite::UIDeactivate           Container
  904. //
  905. // Comments:
  906. //
  907. //
  908. //********************************************************************
  909. void CSimpSvrObj::DeactivateUI()
  910. {
  911.         // if not UI active, or no pointer to IOleInPlaceFrame, then
  912.         // return NOERROR
  913.         if (!(m_fUIActive || m_lpFrame))
  914.                 return;
  915.         else
  916.                 {
  917.                 m_fUIActive = FALSE;
  918.                 // remove hatching
  919.                 SetParent (m_lpDoc->GethDocWnd(), m_lpDoc->GethAppWnd());
  920.                 SetParent (m_lpDoc->GethHatchWnd(),m_lpDoc->GethDocWnd());
  921.                 // if in an MDI container, call SetActiveObject on the DOC.
  922.                 if (m_lpCntrDoc)
  923.                         m_lpCntrDoc->SetActiveObject(NULL, NULL);
  924.                 m_lpFrame->SetActiveObject(NULL, NULL);
  925.                 // tell the container that our UI is going away.
  926.                 if (m_lpIPSite)
  927.                         m_lpIPSite->OnUIDeactivate(FALSE);
  928.                 }
  929. }