# OCLIENT Sample: Illustrates a Visual Editing Container Application

The OCLIENT sample is an example of a visual editing container application. It is essentially an extended version of the CONTAINER sample, although it is not strictly a derivation of CONTAINER.

Security Note
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices.

# Building and Running the Sample

#### To build and run the OCLIENT sample

1. Open the solution OCLIENT.sln.

2. On the Build menu, click Build.

3. Open and run the OCLIENT application.

OCLIENT illustrates these features:

- Drag and drop to and from another application.

- Cloning (duplication) of objects with Control-Drag within the same application window.

- Automatic scrolling of window during a drag-and-drop operation.

- Edit Paste of a native format object.

- Edit Paste Link.

OCLIENT, like CONTAINER, is a simple object-drawing program. The only type of object it draws is a linked or embedded OLE item.

#### To add a new object to the OCLIENT drawing

1. Click Insert New Object on the Edit menu.

   The Insert New Object dialog box appears.

2. Select the type of OLE item you want to add.

   A new object will appear in OCLIENT's window, and OCLIENT's menu and toolbar will be updated with pop-up menus and toolbar buttons supplied by the server application.

-or-

1. While running an Automation server, copy an OLE item to the Clipboard.

2. On the Edit menu in OCLIENT, click Paste to embed the OLE item, or click Paste Link to link the OLE item.

The newly added OLE item is always placed in the top left corner of the OCLIENT drawing. The new OLE item might partially or completely cover an older item. You can select one OLE item at a time using the mouse. A selected linked item is indicated with a dotted rectangle, and an embedded item is indicated with a solid rectangle. You can move an OLE item by dragging it; you can resize a selected OLE item by using the resize handles.

To delete an OLE item, select it with a mouse click, then press DELETE or use the Clear command on the Edit menu.

To edit the contents of an OLE item, double-click it or select it with the mouse and then click Edit <type> Object on the Edit menu. To complete the editing of an in-place editing item, click somewhere outside the rectangle of the item in OCLIENT's window. To complete the editing of an item that has been fully opened in the server application, use the server's File Update command.

# Keywords

This sample demonstrates the following keywords:

AfxGetMainWnd; AfxMessageBox; AfxOleInit; AfxThrowArchiveException; AfxThrowFileException; AfxThrowMemoryException; CArchive::Close; CArchive::IsStoring; CCmdTarget::BeginWaitCursor; CCmdTarget::EndWaitCursor; CCmdUI::Enable; CCmdUI::SetCheck; CControlBar::EnableDocking; CDC::DPtoLP; CDC::DrawFocusRect; CDC::GetDeviceCaps; CDC::HIMETRICtoDP; CDC::LPtoDP; CDC::RealizePalette; CDC::SelectPalette; CDocTemplate::SetContainerInfo; CDocument::SetModifiedFlag; CDocument::UpdateAllViews; CFrameWnd::DockControlBar; CFrameWnd::EnableDocking; CFrameWnd::LoadFrame; CFrameWnd::OnCreateClient; CGdiObject::UnrealizeObject; CMDIChildWnd::Create; CMenu::GetSubMenu; CMenu::LoadMenu; CMenu::TrackPopupMenu; CObject::AssertValid; CObject::Dump; CObject::IsKindOf; CObject::Serialize; COleClientItem::Close; COleClientItem::CreateCloneFrom; COleClientItem::Deactivate; COleClientItem::Delete; COleClientItem::DoDragDrop; COleClientItem::DoVerb; COleClientItem::Draw; COleClientItem::GetActiveView; COleClientItem::GetClipboardData; COleClientItem::GetDocument; COleClientItem::GetDrawAspect; COleClientItem::GetInPlaceWindow; COleClientItem::GetItemState; COleClientItem::GetType; COleClientItem::IsInPlaceActive; COleClientItem::OnActivate; COleClientItem::OnChange; COleClientItem::OnChangeItemPosition; COleClientItem::OnDeactivateUI; COleClientItem::OnGetClipboardData; COleClientItem::OnGetItemPosition; COleClientItem::SetDrawAspect; COleClientItem::SetItemRects; COleClientItem::UpdateLink; COleDataObject::Attach; COleDataObject::AttachClipboard; COleDataObject::IsDataAvailable; COleDataSource::CacheGlobalData; COleDocument::EnableCompoundFile; COleDocument::GetNextItem; COleDocument::GetStartPosition; COleDocument::HasBlankItems; COleDocument::OnShowViews; COleInsertDialog::CreateItem; COleInsertDialog::DoModal; COleInsertDialog::GetSelectionType; COlePasteSpecialDialog::AddFormat; COlePasteSpecialDialog::AddStandardFormats; COlePasteSpecialDialog::CreateItem; COlePasteSpecialDialog::DoModal; COlePasteSpecialDialog::GetSelectionType; COleTemplateServer::ConnectTemplate; COleTemplateServer::UpdateRegistry; COleUpdateDialog::DoModal; CPalette::CreateHalftonePalette; CRect::InflateRect; CRect::IntersectRect; CRect::IsRectEmpty; CRect::OffsetRect; CRect::Size; CRect::TopLeft; CRectTracker::Draw; CRectTracker::HitTest; CRectTracker::SetCursor; CRectTracker::Track; CScrollView::GetDeviceScrollPosition; CScrollView::SetScrollSizes; CStatusBar::Create; CStatusBar::SetIndicators; CToolBar::Create; CToolBar::LoadBitmap; CToolBar::SetButtons; CView::DoPreparePrinting; CView::GetDocument; CView::IsSelected; CView::OnDragEnter; CView::OnDragLeave; CView::OnDragOver; CView::OnDraw; CView::OnDrop; CView::OnInitialUpdate; CView::OnPrepareDC; CView::OnPreparePrinting; CView::OnScrollBy; CView::OnUpdate; CWinApp::AddDocTemplate; CWinApp::EnableShellOpen; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWinApp::RegisterShellFileTypes; CWinApp::RunEmbedded; CWnd::ClientToScreen; CWnd::GetClientRect; CWnd::GetDC; CWnd::GetParentFrame; CWnd::InvalidateRect; CWnd::OnChar; CWnd::OnCreate; CWnd::OnDestroy; CWnd::OnLButtonDblClk; CWnd::OnLButtonDown; CWnd::OnPaletteChanged; CWnd::OnQueryNewPalette; CWnd::OnRButtonDown; CWnd::OnSetCursor; CWnd::OnSetFocus; CWnd::OnSize; CWnd::ReleaseDC; CWnd::SetFocus; CWnd::ShowWindow; CWnd::UpdateWindow; CreateHatchBrush; DeleteItem; DragAcceptFiles; FORMATETC; FillRect; GetDeviceCaps; GetKeyState; GetSysColor; GlobalFree; GlobalLock; GlobalUnlock; LPtoDP; MessageBeep; MulDiv; RGB; RectVisible; RegisterClipboardFormat; ReleaseStgMedium; STGMEDIUM; SelectPalette; SetBkColor; SetBrushOrg; SetMapMode; SetRect; SetTextColor; SetViewportExt; SetWindowExt; abs; afxMemDF; max; memset; min

Note
Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.