Export (0) Print
Expand All

HIERSVR Sample: Demonstrates a Server Application with OLE Drag and Drop 

Download sample

The HIERSVR sample is an example of a Visual Editing server application that supports linked objects as well as in-place edited objects. In addition, as a "full" server, this application also can directly open and save files. The HIERSVR object is a multiple-level hierarchy diagram, where each node in the hierarchy consists of text surrounded by a rectangle or other shapes. In addition to illustrating server functionality, HIERSVR also illustrates OLE drag and drop, and copying to the Clipboard.

Security noteSecurity 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. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

Building and Running the Sample

To build and run the HIERSVR sample

  1. Open the solution hiersvr.sln.

  2. On the Build menu, click Build.

  3. Run HIERSRV as a stand-alone application so it can register itself with the system.

HIERSRV Diagrams

The type of document or object HIERSVR edits and displays is a single inheritance hierarchy diagram. Each node in the diagram, except the root node, has only one parent node. Each parent can have multiple children. A company's organization chart is an example of a hierarchy diagram. So is the list of the MFC classes, because they do not use C++ multiple inheritance. Mfcclass.hie is included as an example HIERSVR document.

Every node in the hierarchy has a minimal set of attributes.

  • Description — Text consisting of up to 30 characters.

  • Shape — Style of rectangle that surrounds the text rectangle, rounded rectangle, or oval rectangle.

  • Item Key Link (optional) — Name used to refer to a linked item. If not specified, the item key link defaults to the description string. This name is visible when you view the link using the Edit Links command in the client application.

Creating a HIERSVR Diagram

A new HIERSVR diagram begins as a single node with the text "Root node." To add a node, first select its parent node by clicking it. Then click Add Node on the Edit menu. In the Add Node dialog box, specify the three attributes described above. To change the attributes of a node, select it with a mouse click, and then click Change Node. To move a node, click it and drag to the new location.

HIERSVR will import hierarchy information from a text file formatted as follows: The text in each line (delimited by a line feed) is the node's Description. The number of tab characters preceding the text determines the level of the node in the hierarchy. In the HIERSVR sample directory, Mfcclass.txt is the text import file for Mfcclass.hie, the native HIERSVR file.

To link a hierarchy diagram to a client document, you must first save the file in HIERSVR. Then select the node you want to copy using Edit Copy. This will copy the link to the Clipboard. The text of the selected node will also be copied to the Clipboard in the CF_TEXT format, and the entire hierarchy of nodes will be copied in a HIERSVR-native clipboard format. Saving the document is required because the link format requires a document name. Finally, in the client application, click Edit Paste Link (or click Paste Link on the Edit Paste Special menu). The link will be displayed in the client document as the node that you selected before clicking Edit Copy. The rectangle will also be displayed.

To embed a hierarchy diagram in a client document, you can either use a clipboard procedure similar to that above for linking the object, or click Insert New Object in the client application. If you choose the clipboard procedure, use Edit Paste rather than Edit Paste Link in the client application. Only the subhierarchy starting at the selected node will be embedded in the client document.

Whether you link or embed the diagram, only the top selected node will be displayed in the client application window. To see the rest of the diagram, you will need to launch HIERSVR from the client application by double-clicking the item.

Visual Editing Server

HIERSVR illustrates the class derivations necessary to implement a fully functional Visual Editing server application and illustrates some of the most common client application user interfaces that require additional code.

The three framework classes used to implement a Visual Editing server application are illustrated by the following.

  • A COleTemplateServer object, stored as member variable m_server in HIERSVR's application class.

  • The HIERSVR CServerDoc class, derived from COleServerDoc.

  • The HIERSVR CServerItem class, derived from COleServerItem.

  • The HIERSVR CInPlaceFrame class, derived from COleIPFrameWnd, originally created by the application wizard.

Keywords

This sample demonstrates the following keywords:

AfxGetMainWnd; AfxMessageBox; AfxOleInit; AfxThrowMemoryException; AfxThrowNotSupportedException; AfxThrowResourceException; CArchive::Close; CCmdTarget::BeginWaitCursor; CCmdTarget::EndWaitCursor; CCmdUI::Enable; CCmdUI::SetCheck; CControlBar::EnableDocking; CControlBar::GetBarStyle; CControlBar::SetBarStyle; CDC::GetDeviceCaps; CDC::LPtoDP; CDC::LPtoHIMETRIC; CDC::SelectObject; CDC::SetMapMode; CDC::SetViewportExt; CDC::SetWindowExt; CDialog::DoModal; CDialog::OnInitDialog; CDocTemplate::SetServerInfo; CDocument::DeleteContents; CDocument::GetFirstViewPosition; CDocument::GetNextView; CDocument::OnNewDocument; CDocument::SetModifiedFlag; CDocument::UpdateAllViews; CFile::Open; CFileDialog::DoModal; CFileDialog::GetPathName; CFontDialog::DoModal; CFontDialog::GetColor; CFrameWnd::Create; CFrameWnd::DockControlBar; CFrameWnd::EnableDocking; CFrameWnd::LoadFrame; CMenu::GetSubMenu; CMenu::LoadMenu; CMenu::TrackPopupMenu; CObList::AddHead; CObList::AddTail; CObList::GetCount; CObList::GetHeadPosition; CObList::GetNext; CObList::GetTail; CObList::RemoveAll; CObList::RemoveAt; CObject::AssertValid; CObject::Dump; CObject::Serialize; COleDataObject::AttachClipboard; COleDataObject::GetFileData; COleDataObject::IsDataAvailable; COleIPFrameWnd::OnCreateControlBars; COleLinkingDoc::OnGetLinkedItem; COleServerDoc::GetItemPosition; COleServerDoc::IsInPlaceActive; COleServerDoc::OnDeactivateUI; COleServerDoc::OnGetEmbeddedItem; COleServerDoc::OnSetItemRects; COleServerDoc::RequestPositionChange; COleServerDoc::UpdateAllItems; COleServerItem::CopyToClipboard; COleServerItem::DoDragDrop; COleServerItem::GetClipboardData; COleServerItem::GetDataSource; COleServerItem::GetDocument; COleServerItem::GetItemName; COleServerItem::IsLinkedItem; COleServerItem::OnDraw; COleServerItem::OnGetClipboardData; COleServerItem::OnGetExtent; COleServerItem::OnOpen; COleServerItem::OnRenderFileData; COleServerItem::SetItemName; COleTemplateServer::ConnectTemplate; COleTemplateServer::UpdateRegistry; CPen::CreatePen; CRect::BottomRight; CRect::Height; CRect::InflateRect; CRect::IntersectRect; CRect::OffsetRect; CRect::PtInRect; CRect::Size; CRect::TopLeft; CScrollView::GetDeviceScrollPosition; CScrollView::ScrollToPosition; CScrollView::SetScrollSizes; CString::Empty; CString::GetLength; CString::IsEmpty; CToolBar::Create; CToolBar::LoadBitmap; CToolBar::SetButtons; CView::GetDocument; CView::OnDragEnter; CView::OnDragLeave; CView::OnDragOver; CView::OnDraw; CView::OnDrop; CView::OnInitialUpdate; CView::OnPrepareDC; CView::OnUpdate; CWinApp::AddDocTemplate; CWinApp::EnableShellOpen; CWinApp::ExitInstance; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWinApp::RegisterShellFileTypes; CWnd::ClientToScreen; CWnd::DoDataExchange; CWnd::GetClientRect; CWnd::GetParentFrame; CWnd::Invalidate; CWnd::InvalidateRect; CWnd::OnCreate; CWnd::OnKeyDown; CWnd::OnLButtonDblClk; CWnd::OnLButtonDown; CWnd::OnRButtonDown; CWnd::OnSize; CWnd::SetOwner; CWnd::ShowWindow; CWnd::UpdateWindow; CreateFontIndirect; DragAcceptFiles; EnableWindow; ExtTextOut; GetDeviceCaps; GetSysColor; GetTextExtent; GetWindowTextLength; IsChild; LPtoDP; LineTo; LoadBitmap; MoveTo; MulDiv; RGB; RectVisible; Rectangle; RegisterClipboardFormat; RoundRect; SelectObject; SetTextColor; SetViewportExt; SetWindowExt; SetWindowOrg; _alloca; afxMemDF; lstrcpy; memset; min; strlen; wcstombs

NoteNote

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.

See Also

Other Resources

MFC Samples

Community Additions

ADD
Show:
© 2014 Microsoft