SUPERPAD Sample: Demonstrates a Visual Editing Server That Edits Text Using CEditView
The SUPERPAD sample illustrates how to use the CEditView class in conjunction with Visual Editing server support.
Security Note |
---|
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties. |
To get samples and instructions for installing them:
To access samples from Visual Studio
On the Help menu, click Samples.
By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.
- For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.
Building and Running the Sample
To build and run the SUPERPAD sample
Open the solution superpad.sln.
On the Build menu, click Build.
To use SUPERPAD as a Visual Editing server, run it once as a stand-alone application so it can register itself with the system.
When you first run SUPERPAD, it displays a splash window that looks like an About dialog box. This dialog box stays on the screen briefly and then vanishes after a time-out. To close the splash window, press any key or click the mouse.
SUPERPAD remembers its window position from the last time you ran it. It also remembers whether the document window was maximized in the MDI frame window.
Additional SUPERPAD Features
SUPERPAD illustrates advanced uses of CEditView through class derivation, including toggling the word wrap state of the edit control and changing the screen and printer font. SUPERPAD also illustrates a wide variety of MFC programming techniques.
About dialog box showing system resource usage.
Splash window that is displayed when the application first starts.
Persistent window placement by storing window position information in a private .ini file.
Idle loop processing.
Using a wait cursor.
Subclassing a window.
Adding page headers and footers during printing.
Page breaking during printing.
Starting print preview at the current selection in the document.
Returning from print preview to the same position in the document as last previewed.
Standard font dialog box (CFontDialog).
SUPERPAD Menus
The File menu offers standard commands — New, Open, Close, Save, Save As, Print, Print Preview, Print Setup, the most recently used (MRU) file list, and Exit.
The File menu also offers a Page Setup option you can use to specify a per-page header and/or footer. Leave the header or footer blank if you want none. You can specify any text in the header and footer. You can also specify any of the following formatting codes.
&f for the file name.
&p for the page number.
Any of the formatting codes defined for the C run-time strftime function. For example, %a for the abbreviated weekday name, %B for the full month name, %d for the day of the month, and %Y for the year with century can be specified. These formatting options are not available if you link SUPERPAD to the DLL version of MFC because strftime is not available in a DLL.
SUPERPAD offers the following Edit menu commands, which are handled by default by CEditView: Cut, Copy, Page, Delete, Find. Find Next, Replace, Select All, and Undo. The Edit menu also offers a WordWrap command to turn word wrapping on or off.
The View menu offers the following commands, which exercise various features of CEditView:
Set Tab Stops — enter a single integer in the dialog box for equally spaced tab stops.
Set Font — specify the font to be used when displaying the file on the screen.
Set Printer Font — specify the font to be used when printing.
Mirror Display Font — turn this toggle state on if you want to temporarily deselect the currently specified printer font and instead use a printer font that most closely matches the screen font.
SUPERPAD Classes
SUPERPAD derives its view class CPadView from CEditView. CPadView accesses the attributes and operations of CEditView to add to the functionality of CEditView, as described here.
CPadView calls CEditView::SetFont and SetPrinterFont to initialize and change the screen and printer fonts.
To implement the Edit Word Wrap command, CPadView toggles the state of word wrapping by creating a new edit control (whose WNDCLASS is the standard Windows edit control). It toggles the ES_AUTOHSCROLL and WS_HSCROLL styles of the control, which together determine whether an edit control does word wrapping. CPadView saves the buffer of the old edit control and moves it into the new edit control. Finally, it destroys the old edit control and then associates the hWnd of the new edit control with the CPadView class by calling CWnd::SubclassWindow.
CPadView overrides OnPrint to add page headers and footers. It overrides OnBeginPrinting to set the current time, which is optionally displayed in the header, in the footer, or in both. It starts print preview at the current selection in the edit control.
CPadView overrides CView::OnScrollTo to scroll the view to the same position as last viewed during print preview.
Keywords
This sample demonstrates the following keywords:
AfxGetApp; AfxGetInstanceHandle; AfxMessageBox; AfxOleInit; CArchive::Flush; CArchive::GetFile; CArchive::IsStoring; CBitmap::CreateCompatibleBitmap; CButton::DrawItem; CCmdUI::SetCheck; CDC::Attach; CDC::CreateCompatibleDC; CDC::Detach; CDC::DrawIcon; CDC::FillRect; CDC::GetDeviceCaps; CDC::GetTextMetrics; CDC::IntersectClipRect; CDC::LPtoHIMETRIC; CDC::LineTo; CDC::MoveTo; CDC::Rectangle; CDC::RestoreDC; CDC::SaveDC; CDC::SelectObject; CDC::SetBkMode; CDC::SetWindowExt; CDC::SetWindowOrg; CDC::StretchBlt; CDC::TextOut; CDialog::Create; CDialog::DoModal; CDialog::OnInitDialog; CDocTemplate::SetServerInfo; CDocument::DeleteContents; CDocument::GetFirstViewPosition; CDocument::GetNextView; CEditView::GetEditCtrl; CEditView::GetPrinterFont; CEditView::PrintInsideRect; CEditView::SerializeRaw; CEditView::SetPrinterFont; CEditView::SetTabStops; CEditView::dwStyleDefault; CFile::Write; CFont::CreateFontIndirect; CFontDialog::DoModal; CFrameWnd::ActivateFrame; CFrameWnd::Create; CFrameWnd::LoadFrame; CGdiObject::CreateStockObject; CGdiObject::DeleteObject; CGdiObject::GetObject; CObject::AssertValid; CObject::Dump; CObject::IsKindOf; CObject::Serialize; COleIPFrameWnd::OnCreateControlBars; COleLinkingDoc::OnGetLinkedItem; COleResizeBar::Create; COleServerDoc::IsInPlaceActive; COleServerDoc::OnDeactivateUI; COleServerDoc::OnGetEmbeddedItem; COleServerDoc::UpdateAllItems; COleServerItem::CopyToClipboard; COleServerItem::GetDataSource; COleServerItem::GetDocument; COleServerItem::OnDraw; COleServerItem::OnGetExtent; COleServerItem::OnRenderFileData; COleServerItem::OnShow; COleServerItem::SetItemName; COleTemplateServer::ConnectTemplate; COleTemplateServer::UpdateRegistry; CPrintDialog::CreatePrinterDC; CPrintInfo::SetMaxPage; CRect::Height; CRect::InflateRect; CRect::IsRectEmpty; CRect::SetRect; CRect::Size; CRect::Width; CStatusBar::Create; CStatusBar::SetIndicators; CString::Find; CString::GetBuffer; CString::GetLength; CString::IsEmpty; CString::Left; CString::LoadString; CString::Mid; CString::ReleaseBuffer; CTime::Format; CToolBar::Create; CToolBar::LoadBitmap; CToolBar::SetButtons; CView::GetDocument; CView::OnBeginPrinting; CView::OnPrepareDC; CView::OnPrint; CWinApp::AddDocTemplate; CWinApp::EnableShellOpen; CWinApp::ExitInstance; CWinApp::GetProfileInt; CWinApp::GetProfileString; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWinApp::OnIdle; CWinApp::PreTranslateMessage; CWinApp::RegisterShellFileTypes; CWinApp::WriteProfileInt; CWinApp::WriteProfileString; CWnd::BringWindowToTop; CWnd::CenterWindow; CWnd::DestroyWindow; CWnd::Detach; CWnd::DoDataExchange; CWnd::FromHandle; CWnd::GetClientRect; CWnd::GetDC; CWnd::GetDlgCtrlID; CWnd::GetFocus; CWnd::GetFont; CWnd::GetParent; CWnd::GetParentFrame; CWnd::GetStyle; CWnd::GetSuperWndProcAddr; CWnd::GetWindowPlacement; CWnd::GetWindowRect; CWnd::GetWindowText; CWnd::GetWindowTextLength; CWnd::IsZoomed; CWnd::KillTimer; CWnd::OnClose; CWnd::OnCreate; CWnd::OnEraseBkgnd; CWnd::OnRButtonDown; CWnd::OnSize; CWnd::OnTimer; CWnd::PreCreateWindow; CWnd::ReleaseDC; CWnd::ScreenToClient; CWnd::SendMessage; CWnd::SetDlgCtrlID; CWnd::SetDlgItemText; CWnd::SetFocus; CWnd::SetFont; CWnd::SetOwner; CWnd::SetTimer; CWnd::SetWindowPlacement; CWnd::SetWindowPos; CWnd::SetWindowText; CWnd::ShowWindow; CWnd::SubclassDlgItem; CWnd::SubclassWindow; CWnd::UpdateWindow; CreateWindow; DragAcceptFiles; GetCurrentTime; GetObject; GetProfileInt; GetProfileString; GetStockObject; GetSystemMetrics; GlobalMemoryStatus; IsIconic; IsWindowVisible; LOWORD; LoadIcon; MulDiv; SetWindowLong; SetWindowPos; UpdateWindow; WideCharToMultiByte; WriteProfileString; _alloca; _getdrive; lstrcpyn; lstrlen; min; wcstombs; wsprintf
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.