home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap19 / polyline / irunobj.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  5KB  |  219 lines

  1. /*
  2.  * IRUNOBJ.CPP
  3.  * Polyline Component Chapter 19
  4.  *
  5.  * Implementation of the IRunnableObject interface which allows
  6.  * us to enter the "running" state which means Polyline's dialog
  7.  * box is created, but not visible.  This is necessary so that
  8.  * containers can ask for our extents before calling DoVerb.
  9.  *
  10.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  11.  *
  12.  * Kraig Brockschmidt, Microsoft
  13.  * Internet  :  kraigb@microsoft.com
  14.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  15.  */
  16.  
  17.  
  18. #include "polyline.h"
  19.  
  20.  
  21. /*
  22.  * CImpIRunnableObject::CImpIRunnableObject
  23.  * CImpIRunnableObject::~CImpIRunnableObject
  24.  *
  25.  * Parameters (Constructor):
  26.  *  pObj            PCPolyline of the object we're in.
  27.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  28.  */
  29.  
  30. CImpIRunnableObject::CImpIRunnableObject(PCPolyline pObj
  31.     , LPUNKNOWN pUnkOuter)
  32.     {
  33.     m_cRef=0;
  34.     m_pObj=pObj;
  35.     m_pUnkOuter=pUnkOuter;
  36.     return;
  37.     }
  38.  
  39. CImpIRunnableObject::~CImpIRunnableObject(void)
  40.     {
  41.     return;
  42.     }
  43.  
  44.  
  45.  
  46. /*
  47.  * CImpIRunnableObject::QueryInterface
  48.  * CImpIRunnableObject::AddRef
  49.  * CImpIRunnableObject::Release
  50.  *
  51.  * Purpose:
  52.  *  Delegating IUnknown members for CImpIRunnableObject.
  53.  */
  54.  
  55. STDMETHODIMP CImpIRunnableObject::QueryInterface(REFIID riid
  56.     , LPVOID *ppv)
  57.     {
  58.     return m_pUnkOuter->QueryInterface(riid, ppv);
  59.     }
  60.  
  61.  
  62. STDMETHODIMP_(ULONG) CImpIRunnableObject::AddRef(void)
  63.     {
  64.     ++m_cRef;
  65.     return m_pUnkOuter->AddRef();
  66.     }
  67.  
  68. STDMETHODIMP_(ULONG) CImpIRunnableObject::Release(void)
  69.     {
  70.     --m_cRef;
  71.     return m_pUnkOuter->Release();
  72.     }
  73.  
  74.  
  75.  
  76.  
  77. /*
  78.  * CImpIRunnableObject::GetRunningClass
  79.  *
  80.  * Purpose:
  81.  *  Returns the CLSID of the object.
  82.  *
  83.  * Parameters:
  84.  *  pClsID          LPCLSID in which to store the CLSID.
  85.  *
  86.  * Return Value:
  87.  *  HRESULT         NOERROR or a general error value.
  88.  */
  89.  
  90. STDMETHODIMP CImpIRunnableObject::GetRunningClass(LPCLSID pClsID)
  91.     {
  92.     *pClsID=m_pObj->m_clsID;
  93.     return NOERROR;
  94.     }
  95.  
  96.  
  97.  
  98.  
  99.  
  100. /*
  101.  * CImpIRunnableObject::Run
  102.  *
  103.  * Purpose:
  104.  *  Run an object in the given bind context, that is, put the object
  105.  *  into the running state.
  106.  *
  107.  * Parameters:
  108.  *  pBindCtx        LPBINDCTX of the bind context to use.
  109.  *
  110.  * Return Value:
  111.  *  HRESULT         NOERROR or a general error value.
  112.  */
  113.  
  114. STDMETHODIMP CImpIRunnableObject::Run(LPBINDCTX pBindCtx)
  115.     {
  116.     /*
  117.      * Create the dialog but not show it.  This function is called
  118.      * from OleRun which is called from within OleCreate.  So when
  119.      * a container creates this object, we'll create the dialog
  120.      * which is a basis for the object's extents (as returned from
  121.      * IViewObject2::GetExtent.  Our IOleObject::DoVerb will later
  122.      * note that the dialog is already created and will just make
  123.      * it visible and not create it anew.
  124.      *
  125.      * Note that the dialog is unowned--it acts like an overlapped
  126.      * window.
  127.      */
  128.  
  129.     if (NULL!=m_pObj->m_hDlg)
  130.         return NOERROR;
  131.  
  132.     //This stores the dialog handle in m_pObj.
  133.     CreateDialogParam(m_pObj->Instance()
  134.         , MAKEINTRESOURCE(IDD_EDITDIALOG), NULL, PolyDlgProc
  135.         , (LPARAM)m_pObj);
  136.  
  137.     if (NULL==m_pObj->m_hDlg)
  138.         return ResultFromScode(E_OUTOFMEMORY);
  139.  
  140.     return NOERROR;
  141.     }
  142.  
  143.  
  144.  
  145.  
  146.  
  147. /*
  148.  * CImpIRunnableObject::IsRunning
  149.  *
  150.  * Purpose:
  151.  *  Answers whether an object is currently in the running state.
  152.  *
  153.  * Parameters:
  154.  *  None
  155.  *
  156.  * Return Value:
  157.  *  BOOL            Indicates the running state of the object.
  158.  */
  159.  
  160. STDMETHODIMP_(BOOL) CImpIRunnableObject::IsRunning(void)
  161.     {
  162.     return (NULL!=m_pObj->m_hDlg);
  163.     }
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. /*
  171.  * CImpIRunnableObject::LockRunning
  172.  *
  173.  * Purpose:
  174.  *  Locks an already running object into the running state or unlocks
  175.  *  it from such a state.
  176.  *
  177.  * Parameters:
  178.  *  fLock               BOOL indicating lock (TRUE) or unlock
  179.  *                      (FALSE)
  180.  *  fLastUnlockCloses   BOOL indicating if the last call to this
  181.  *                      function with fLock==FALSE closes the
  182.  *                      object.
  183.  *
  184.  * Return Value:
  185.  *  HRESULT         NOERROR or a general error value.
  186.  */
  187.  
  188. STDMETHODIMP CImpIRunnableObject::LockRunning(BOOL fLock
  189.     , BOOL fLastUnlockCloses)
  190.     {
  191.     //Calling CoLockObjectExternal is all we have to do here.
  192.     return CoLockObjectExternal(this, fLock, fLastUnlockCloses);
  193.     }
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200. /*
  201.  * CImpIRunnableObject::SetContainedObject
  202.  *
  203.  * Purpose:
  204.  *  Informs the object (embedded object) that it is inside a
  205.  *  compound document container.
  206.  *
  207.  * Parameters:
  208.  *  fContained      BOOL indicating if the object is now contained.
  209.  *
  210.  * Return Value:
  211.  *  HRESULT         NOERROR or a general error value.
  212.  */
  213.  
  214. STDMETHODIMP CImpIRunnableObject::SetContainedObject(BOOL fContained)
  215.     {
  216.     //We can ignore this.
  217.     return NOERROR;
  218.     }
  219.