?? polyline.cpp
字號:
* CPolyline::RenderNative
*
* Purpose:
* Retrieves the Polyline's data in a global memory handle.
*
* Parameters:
* phMem HGLOBAL * in which to store the handle.
*
* Return Value:
* HRESULT NOERROR if successful, otherwise a
* POLYLINE_E_ value.
*/
STDMETHODIMP CPolyline::RenderNative(HGLOBAL *phMem)
{
HGLOBAL hMem;
PPOLYLINEDATA ppl;
HRESULT hr=ResultFromScode(POLYLINE_E_INVALIDPOINTER);
if (NULL==phMem)
return ResultFromScode(POLYLINE_E_INVALIDPOINTER);
hMem=GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, CBPOLYLINEDATA);
if (NULL!=hMem)
{
ppl=(PPOLYLINEDATA)GlobalLock(hMem);
hr=DataGet(ppl);
GlobalUnlock(hMem);
if (FAILED(hr))
{
GlobalFree(hMem);
hMem=NULL;
}
}
*phMem=hMem;
return hr;
}
/*
* CPolyline::RenderBitmap
*
* Purpose:
* Creates a bitmap image of the current Polyline.
*
* Parameters:
* phBmp HBITMAP * in which to return the bitmap.
*
* Return Value:
* HRESULT NOERROR if successful, otherwise a
* POLYLINE_E_ value.
*/
STDMETHODIMP CPolyline::RenderBitmap(HBITMAP *phBmp)
{
HDC hDC;
HDC hMemDC;
HBITMAP hBmp;
RECT rc;
HGDIOBJ hObj;
if (NULL==phBmp)
return ResultFromScode(POLYLINE_E_INVALIDPOINTER);
//Render a bitmap the size of the current rectangle.
hDC=GetDC(m_hWnd);
hMemDC=CreateCompatibleDC(hDC);
GetClientRect(m_hWnd, &rc);
hBmp=CreateCompatibleBitmap(hDC, rc.right, rc.bottom);
if (NULL!=hBmp)
{
//Draw the POLYLINEDATA into the bitmap.
hObj=SelectObject(hMemDC, hBmp);
Draw(hMemDC, FALSE, TRUE, &rc, NULL);
SelectObject(hMemDC, hObj);
}
DeleteDC(hMemDC);
ReleaseDC(m_hWnd, hDC);
*phBmp=hBmp;
return NOERROR;
}
//RenderMetafile not necessary--now part of RenderMetafilePict.
/*
* CPolyline::RenderMetafilePict
*
* Purpose:
* Renders the current Polyline into a METAFILEPICT structure in
* global memory.
*
* Parameters:
* phMem HGLOBAL * in which to return the
* METAFILEPICT.
*
* Return Value:
* HRESULT NOERROR if successful, otherwise a
* POLYLINE_E_ value.
*/
STDMETHODIMP CPolyline::RenderMetafilePict(HGLOBAL *phMem)
{
HGLOBAL hMem;
HMETAFILE hMF;
LPMETAFILEPICT pMF;
RECT rc;
HDC hDC;
if (NULL==phMem)
return ResultFromScode(POLYLINE_E_INVALIDPOINTER);
//Create a memory metafile and return its handle.
hDC=(HDC)CreateMetaFile(NULL);
if (NULL==hDC)
return ResultFromScode(STG_E_MEDIUMFULL);
SetMapMode(hDC, MM_ANISOTROPIC);
GetClientRect(m_hWnd, &rc);
SetWindowOrgEx(hDC, 0, 0, NULL);
SetWindowExtEx(hDC, rc.right, rc.bottom, NULL);
Draw(hDC, TRUE, TRUE, &rc, NULL);
hMF=CloseMetaFile(hDC);
if (NULL==hMF)
return ResultFromScode(STG_E_MEDIUMFULL);
//Allocate the METAFILEPICT structure.
hMem=GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE
, sizeof(METAFILEPICT));
if (NULL==hMem)
{
DeleteMetaFile(hMF);
return ResultFromScode(E_FAIL);
}
/*
* Global lock only fails in PMODE if the selector is invalid
* (like it was discarded) or references a 0 length segment,
* neither of which can happen here.
*/
pMF=(LPMETAFILEPICT)GlobalLock(hMem);
pMF->hMF=hMF;
pMF->mm=MM_ANISOTROPIC;
//Insert the extents in MM_HIMETRIC units.
GetClientRect(m_hWnd, &rc);
RectConvertMappings(&rc, FALSE);
pMF->xExt=rc.right;
pMF->yExt=rc.bottom;
GlobalUnlock(hMem);
*phMem=hMem;
return NOERROR;
}
/*
* CPolyline::Instance
*
* Purpose:
* Provides access to the module instance.
*
* Parameters:
* None
*
* Return Value:
* HINSTANCE The instance handle of the module.
*/
HINSTANCE CPolyline::Instance(void)
{
return m_hInst;
}
/*
* CPolyline::String
*
* Purpose:
* Provides string lookup in the Polyline string table.
*
* Parameters:
* uID UINT of the string to return.
*
* Return Value:
* LPTSTR Pointer to the string.
*/
LPTSTR CPolyline::String(UINT uID)
{
return PSZ(uID);
}
/*
* CPolyline::SendAdvise
*
* Purpose:
* Calls the appropriate IOleClientSite or IAdviseSink member
* function for various events such as closure, renaming, etc.
*
* Parameters:
* uCode UINT OBJECTCODE_* identifying the notification.
*
* Return Value:
* None
*/
void CPolyline::SendAdvise(UINT uCode)
{
DWORD dwAspect=DVASPECT_CONTENT | DVASPECT_THUMBNAIL;
switch (uCode)
{
case OBJECTCODE_SAVED:
if (NULL!=m_pIOleAdviseHolder)
m_pIOleAdviseHolder->SendOnSave();
break;
case OBJECTCODE_CLOSED:
if (NULL!=m_pIOleAdviseHolder)
m_pIOleAdviseHolder->SendOnClose();
break;
case OBJECTCODE_RENAMED:
//Call IOleAdviseHolder::SendOnRename (later)
break;
case OBJECTCODE_SAVEOBJECT:
if (m_fDirty && NULL!=m_pIOleClientSite)
m_pIOleClientSite->SaveObject();
m_fDirty=FALSE;
break;
case OBJECTCODE_DATACHANGED:
m_fDirty=TRUE;
//No flags are necessary here.
if (NULL!=m_pIDataAdviseHolder)
{
m_pIDataAdviseHolder->SendOnDataChange
(m_pImpIDataObject, 0, 0);
}
if (NULL!=m_pIAdviseSink
& (dwAspect & m_dwAdviseAspects))
{
m_pIAdviseSink->OnViewChange(dwAspect
& m_dwAdviseAspects, 0);
}
break;
case OBJECTCODE_SHOWWINDOW:
if (NULL!=m_pIOleClientSite)
m_pIOleClientSite->OnShowWindow(TRUE);
break;
case OBJECTCODE_HIDEWINDOW:
if (NULL!=m_pIOleClientSite)
m_pIOleClientSite->OnShowWindow(FALSE);
break;
case OBJECTCODE_SHOWOBJECT:
if (NULL!=m_pIOleClientSite)
m_pIOleClientSite->ShowObject();
break;
}
return;
}
//CHAPTER23MOD
/*
* CPolyline::InPlaceActivate
*
* Purpose:
* Goes through all the steps of activating the Polyline as an
* in-place object.
*
* Parameters:
* pActiveSite LPOLECLIENTSITE of the active site we show in.
* fIncludeUI BOOL controls whether we call UIActivate too.
*
* Return Value:
* HRESULT Whatever error code is appropriate.
*/
HRESULT CPolyline::InPlaceActivate(LPOLECLIENTSITE pActiveSite
, BOOL fIncludeUI)
{
HRESULT hr;
HWND hWnd;
HWND hWndHW;
RECT rcPos;
RECT rcClip;
OLEINPLACEFRAMEINFO frameInfo;
if (NULL==pActiveSite)
return ResultFromScode(E_INVALIDARG);
if (NULL!=m_pIOleIPSite)
{
if (fIncludeUI)
UIActivate();
return NOERROR;
}
//1. Initialization, obtaining interfaces, OnInPlaceActivate.
hr=pActiveSite->QueryInterface(IID_IOleInPlaceSite
, (PPVOID)&m_pIOleIPSite);
if (FAILED(hr))
return hr;
hr=m_pIOleIPSite->CanInPlaceActivate();
if (NOERROR!=hr)
{
m_pIOleIPSite->Release();
m_pIOleIPSite=NULL;
return ResultFromScode(E_FAIL);
}
m_pIOleIPSite->OnInPlaceActivate();
//2. Get the window context and create a window.
m_pIOleIPSite->GetWindow(&hWnd);
frameInfo.cb=sizeof(OLEINPLACEFRAMEINFO);
m_pIOleIPSite->GetWindowContext(&m_pIOleIPFrame
, &m_pIOleIPUIWindow, &rcPos, &rcClip, &frameInfo);
/*
* Create the hatch window after we get a parent window. We
* could not create the hatch window sooner because had nothing
* to use for the parent.
*/
m_pHW=new CHatchWin(m_hInst);
if (NULL==m_pHW)
{
InPlaceDeactivate();
return ResultFromScode(E_OUTOFMEMORY);
}
if (!m_pHW->Init(hWnd, ID_HATCHWINDOW, NULL))
{
InPlaceDeactivate();
return ResultFromScode(E_OUTOFMEMORY);
}
//Make sure dialog is hidden
if (NULL!=m_hDlg)
{
ShowWindow(m_hDlg, SW_HIDE);
SendAdvise(OBJECTCODE_HIDEWINDOW);
}
//Move the hatch window to the container window.
hWndHW=m_pHW->Window();
SetParent(hWndHW, hWnd);
//Move the Polyline window from the hidden dialog to hatch window
m_pHW->HwndAssociateSet(m_hWnd);
m_pHW->ChildSet(m_hWnd);
m_pHW->RectsSet(&rcPos, &rcClip); //Positions polyline
ShowWindow(hWndHW, SW_SHOW);
SendAdvise(OBJECTCODE_SHOWOBJECT);
//3, 4, 5. Do UI things: active object, shared menu, tools
hr=NOERROR;
if (fIncludeUI)
hr=UIActivate();
/*
* Since we don't have an Undo while in-place, tell the continer
* to free it's undo state immediately.
*/
m_pIOleIPSite->DiscardUndoState();
return hr;
}
/*
* CPolyline::InPlaceDeactivate
*
* Purpose:
* Reverses all the activation steps from InPlaceActivate.
*
* Parameters:
* None
*
* Return Value:
* None
*/
void CPolyline::InPlaceDeactivate(void)
{
UIDeactivate();
if (NULL!=m_pHW)
{
RECT rc;
ShowWindow(m_pHW->Window(), SW_HIDE);
//Reposition the polyline window in the dialog box.
SetParent(m_hWnd, m_hDlg);
CalcPolyRectInDialog(m_hDlg, &rc);
SetWindowPos(m_hWnd, NULL, rc.left, rc.top
, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER);
m_pHW->ChildSet(NULL);
delete m_pHW;
m_pHW=NULL;
}
ReleaseInterface(m_pIOleIPFrame);
ReleaseInterface(m_pIOleIPUIWindow)
if (NULL!=m_pIOleIPSite)
{
m_pIOleIPSite->OnInPlaceDeactivate();
ReleaseInterface(m_pIOleIPSite);
}
return;
}
/*
* CPolyline::UIActivate
*
* Purpose:
* Goes through all the steps of activating the user interface of
* Polyline as an in-place object.
*
* Parameters:
* None
*
* Return Value:
* HRESULT NOERROR or error code.
*/
HRESULT CPolyline::UIActivate(void)
{
//1. Call IOleInPlaceSite::UIActivate
if (NULL!=m_pIOleIPSite)
m_pIOleIPSite->OnUIActivate();
//2. Set the active object
#ifdef WIN32ANSI
OLECHAR szTemp[40];
MultiByteToWideChar(CP_ACP, 0, PSZ(IDS_USERTYPE)
, -1, szTemp, 40);
#endif
if (NULL!=m_pIOleIPFrame)
{
m_pIOleIPFrame->SetActiveObject(m_pImpIOleIPActiveObject
#ifdef WIN32ANSI
, szTemp);
#else
, PSZ(IDS_USERTYPE));
#endif
}
if (NULL!=m_pIOleIPUIWindow)
{
m_pIOleIPUIWindow->SetActiveObject(m_pImpIOleIPActiveObject
#ifdef WIN32ANSI
, szTemp);
#else
, PSZ(IDS_USERTYPE));
#endif
}
//3. Critical for accelerators to work initially.
SetFocus(m_pHW->Window());
//4. Negotiate border space. Polyline doesn't need any.
if (NULL!=m_pIOleIPFrame)
m_pIOleIPFrame->SetBorderSpace(NULL);
if (NULL!=m_pIOleIPUIWindow)
m_pIOleIPUIWindow->SetBorderSpace(NULL);
/*
* 5. Create the shared menu. We don't have any, so tell
* the container to use its own menu.
*/
if (NULL!=m_pIOleIPFrame)
m_pIOleIPFrame->SetMenu(NULL, NULL, m_hWnd);
m_fUIActive=TRUE;
return NOERROR;
}
/*
* CPolyline::UIDeactivate
*
* Purpose:
* Reverses all the user interface activation steps from
* UIActivate.
*
* Parameters:
* None
*
* Return Value:
* None
*/
void CPolyline::UIDeactivate(void)
{
m_fUIActive=FALSE;
//We don't have any shared menu or tools to clean up.
//Clear out the active objects
if (NULL!=m_pIOleIPFrame)
m_pIOleIPFrame->SetActiveObject(NULL, NULL);
if (NULL!=m_pIOleIPUIWindow)
m_pIOleIPUIWindow->SetActiveObject(NULL, NULL);
if (NULL!=m_pIOleIPSite)
m_pIOleIPSite->OnUIDeactivate(FALSE);
return;
}
//End CHAPTER23MOD
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -