📄 ioleobj.cpp
字号:
* pRectPos LPRECT of the object in hWndParent where the
* object can play in-place if desired.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::DoVerb(LONG iVerb, LPMSG pMSG
, LPOLECLIENTSITE pActiveSite, LONG lIndex, HWND hWndParent
, LPCRECT pRectPos)
{
HWND hWnd, hWndT;
//CHAPTER23MOD
/*
* Find the upper most window. Note that for in-place activation
* we must start at the document to find our uppermost frame because
* the object editing window may be a child of the container now.
*/
//End CHAPTER23MOD
hWndT=GetParent(m_pObj->m_pDoc->Window());
while (NULL!=hWndT)
{
hWnd=hWndT;
hWndT=GetParent(hWndT);
}
switch (iVerb)
{
//CHAPTER23MOD
case OLEIVERB_HIDE:
if (NULL!=m_pObj->m_pIOleIPSite)
m_pObj->InPlaceDeactivate();
else
{
ShowWindow(hWnd, SW_HIDE);
m_pObj->SendAdvise(OBJECTCODE_HIDEWINDOW);
}
break;
case OLEIVERB_PRIMARY:
case OLEIVERB_SHOW:
//If already IP active, nothing much to do here.
if (NULL!=m_pObj->m_pIOleIPSite)
return NOERROR;
if (m_pObj->m_fAllowInPlace)
{
if (SUCCEEDED(m_pObj->InPlaceActivate(pActiveSite
, TRUE)))
{
return NOERROR;
}
}
//FALL-THROUGH
case OLEIVERB_OPEN:
/*
* If we're already in-place active, deactivate and
* prevent later reactivation.
*/
if (NULL!=m_pObj->m_pIOleIPSite)
{
m_pObj->InPlaceDeactivate();
m_pObj->m_fAllowInPlace=FALSE;
}
/*
* With all the in-place stuff gone, we can go back to
* our normal open state.
*/
ShowWindow(hWnd, SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
m_pObj->SendAdvise(OBJECTCODE_SHOWOBJECT);
m_pObj->SendAdvise(OBJECTCODE_SHOWWINDOW);
break;
case OLEIVERB_INPLACEACTIVATE:
//This means activate in-place but no UI.
return m_pObj->InPlaceActivate(pActiveSite, FALSE);
case OLEIVERB_UIACTIVATE:
//This means fully activate in-place with full UI
return m_pObj->InPlaceActivate(pActiveSite, TRUE);
case OLEIVERB_DISCARDUNDOSTATE:
//We don't hold a state, but if you do, free it here.
break;
//End CHAPTER23MOD
default:
return ResultFromScode(OLEOBJ_S_INVALIDVERB);
}
return NOERROR;
}
/*
* CImpIOleObject::EnumVerbs
*
* Purpose:
* Creates an enumerator that knows the object's verbs. If you
* need to change the verb list dynamically, then you'll need to
* implement this, otherwise you can return OLE_S_USEREG.
*
* Parameters:
* ppEnum LPENUMOLEVERB * into which to return the
* enum.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::EnumVerbs(LPENUMOLEVERB *ppEnum)
{
//Trivial implementation if you fill the regDB.
return ResultFromScode(OLE_S_USEREG);
}
/*
* CImpIOleObject::Update
*
* Purpose:
* Insures that the object is up to date. This is mostly used for
* caching but you must make sure that you recursively call all
* nested objects you contain as well.
*
* Parameters:
* None
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::Update(void)
{
//We're always updated since we don't contain.
return NOERROR;
}
/*
* CImpIOleObject::IsUpToDate
*
* Purpose:
* Returns if the object is currently up to date, which involves
* asking all contained object inside this object if they are up
* to date as well.
*
* Parameters:
* None
*
* Return Value:
* HRESULT NOERROR if successful, S_FALSE if dirty.
*/
STDMETHODIMP CImpIOleObject::IsUpToDate(void)
{
//We're always updated since we don't contain.
return NOERROR;
}
/*
* CImpIOleObject::GetUserClassID
*
* Purpose:
* Used for linked objects, this returns the class ID of what end
* users think they are editing.
*
* Parameters:
* pClsID LPCLSID in which to store the CLSID.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::GetUserClassID(LPCLSID pClsID)
{
/*
* If you are not registered to handle data other than yourself,
* then you can just return your class ID here. If you are
* registered as usable from Treat-As dialogs, then you need
* to return the CLSID of what you are really editing.
*/
*pClsID=m_pObj->m_clsID;
return NOERROR;
}
/*
* CImpIOleObject::GetUserType
*
* Purpose:
* Determines the user-presentable name of the object.
*
* Parameters:
* dwForm DWORD describing which form of the string is
* desired.
* pszType LPOLESTR * into which to return the pointer to
* the type string.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::GetUserType(DWORD dwForm
, LPOLESTR *ppszType)
{
return ResultFromScode(OLE_S_USEREG);
}
/*
* CImpIOleObject::SetExtent
*
* Purpose:
* Sets the size of the object in HIMETRIC units.
*
* Parameters:
* dwAspect DWORD of the aspect affected.
* pszl LPSIZEL containing the new size.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::SetExtent(DWORD dwAspect, LPSIZEL pszl)
{
RECT rc;
SIZEL szl;
if (!(DVASPECT_CONTENT & dwAspect))
return ResultFromScode(E_FAIL);
XformSizeInHimetricToPixels(NULL, pszl, &szl);
//This resizes the window to match the container's size.
SetRect(&rc, 0, 0, (int)szl.cx, (int)szl.cy);
m_pObj->m_pPL->SizeSet(&rc, TRUE);
return NOERROR;
}
/*
* CImpIOleObject::GetExtent
*
* Purpose:
* Retrieves the size of the object in HIMETRIC units.
*
* Parameters:
* dwAspect DWORD of the aspect requested
* pszl LPSIZEL into which to store the size.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::GetExtent(DWORD dwAspect, LPSIZEL pszl)
{
RECT rc;
SIZEL szl;
if (!(DVASPECT_CONTENT & dwAspect))
return ResultFromScode(E_FAIL);
m_pObj->m_pPL->RectGet(&rc);
szl.cx=rc.right-rc.left;
szl.cy=rc.bottom-rc.top;
XformSizeInPixelsToHimetric(NULL, &szl, pszl);
return NOERROR;
}
/*
* CImpIOleObject::Advise
*
* Purpose:
* Provides an IAdviseSink to the object for notifications.
*
* Parameters:
* pIAdviseSink LPADVISESINK to notify.
* pdwConn LPDWORD into which to store a connection key.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::Advise(LPADVISESINK pIAdviseSink
, LPDWORD pdwConn)
{
if (NULL==m_pObj->m_pIOleAdviseHolder)
{
HRESULT hr;
hr=CreateOleAdviseHolder(&m_pObj->m_pIOleAdviseHolder);
if (FAILED(hr))
return hr;
}
return m_pObj->m_pIOleAdviseHolder->Advise(pIAdviseSink
, pdwConn);
}
/*
* CImpIOleObject::Unadvise
*
* Purpose:
* Terminates a previous advise connection from Advise.
*
* Parameters:
* dwConn DWORD connection key from Advise.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::Unadvise(DWORD dwConn)
{
if (NULL!=m_pObj->m_pIOleAdviseHolder)
return m_pObj->m_pIOleAdviseHolder->Unadvise(dwConn);
return ResultFromScode(E_FAIL);
}
/*
* CImpIOleObject::EnumAdvise
*
* Purpose:
* Creates and returns a enumeration of the advises on this object.
*
* Parameters:
* ppEnum LPENUMSTATDATA * in which to return the
* enumerator.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::EnumAdvise(LPENUMSTATDATA *ppEnum)
{
if (NULL!=m_pObj->m_pIOleAdviseHolder)
return m_pObj->m_pIOleAdviseHolder->EnumAdvise(ppEnum);
return ResultFromScode(E_FAIL);
}
/*
* CImpIOleObject::GetMiscStatus
*
* Purpose:
* Returns a set of miscellaneous status flags for the object.
*
* Parameters:
* dwAspect DWORD of the aspect in question.
* pdwStatus LPDWORD in which to store the flags.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::GetMiscStatus(DWORD dwAspect
, LPDWORD pdwStatus)
{
return ResultFromScode(OLE_S_USEREG);
}
/*
* CImpIOleObject::SetColorScheme
*
* Purpose:
* Provides the object with the color palette as recommended by
* the container application that also knows the palettes of other
* objects. The object here is not required to use these colors.
*
* Parameters:
* pLP LPLOGPALETTE providing the colors.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::SetColorScheme(LPLOGPALETTE pLP)
{
return ResultFromScode(E_NOTIMPL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -