001 /**************************************************
002 以下代码由“老罗代码着色器”0.1版进行着色
003 测试文件名:NotePadDlg.cpp
004 测试日期: 2002-12-24
005 **************************************************/
006
007
008 // NotePadDlg.cpp : implementation file
009 //
010
011 #include "stdafx.h"
012 #include "NotePad.h"
013 #include "NotePadDlg.h"
014
015 #ifdef _DEBUG
016 #define new DEBUG_NEW
017 #undef THIS_FILE
018 static char THIS_FILE[] = __FILE__;
019 #endif
020
021 /////////////////////////////////////////////////////////////////////////////
022 // CAboutDlg dialog used for App About
023
024 class CAboutDlg : public CDialog
025 {
026 public:
027 CAboutDlg();
028
029 // Dialog Data
030 //{{AFX_DATA(CAboutDlg)
031 enum { IDD = IDD_ABOUTBOX };
032 //}}AFX_DATA
033
034 // ClassWizard generated virtual function overrides
035 //{{AFX_VIRTUAL(CAboutDlg)
036 protected:
037 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
038 //}}AFX_VIRTUAL
039
040 // Implementation
041 protected:
042 //{{AFX_MSG(CAboutDlg)
043 //}}AFX_MSG
044 DECLARE_MESSAGE_MAP()
045 };
046
047 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
048 {
049 //{{AFX_DATA_INIT(CAboutDlg)
050 //}}AFX_DATA_INIT
051 }
052
053 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
054 {
055 CDialog::DoDataExchange(pDX);
056 //{{AFX_DATA_MAP(CAboutDlg)
057 //}}AFX_DATA_MAP
058 }
059
060 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
061 //{{AFX_MSG_MAP(CAboutDlg)
062 // No message handlers
063 //}}AFX_MSG_MAP
064 END_MESSAGE_MAP()
065
066 /////////////////////////////////////////////////////////////////////////////
067 // CNotePadDlg dialog
068
069 CNotePadDlg::CNotePadDlg(CWnd* pParent /*=NULL*/)
070 : CDialog(CNotePadDlg::IDD, pParent)
071 {
072 //{{AFX_DATA_INIT(CNotePadDlg)
073 // NOTE: the ClassWizard will add member initialization here
074 //}}AFX_DATA_INIT
075 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
076 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
077 }
078
079 void CNotePadDlg::DoDataExchange(CDataExchange* pDX)
080 {
081 CDialog::DoDataExchange(pDX);
082 //{{AFX_DATA_MAP(CNotePadDlg)
083 // NOTE: the ClassWizard will add DDX and DDV calls here
084 //}}AFX_DATA_MAP
085 }
086
087 BEGIN_MESSAGE_MAP(CNotePadDlg, CDialog)
088 //{{AFX_MSG_MAP(CNotePadDlg)
089 ON_WM_SYSCOMMAND()
090 ON_WM_PAINT()
091 ON_WM_QUERYDRAGICON()
092 //}}AFX_MSG_MAP
093 END_MESSAGE_MAP()
094
095 /////////////////////////////////////////////////////////////////////////////
096 // CNotePadDlg message handlers
097
098 BOOL CNotePadDlg::OnInitDialog()
099 {
100 CDialog::OnInitDialog();
101
102 // Add "About..." menu item to system menu.
103
104 // IDM_ABOUTBOX must be in the system command range.
105 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
106 ASSERT(IDM_ABOUTBOX < 0xF000);
107
108 CMenu* pSysMenu = GetSystemMenu(FALSE);
109 if (pSysMenu != NULL)
110 {
111 CString strAboutMenu;
112 strAboutMenu.LoadString(IDS_ABOUTBOX);
113 if (!strAboutMenu.IsEmpty())
114 {
115 pSysMenu->AppendMenu(MF_SEPARATOR);
116 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
117 }
118 }
119
120 // Set the icon for this dialog. The framework does this automatically
121 // when the application's main window is not a dialog
122 SetIcon(m_hIcon, TRUE); // Set big icon
123 SetIcon(m_hIcon, FALSE); // Set small icon
124
125 // TODO: Add extra initialization here
126
127 return TRUE; // return TRUE unless you set the focus to a control
128 }
129
130 void CNotePadDlg::OnSysCommand(UINT nID, LPARAM lParam)
131 {
132 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
133 {
134 CAboutDlg dlgAbout;
135 dlgAbout.DoModal();
136 }
137 else
138 {
139 CDialog::OnSysCommand(nID, lParam);
140 }
141 }
142
143 // If you add a minimize button to your dialog, you will need the code below
144 // to draw the icon. For MFC applications using the document/view model,
145 // this is automatically done for you by the framework.
146
147 void CNotePadDlg::OnPaint()
148 {
149 if (IsIconic())
150 {
151 CPaintDC dc(this); // device context for painting
152
153 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
154
155 // Center icon in client rectangle
156 int cxIcon = GetSystemMetrics(SM_CXICON);
157 int cyIcon = GetSystemMetrics(SM_CYICON);
158 CRect rect;
159 GetClientRect(&rect);
160 int x = (rect.Width() - cxIcon + 1) / 2;
161 int y = (rect.Height() - cyIcon + 1) / 2;
162
163 // Draw the icon
164 dc.DrawIcon(x, y, m_hIcon);
165 }
166 else
167 {
168 CDialog::OnPaint();
169 }
170 }
171
172 // The system calls this to obtain the cursor to display while the user drags
173 // the minimized window.
174 HCURSOR CNotePadDlg::OnQueryDragIcon()
175 {
176 return (HCURSOR) m_hIcon;
177 }
178