Objective Views : Chapter 15 OLE Document Servers : Server Item Viewport
Server Item Viewport
To render the information in the model, the server item needs a viewport. The CView derived class in your application either mixes in a viewport class, or it contains a viewport as a member. It is possible to have your COleServerItem derived class either mix in or aggregate a viewport. However, it is easier to use the viewport that is already available from the active CView object attached to the document. When the document template is used to create the server document, it also creates a view. By retrieving the first view attached to the document, we can get a viewport to use for rendering the server item.
Example 25 – Server item viewport
CMyAppViewport* CMyAppSrvrItem::GetViewport()
{
//
// Find the first view attached to the document, and
// use it to render the server item.
//
 
CMyAppDoc* pDoc = GetDocument();
 
if (pDoc != NULL)
{
POSITION pos = pDoc->GetFirstViewPosition();
CMyAppView* pFirstView = (CMyAppView*) pDoc->GetNextView(pos);
if (pFirstView != NULL)
{
return pFirstView->GetViewport();
}
}
 
return NULL;
}