Objective Views : Chapter 15 OLE Document Servers : Server Item OnGetExtent()
Server Item OnGetExtent()
The container must be able to query the server for the size of the item. The COleServerItem::OnGetExtent() method is called when the container requests the size of the item. The size of the item is always expressed in MM_HIMETRIC units (0.01 millimeters per logic unit). The viewport contains a method to return its bounds in MM_HIMETRIC units. All you need to do is get the viewport, make sure it is sized to display the entire model, and then retrieve the size.
Example 26 – OnGetExtent() method
BOOL CMyAppSrvrItem::OnGetExtent(DVASPECT dwDrawAspect,
CSize& rSize)
{
// Most applications, like this one, only handle drawing the
// content aspect of the item. If you wish to support other
// aspects, such as DVASPECT_THUMBNAIL (by overriding OnDrawEx),
// then this implementation of OnGetExtent should be modified
// to handle the additional aspect(s).
 
if (dwDrawAspect != DVASPECT_CONTENT)
return COleServerItem::OnGetExtent(dwDrawAspect, rSize);
 
//
// This function is called to get the extent in HIMETRIC units of
// the entire item.
//
CMyAppViewport* pViewport = GetViewport();
if (pViewport != NULL)
{
// Set the viewport size
pViewport->SizeToModel();
CRect rcBounds = pViewport->GetHiMetricBounds();
rSize.cx = rcBounds.Width();
rSize.cy = rcBounds.Height();
return TRUE;
}
 
return FALSE;
}