Using HTML Documents

You should consider using HTML documents instead of other formats for read-only text in your program. For example, the new help system used by Windows 98 is all HTML-based, as is the new Microsoft Developer Network (MSDN) Library. Using HTML allows you to provide rich text with graphics and tables easily.

Consider using HTML to display textual information in your program, such as text, tables, and reports. This is true even if the information is fairly simple and looks nothing like a typical Web page. For example, consider text as ordinary as that in the Build tab of the Output window in Microsoft Visual C++.

click to view at full size.

How could you implement this window in MFC? The first possible approach is to create a window derived from CScrollView. While the scroll view allows you to display and scroll text with little effort, you have to implement any additional functionality yourself. For example, you would need to write code to be able to select text, copy text to the clipboard, or print text. You would also have to write code to allow the user to double-click on an error message to see the corresponding source code. Alternatively, you could derive from CEditView, but this approach also has drawbacks. In an edit view, you can use only a single font and the view can contain a limited amount of text. (There is a 64 KB limit in Windows 98.) You would also have to handle double-click messages and convert the clicked window locations to error message line offsets to show the source code. Furthermore, the text is editable by default, so you have to make it read-only, which has the side effect of making the background gray. You then have to change the background color.

Assuming you know how to tag text in HTML (which is very easy), the simplest way to implement this window in MFC is with CHTMLView. Not only will an HTML window display and scroll the text without any size limitations, but this approach gives the user the ability to select, copy, and print text. You can embed hyperlinks to allow the user to jump from error messages to source code. HTML makes this connection visible, whereas the original does not, so the user doesn't have to know to double-click the error messages to see the source code. Furthermore, if your requirements change and you want to make the text look better by using different fonts or perhaps tables, all you have to do is add a few HTML tags and you are finished. Of course, you could also add the ability to export HTML files with almost no effort, allowing the user to view rich text on practically any platform. HTML documents are easy to create and very flexible.

click to view at full size.

The key points I want to make are that HTML documents allow you to create better text user interfaces even if the document looks nothing like a Web page and often requires less effort than the alternatives. Of course, if you want rich content, HTML documents are the best way to go.

TIP
Consider using HTML documents even if the document looks nothing like a Web page. They are flexible, powerful, and easy to program.



Developing User Interfaces for Microsoft Windows
Developing User Interfaces for Microsoft Windows
ISBN: 0735605866
EAN: 2147483647
Year: 2005
Pages: 334

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net