深入浅出MFC第2版(PDF格式)-第73部分
按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
#0007
#0008 MainMenu MENU DISCARDABLE
#0009 {
#0010 POPUP 〃&Help〃
#0011 {
#0012 MENUITEM 〃&About HelloMFC。。。〃; IDM_ABOUT
#0013 }
#0014 }
#0015
#0016 AboutBox DIALOG DISCARDABLE 34; 22; 147; 55
#0017 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
#0018 CAPTION 〃About Hello〃
#0019 {
#0020 ICON 〃JJHouRIcon〃;IDC_STATIC;11;17;18;20
#0021 LTEXT 〃Hello MFC 4。0〃;IDC_STATIC;40;10;52;8
#0022 LTEXT 〃Copyright 1996 Top Studio〃;IDC_STATIC;40;25;100;8
#0023 LTEXT 〃J。J。Hou〃;IDC_STATIC;40;40;100;8
#0024 DEFPUSHBUTTON 〃OK〃;IDOK;105;7;32;14;WS_GROUP
#0025 }
STDAFX。H
#0001 // stdafx。h : include file for standard system include files;
#0002 // or project specific include files that are used frequently;
#0003 // but are changed infrequently
#0004
#0005 #include // MFC core and standard ponents
354
…………………………………………………………Page 417……………………………………………………………
第6章 MFC 程式的生死因果
STDAFX。CPP
#0001 // stdafx。cpp : source file that includes just the standard includes
#0002 // Hello。pch will be the pre…piled header
#0003 // stdafx。obj will contain the pre…piled type information
#0004
#0005 #include 〃stdafx。h〃
HELLO。H
#0001 //……………………………………………………………………………………………………………………………………………………………………
#0002 // MFC 4。0 Hello Sample Program
#0003 // Copyright (c) 1996 Top Studio * J。J。Hou
#0004 // 档名 : hello。h
#0005 //
作者 : 侯俊杰
#0006 //
#0007 // 编译联结 : 请参考hello。mak
#0008 //
#0009 // 声明Hello 程序的两个类别 : CMyWinApp 和CMyFrameWnd
#0010 //……………………………………………………………………………………………………………………………………………………………………
#0011
#0012 class CMyWinApp : public CWinApp
#0013 {
#0014 public:
#0015 BOOL InitInstance(); //
每一个应用程序都应该改写此函数
#0016 };
#0017
#0018 //……………………………………………………………………………………………………………………………………………………………………
#0019 class CMyFrameWnd : public CFrameWnd
#0020 {
#0021 public:
#0022 CMyFrameWnd(); // constructor
#0023 afx_msg void OnPaint(); // for WM_PAINT
#0024 afx_msg void OnAbout(); // for WM_MAND (IDM_ABOUT)
#0025
#0026 private:
#0027 DECLARE_MESSAGE_MAP() // Declare Message Map
#0028 static VOID CALLBACK LineDDACallback(int;int;LPARAM);
注意 : callback 函数必须是〃static〃,才能去除隐藏的'this' 指针。
#0029 //
#0030 };
355
…………………………………………………………Page 418……………………………………………………………
第篇 湷觥 FC 程式設計
HELLO。CPP
#0001 //……………………………………………………………………………………………………………………………………………………………………
#0002 // MFC 4。0 Hello sample program
#0003 // Copyright (c) 1996 Top Studio * J。J。Hou
#0004 // 档名 : hello。cpp
#0005 //
作者 : 侯俊杰
#0006 //
#0007 // 编译联结 : 请参考hello。mak
#0008 //
#0009 // 本例示范最简单之MFC 应用程序,不含Document/View 架构。程序每收到
#0010 // WM_PAINT 即利用GDI 函数LineDDA() 让〃Hello; MFC〃 字符串从天而降。
#0011 //……………………………………………………………………………………………………………………………………………………………………
#0012 #include 〃Stdafx。h〃
#0013 #include 〃Hello。h〃
#0014 #include 〃Resource。h〃
#0015
#0016 CMyWinApp theApp; // application object
#0017
#0018 //……………………………………………………………………………………………………………………………………………………………………
#0019 // CMyWinApp's member
#0020 //……………………………………………………………………………………………………………………………………………………………………
#0021 BOOL CMyWinApp::InitInstance()
#0022 {
#0023 m_pMainWnd = new CMyFrameWnd();
#0024 m_pMainWnd…》ShowWindow(m_nCmdShow);
#0025 m_pMainWnd…》UpdateWindow();
#0026 return TRUE;
#0027 }
#0028 //……………………………………………………………………………………………………………………………………………………………………
#0029 // CMyFrameWnd's member
#0030 //……………………………………………………………………………………………………………………………………………………………………
#0031 CMyFrameWnd::CMyFrameWnd()
#0032 {
#0033 Create(NULL; 〃Hello MFC〃; WS_OVERLAPPEDWINDOW; rectDefault;
#0034 NULL; 〃MainMenu〃); // 〃MainMenu〃 定义于 RC 档
#0035 }
#0036 //……………………………………………………………………………………………………………………………………………………………………
#0037 BEGIN_MESSAGE_MAP(CMyFrameWnd; CFrameWnd)
#0038 ON_MAND(IDM_ABOUT; OnAbout)
#0039 ON_WM_PAINT()
#0040 END_MESSAGE_MAP()
#0041 //……………………………………………………………………………………………………………………………………………………………………
#0042 void CMyFrameWnd::OnPaint()
#0043 {
#0044 CPaintDC dc(this);
356
…………………………………………………………Page 419……………………………………………………………
第6章 MFC 程式的生死因果
#0045 CRect rect;
#0046
#0047 GetClientRect(rect);
#0048
#0049 dc。SetTextAlign(TA_BOTTOM | TA_CENTER);
#0050
#0051 ::LineDDA(rect。right/2; 0; rect。right/2; rect。bottom/2;
#0052 (LINEDDAPROC) LineDDACallback; (LPARAM) (LPVOID) &dc);
#0053 }
#0054 //……………………………………………………………………………………………………………………………………………………………………
#0055 VOID CALLBACK CMyFrameWnd::LineDDACallback(int x; int y; LPARAM lpdc)
#0056 {
#0057 static char szText'' = 〃Hello; MFC〃;
#0058
#0059 ((CDC*)lpdc)…》TextOut(x; y; szText; sizeof(szText)…1);
#0060 for(int i=1; i