To finish adding application-specific server support in the document class, you must:
In the following procedure, you’ll use the Add Member Function command to implement the OnSetItemRects
function for class CScribbleDoc
. The framework calls OnSetItemRects when the position or size of the embedded item has changed in the container, or when the clipping of the embedded item has changed in the container. Because Scribble’s view is a CScrollView, you need to call CScrollView::SetScrollSizes to reflect the change in the size of the item. Because there are multiple places where the logic associated with SetScrollSizes must be performed, you will later write a helper function, CScribbleView::ResyncScrollSizes
, which you will call from the override of OnSetItemRects.
To notify the OLE server when the embedded item moves or changes size
CScribbleDoc
.The Add Member Function dialog box appears.
void
.OnSetItemRects(LPCRECT lpPosRect, LPCRECT lpClipRect)
// call base class to change the size of the window
COleServerDoc::OnSetItemRects(lpPosRect, lpClipRect);
// notify first view that scroll info should change
POSITION pos = GetFirstViewPosition();
CScribbleView* pView = (CScribbleView*)GetNextView(pos);
pView->ResyncScrollSizes();
CScribbleView
:#include "ScribbleView.h"
The short filename is ScribVw.h.
The next step is to modify CScribbleDoc::InitDocument
so Scribble’s fixed document size changes from 8 by 9 inches, to 2 by 2 inches. The current size, 8 by 9 inches, is too large for most containers.
To change the initial size of the document
CScribbleDoc::InitDocument
and modify the comments and the parameters that return the default document size, as follows://default document size is 200 x 200 screen pixels
...
m_sizeDoc = CSize(200, 200);
CScribbleDoc
constructor and replace the //TODO comments with the following line:m_sizeDoc = CSize(200, 200);
The m_sizeDoc
variable is also initialized in the helper member function, InitDocument
, when a document is newly created or reopened in a stand-alone running instance of Scribble. InitDocument
is called by Scribble’s overrides of CDocument::OnNewDocument and OnOpenDocument. When Scribble is run as a server, the OnNewDocument
and OnOpenDocument
functions are not called. Therefore a good place to initialize m_sizeDoc
is in the constructor.
Finally, in the following procedure you’ll implement the ability for containers to execute the Paste Link command on the server’s Edit menu.
To implement the document’s support for putting a link format on the Clipboard
The New Windows Message and Event Handlers dialog box appears.
The Add Member Function dialog box appears.
CScribbleItem* pItem = GetEmbeddedItem();
pItem->CopyToClipboard(TRUE);
The framework function COleServerItem::CopyToClipboard creates a COleDataSource object containing the OLE item's data in proper formats, then places the COleDataSource object on the Clipboard. The COleDataSource object includes the item's native data and its representation in CF_METAFILEPICT format, as well as data in any conversion formats you choose to support.