按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
#0046
#0047 // App mand to run the dialog
#0048 void CScribbleApp::OnAppAbout()
#0049 {
#0050 CAboutDlg aboutDlg;
#0051 aboutDlg。DoModal();
#0052 }
CAboutDlg 虽然衍生自CDialog,但太简陋,不符合我们新增的这个【Pen Width】对话
框所需,所以我们首先必须另为【Pen Width】对话框产生一个类别,以负责其行径。步
骤如下:
接续刚才完成对话框模板的动作,选按整合环境的【View/ClassWizard 】命令项
(或是直接在对话框模板上快按两下),进入ClassWizard 。这时候【Adding a
Class 】对话框会出现,并以刚才的IDD_PEN_ WIDTHS 为新资源,这是因为
ClassWizard 知道你已在对话框编辑器中设计了一个对话框模板,却还未设计
其对应类别(整合环境就是这么便利)。好,按下【OK 】。
608
…………………………………………………………Page 671……………………………………………………………
10 MFC
第 章 與對話盒
在【Create New Class 】对话框中设计新类别。键入〃CPenWidthsDlg〃 做为类别
名称。请注意类别的基础类型为CDialog,因为ClassWizard 知道目前是由对
话盒编辑器过来:
ClassWizard 把类别名称再加上。cpp 和。h,作为预设档名。毫无问题,因为
Windows 95 和Windows NT 都支持长档名。如果你不喜欢,按下上图右侧的
【Change 】钮去改它。本例改用PENDLG。CPP 和PENDLG。H 两个档名。
按下上图的【OK 】钮,于是类别产生,回到ClassWizard 画面。
这样,我们就进账了两个新文件:
609
…………………………………………………………Page 672……………………………………………………………
第篇 深入 MFC 程式設計
PENDLG。H
#0001 // PenDlg。h : header file
#0002 //
#0003
#0004 /////////////////////////////////////////////////////////////////
#0005 // CPenWidthsDlg dialog
#0006
#0007 class CPenWidthsDlg : public CDialog
#0008 {
#0009 // Construction
#0010 public:
#0011 CPenWidthsDlg(CWnd* pParent = NULL); // standard constructor
#0012
#0013 // Dialog Data
#0014 //{{AFX_DATA(CPenWidthsDlg)
#0015 enum { IDD = IDD_PEN_WIDTHS };
#0016 // NOTE: the ClassWizard will add data members here
#0017 //}}AFX_DATA
#0018
#0019
#0020 // Overrides
#0021 // ClassWizard generated virtual function overrides
#0022 //{{AFX_VIRTUAL(CPenWidthsDlg)
#0023 protected:
#0024 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV suppo
#0025 //}}AFX_VIRTUAL
#0026
#0027 // Implementation
#0028 protected:
#0029
#0030 // Generated message map functions
#0031 //{{AFX_MSG(CPenWidthsDlg)
#0032 afx_msg void OnDefaultPenWidths();
#0033 //}}AFX_MSG
#0034 DECLARE_MESSAGE_MAP()
#0035 };
PENDLG。CPP
#0001 // PenDlg。cpp : implementation file
#0002 //
#0003
#0004 #include 〃stdafx。h〃
#0005 #include 〃Scribble。h〃
610
…………………………………………………………Page 673……………………………………………………………
10 MFC
第 章 與對話盒
#0006 #include 〃PenDlg。h〃
#0007
#0008 #ifdef _DEBUG
#0009 #define new DEBUG_NEW
#0010 #undef THIS_FILE
#0011 static char THIS_FILE'' = __FILE__;
#0012 #endif
#0013
#0014 /////////////////////////////////////////////////////////////
#0015 // CPenWidthsDlg dialog
#0016
#0017
#0018 CPenWidthsDlg::CPenWidthsDlg(CWnd* pParent /*=NULL*/)
#0019 : CDialog(CPenWidthsDlg::IDD; pParent)
#0020 {
#0021 //{{AFX_DATA_INIT(CPenWidthsDlg)
#0022 // NOTE: the ClassWizard will add member initialization here
#0023 //}}AFX_DATA_INIT
#0024 }
#0025
#0026
#0027 void CPenWidthsDlg::DoDataExchange(CDataExchange* pDX)
#0028 {
#0029 CDialog::DoDataExchange(pDX);
#0030 //{{AFX_DATA_MAP(CPenWidthsDlg)
#0031 // NOTE: the ClassWizard will add DDX and DDV calls here
#0032 //}}AFX_DATA_MAP
#0033 }
#0034
#0035
#0036 BEGIN_MESSAGE_MAP(CPenWidthsDlg; CDialog)
#0037 //{{AFX_MSG_MAP(CPenWidthsDlg)
#0038 ON_BN_CLICKED(IDC_DEFAULT_PEN_WIDTHS; OnDefaultPenWidths)
#0039 //}}AFX_MSG_MAP
#0040 END_MESSAGE_MAP()
#0041
#0042 ///////////////////////////////////////////////////////////////
#0043 // CPenWidthsDlg message handlers
#0044
#0045 void CPenWidthsDlg::OnDefaultPenWidths()
#0046 {
#0047 // TODO: Add your control notification handler code here
#0048
#0049 }
611
…………………………………………………………Page 674……………………………………………………………
第篇 深入 MFC 程式設計
稍早我