|
Using the MyApp HTML View Automation ClassesEric Hartwell - January 2000 Microsoft's CHtmlView class provides the functionality of the WebBrowser control within the context of MFC's document/view architecture. The WebBrowser control is a window in which the user can browse sites on the World Wide Web, as well as folders in the local file system and on a network. This effectively makes the application a web browser. The functionality of CHtmlView is designed for applications that access the Web (and/or HTML documents). For HTML-based applications, however, we need a tighter integration between the view class and the actual application. For example,
This article explains how this is implemented for MyApp.
CHtmlView2 ClassCHtmlView2 was originally developed for displaying HTML screens in MyApp. Basically, this class adds the NavigateText method, which lets you specify the screen as an HTML characters string instead of a URL (see Tech Note: Setting HTML View Text Directly From a String). void CHtmlView2::NavigateText(const char *pszHtmlText) If the browser has already navigated to a page, the HTML is loaded directly. However, if it hasn't, the method caches the text, navigates to the internal page "about:blank" to initialize the document object, then loads the HTML.
CMyAppHtmlView ClassCMyAppHtmlView was developed for displaying HTML screens in MyApp. It builds on the CHtmlView2 foundation to add event sourcing and sinking (see Q181845), printing (see Q156732), and the ability to execute a script within the browser (see Exoware Tech Note: Issuing Commands to the HTML View). Printing support is simply a matter of sending a print command to the browser control. (It's actually more complicated in BenWin32, since the user may choose to print a screen that isn't currently displayed). void CMyAppHtmlView::OnPrint(CDC* pDC, CPrintInfo* pInfo) { // Let the HTML control print the current screen ExecWB(pInfo->m_bPreview ? OLECMDID_PRINTPREVIEW : OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL); }
CMyAppStudioHtmlDoc/View Implementation
Using CMyAppHtmlDoc/ViewThe CMyAppHtmlDoc and CMyAppHtmlView classes forma a base class for HTML document/view pairs that are aware of MyApp plan information. The next step is to derive classes for particular document/view types. CMyAppRuleDoc/ViewMyApp Rule screens are essentially data entry screens for the plan database. Each rule has a collection of values (the script variables), and a template which specifies how the values are to be displayed and edited. In addition, each rule has a Validate() method which validates its values according to internal program logic. Rules are displayed as form views, list views, or both (one or more lists embedded within a form). CMyAppScreenDoc/ViewMyApp "screens" are what the user sees. In MyApp, the screens are normally shown in Rule mode, with the literals and fields fixed and the only the values (script variables) changeable. However, the screens can also be switched to Edit mode, where the literals and fields themselves may be modified. (Later enhancement: The screens can also be shown in "Preview" mode, where the contents of the fields are replaced with actual data.) References:
Resources:MSDN, Microsoft Knowledge Base, Site Builder Workshop, Platform SDK, etc. Revisions:
|
|