您现在的位置: 中国教师站 >> 教师关注 >> 电脑技术 >> 编程技术 >> Visual C >> 正文

Google
The MyWord Application
作者:Siny 文章来源:中国教师站cn-teacher 点击数: 更新时间:2007-4-22 13:05:33

Putting It All Together: The MyWord Application

The sample program shown in Figure 12-8 demonstrates many of the principles discussed in the preceding sections. MyWord is a miniature word processor built around a CRichEditView. MFC's CRichEditView class is like a CEditView on steroids; based on the rich text edit control supplied in the common controls library, it features superior text formatting capabilities and the ability to read and write rich text format (RTF) files with a simple function call. MyWord doesn't use all the features of a CRichEditView; in fact, it barely scratches the surface. (For a more in-depth look at CRichEditView, see the Wordpad sample program provided with MFC. The Wordpad files are the actual source code for the Wordpad applet that ships with Windows.) But MyWord packs a lot of punch for a program that's only a few hundred lines long, and it's a good starting point for writing CRichEditView-based applications of your own.

Figure 12-8. The MyWord window.

MyWord uses two toolbars and one status bar. The main toolbar includes buttons that serve as shortcuts for the New, Open, and Save items in the File menu and the Cut, Copy, Paste, and Undo items in the Edit menu. The other toolbar, which I'll refer to as the style bar, includes check push buttons for setting the character format (bold, italic, and underline), radio push buttons for setting the paragraph alignment (left aligned, centered, and right aligned), and combo boxes for selecting typefaces and font sizes. Both toolbars can be detached from the frame window, floated, and docked at other locations; and both can be resized while they're floating. Try it: Drag the main toolbar to the right side of the window, and dock it in a vertical position. Grab the style bar and release it in the center of the window so that it becomes a floating palette. Use the View menu to hide and display the toolbars and the status bar. You can also hide a toolbar by clicking the close button in the mini frame window it floats in when it's detached from the main frame window. To redisplay the toolbar, simply select the Toolbar or Style Bar command in the View menu.

The status bar at the bottom of MyWord's frame window displays help text for menu items and toolbar controls. It also includes Caps Lock and Num Lock indicators and a line number display that's continually updated as the caret moves through the document. The Caps Lock and Num Lock indicators were added using MFC's predefined ID_INDICATOR_CAPS and ID_INDICATOR_NUM IDs. The line number indicator is updated by an ON_UPDATE_COMMAND_UI handler that, when called, retrieves the current line number from the CRichEditView, formulates a text string containing the line number, and updates the status bar display with CCmdUI::SetText. The line number pane is sized to fit the dummy string "Line 00000," whose resource ID, ID_INDICATOR_LINE, is identical to the status bar pane's ID. The dummy string is never seen because the pane is updated with a real line number before the status bar appears on the screen.

I used AppWizard to begin MyWord. I checked the Docking Toolbar and Initial Status Bar options in AppWizard's Step 4 dialog box, and in Step 6, I selected CRichEditView as the base class for the view. I next derived a class named CStyleBar to represent the s

[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ... 下一页  >> 

  • 上一篇文章:

  • 下一篇文章:
  • 相关专题:
     
     网友评论:(评论内容只代表网友观点,与本站立场无关!)
    GOOGLE广告

    阅读排行

    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 |
    中国教师站

    中国教师站 版权所有 Copyright © 2006-2020 All Rights Reserved 站长:Sina & Siny
    [备用域名:www.JXZYW.Com] 有事请留言有事请留言
    【实力成就精品 诚信呵护品牌】

    信息产业部备案
    苏ICP备06018635号