Tải bản đầy đủ (.doc) (33 trang)

Lập trình C trên Win doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (248.88 KB, 33 trang )

Lập trình C trên Win
L p trình C trênậ
Win
Trang 1
Lập trình C trên Win
Ùng duùng Single Document:
Vớ duù taùo moọt ửựng duùng teõn vidu1 kieồu single document baống trỡnh
AppWizard. Trỡnh AppWizard seừ taùo ra caực lụựp ủoỏi tửụùng daón xuaỏt tửứ caực
lụựp ủoỏi tửụùng cụ sụỷ Application classes, Document classes, ViewClasses vaứ
Frames classes
Vớ duù:
Lụựp cụ sụỷ Lụựp daón xuaỏt Teõn taọp tin Ghi
chuự
CWinApp Cvd1App Vd1.cpp
CDocument Cvd1Doc Vidu1Doc.cpp
CView Cvd1View Vidu1View.cpp
CFrameWnd CmainFrame MainFrm.cpp
CMDIChildWnd CchildFrame ChildFrm.cpp
 Taọp tin RESOURCE.H
Taọp tin naứy chửựa toaứn boọ nhửừng leọnh #define duứng ủũnh nghúa chổ
danh ID nhửừng taứi nguyeõn nhử laứ:
DD_ABOUTBOX: ẹoỏi vụựi taứi nguyeõn laứ moọt hoọp hoọi thoaùi about box
IDR_MAINFRAME: ẹoỏi vụựi vieọc chia seỷ sửỷ duùng bụỷi nhieàu loaùi taứi
nguyeõn.
IDR_VIDU1TYPE : ẹoỏi vụựi taứi nguyeõn laứ bieồu tửụùng taứi lieọu
Coứn caực haống _APS_3D_xxxx vaứ _APS_NEXT_xxxx khaực khoõng trửùc
tieỏp ủửụùc sửỷ duùng bụỷi caực taọp tin taứi nguyeõn khaực. Taọp tin naứy seừ ủửụùc
sửỷ duùng bụỷi taọp tin Vidu1.RC.
Noọi dung taọp tin RESOURCE.RC
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.


Trang 2
Lập trình C trên Win
// Used by VIDU1.RC
#define IDD_ABOUTBOX 100
#define IDR_MAINFRAME 128
#define IDR_VIDU1TYPE 129
// Next default values for new objects
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 32771
#endif
#endif
 Taọp tin Vidu1.H
Taọp tin tiẽu ủề Vidu1.H chửựa caực khai baựo liẽn quan ủeỏn lụựp
Cvidu1App laứ lụựp ửựng dúng Cvidu1. Cvidu1App laứ theồ hieọn (instance) chửụng
trỡnh ửựng dúng Vidu1. Lụựp naứy ủửụùc dn xuaỏt tửứ lụựp CwinApp
Class Cvidu1App : public CwinApp {
CwinAppp ( Class Windows Application) theo sụ ủồ dửựụi ủãy:
CObject
CCmdTarget
CWinThread
CWinApp
laứ haọu dueọ cuỷa lụựp CCmdTarget lo vieọc quaỷn lyự nhửừng cõng vieọc
ủửụùc ủoứi hoỷi ủeồ khụỷi ủoọng ửựng dúng cuừng nhử ủeồ cho cháy vaứ keỏt
thuực ửựng dúng MFC. Nhử sụ ủồ trẽn CWinApp ủửụùc dn xuaỏt tửứ moọt
chui lụựp CWinThread, CcmdTarget vaứ CObject. Trong vớ dú Cvidu1App laứ

giao dieọn vụựi Windows. Khi moọt tỡnh huoỏng xaỷy ra trong Windows thỡ thõng
ủieọp seừ gụỷi ủeỏn chửụng trỡnh Cvidu1App ủeồ cho noự bieỏt ủửụùc caựi gỡ xaỷy
ra. Vớ dú neỏu moọt phớm ủửụùc nhaỏn, thỡ thõng ủieọp WM_KEYDOWN seừ
ủửụùc phaựt ra vaứ chuyeồn cho Cvidu1App vaứ ủeỏn phiẽn chửụng trỡnh seừ khụỷi
ủoọng haứm giaỷi quyeỏt vaỏn ủề naứy laứ OnKeyDown().
// Vidu1.h : main header file for the VIDU1 application
#if!
defined(AFX_VIDU1_H__B682FE11_E54B_4D80_A49B_3C3AEAE1FF85_
_INCLUDED_)
#defineAFX_VIDU1_H__B682FE11_E54B_4D80_A49B_3C3AEAE1FF85__
INCLUDED_
#if _MSC_VER > 1000
#pragma once
Trang 3
Lập trình C trên Win
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif #include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CVidu1App:
// See Vidu1.cpp for the implementation of this class
// class CVidu1App : public CWinApp
{
public:
CVidu1App();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CVidu1App)
public:

virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CVidu1App)
afx_msg void OnAppAbout();
// NOTE - the ClassWizard will add and remove member
functions here.
// DO NOT EDIT what you see in these blocks of generated
code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before
the previous line.
#endif // !
defined(AFX_VIDU1_H__B682FE11_E54B_4D80_A49B_3C3AEAE1FF85_
_INCLUDED_)
Trong lụựp ủoỏi tửụùng coự khai baựo caực haứm constructor CVidu1App(),
haứm thaứnh vieõn bũ phuỷ quyeỏt InitInstance() vaứ OnAppAbout(). Vieọc ủũnh
nghúa ủửụùc thửùc hieọn trong taọp tin Vidu1.cpp.
AppWizard cho haứm OnAppAbout() naốm giửừa caởp chuự giaỷi ủaởc bieọt:
//{{AFX_MSG(Cvidu1App)
Afx_msg void OnAppAbout();
//}}AFX_MSG
Duứng ủeồ keỏt sinh ra baỷng ủaựp ửựng thoõng ủieọp. AFX_MSG duứng ủeồ ủaựnh
daỏu khụỷi ủaàu vaứ keỏt thuực nhửừng muùc vaứo lieõn quan ủeỏn message map.
Trang 4
Lập trình C trên Win

Muùc vaứo naứy bao giụứ cuừng baột ủaàu bụỷi afx_msg void theo sau laứ teõn haứm
giaỷi quyeỏt thoõng ủieọp bao giụứ cuừng baột ủaàu bụỷi On.
Caởp chuự giaỷi {{AFX_MSG … }}AFX_MSG seừ tửụng ửựng vụựi caởp
chuự giaỷi {{AFX_MSG_MAP …. }} AFX_MSG_MAP trong taọp tin Vidu1.cpp
Haứm chuự giaỷi maứ ClassWizard sửỷ duùng ủeồ phuỷ quyeỏt haứm virtual
nhử InitIntance() seừ sửỷ duùng macro AFX_VIRTUAL nhử sau:
//{{AFX_VIRTUAL(CVidu1App)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
AFX_VIRTUAL duứng ủaựnh daỏu khụỷi ủaàu vaứ keỏt thuực nhửừng khai
baựo cuỷa caực haứm virtual maứ ClassWizard seừ phuỷ quyeỏt trong taọp tin .H cuỷa
lụựp.
Cuoỏi cuứng taọp tin khai baựo lụựp naứy laứ doứng macro
DECLARE_MESSAGE_MAP() baựo cho bieỏt laứ treõn taọp tin .CPP seừ coự phaàn
ủũnh nghúa moọt “baỷn ủoà thoõng ủieọp” (message map) lieõn quan ủeỏn caực haứm
giaỷi quyeỏt thoõng ủieọp baột ủaàu bụỷi macro BEGIN_MESSAGE_MAP vaứ keỏt
thuực bụỷi macro END_MESSAGE_MAP nhử sau:
BEGIN_MESSAGE_MAP(CVidu1App, CWinApp)
//{{AFX_MSG_MAP(CVidu1App)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP,
CWinApp::OnFilePrintSetup)

END_MESSAGE_MAP()
 Taọp tin STDAFX.H
Taọp tin STDAFX.H chuỷ yeỏu include 3 taọp tin AFXWIN.H , AFXEXT.H
vaứ AFXDISP.H . Caực leọnh naứy baỷo ủaỷm laứ ửựng duùng coự theồ duứng
nhửừng lụựp trong caực taực vuù chuaồn vaứ nụựi roọng cuừng nhử lụựp lieõn quan
ủeỏn ActiveX Control (OLE).
#if!
defined(AFX_STDAFX_H__0CF6915F_3416_4CE6_AE4D_815051CD1243__INC
LUDED_)
Trang 5
Lập trình C trên Win
#defineAFX_STDAFX_H__0CF6915F_3416_4CE6_AE4D_815051CD1243_
_INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
 Taọp tin MainFrm.H
Taọp tin naứy chửựa caực khai baựo lieõn quan ủeỏn lụựp khung cửỷa soồ
chớnh (main frame) cuỷa ửựng duùng, CmainFrame. Lụựp naứy laứ haọu dueọ cuỷa
lụựp CframeWnd. Lụựp CmainFrame naứy xem nhử laứ theồ hieọn cửỷa soồ cuỷa
ửựng duùng ủoỏi theỏ giụựi beõn ngoaứi.
#if!
defined(AFX_MAINFRM_H__D2F0152D_93B3_4329_97B6_5DCED9B39D00__I
NCLUDED_)
#define
AFX_MAINFRM_H__D2F0152D_93B3_4329_97B6_5DCED9B39D00__INCLUD

ED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMainFrame : public CFrameWnd
{
protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
Trang 6
Lập trình C trên Win
virtual void Dump(CDumpContext& dc) const;
#endif
protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;

// Generated message map functions
protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
// NOTE - the ClassWizard will add and remove member
functions here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before
the previous line.
#endif!
defined(AFX_MAINFRM_H__D2F0152D_93B3_4329_97B6_5DCED9B39D00__I
NCLUDED_)
Lụựp CmainFrame ủửụùc dn xuaỏt tửứ lụựp cụ sụỷ CframeWnd, vỡ ủãy laứ
ửựng dúng SDI chổ laứm vieọc vụựi moọt taứi lieọu trong moọt luực. Phần khai
baựo gồm:
- Haứm khụỷi táo protected CMainFrame() haứ haứm huyỷ ~CMainFrame().
- Haứm thaứnh viẽn CObject::AssertValid() duứnh kieồm tra hụùp leọ ủoỏi
tửụùng vaứo luực cháy baống caựch kieồm tra tỡnh tráng noọi tái. Trong
phiẽn baỷn Debug (khai baựo bụỷi _DEBUG) haứm naứy giaỷ ủũnh (assert)
vaứ do ủoự coự theồ cho chaỏm dửựt chửụng trỡnh vụựi moọt thõng baựo
cho bieỏt soỏ thửự tửù doứng leọnh vaứ tẽn taọp tin neỏu giaỷ ủũnh naứy
khõng truựng.
- Haứm thaứnh viẽn CObject::Dump() duứng tuõn xoồ (dump) noọi dung
ủoỏi tửụùng khi gụừ roỏi.
- Bieỏn thaứnh viẽn m_wndStatusbar thuoọc kieồu Cstatusbar duứng chửựa

tỡnh tráng cuỷa thanh tỡnh tráng.
- Bieỏn thaứnh viẽn m_wndToolBar thuoọc kieồu CToolBar duứng chửựa
tỡnh tráng cuỷa thanh cõng cú.
Trang 7
Lập trình C trên Win
Ngoaứi ra lụựp coứn khai baựo moọt message map (thõng qua macro
DECLARE_MESSAGE_MAP ụỷ cuoỏi phần khai baựo lụựp), cuừng nhử nhửừng
chuự giaỷi {{AFX_MSG … }}AFX_MSG duứng laứm ch daứnh trửụực ủeồ cheứn
caực haứm thaứnh viẽn giaỷi quyeỏt caực thõng ủieọp maứ coự theồ về sau seừ
thẽm vaứo sửỷ dúng ủeỏn trỡnh ClassWizard.
Ngoaứi ra lụựp naứy coứn trieọu gói:
- haứm afx_msg void OnCreate() ủeồ táo moọt cửỷa soồ cho pheựp ửựng
dúng giaỷi quyeỏt caực thõng ủieọp Windows. Caực haứm naứy baột ủầu
bụỷi afx_msg cho bieỏt laứ haứm giaỷi quyeỏt caực thõng ủieọp Windows
ủaừ coự saỹn . Vớ dú haứm afx_msg void OnCreate() seừ giaỷi quyeỏt
thõng ủieọp Windows WM_CREATE táo moọt cửỷa soồ.
- Haứm virtual BOOL PreCreateWindow() ủeồ laứm vieọc gỡ ủoự, trửụực khi
táo moọt cửỷa soồ Windows ủửụùc gaộn cho ủoỏi tửụùng CWnd. Coự theồ
override haứm naứy ủeồ thay ủoồi caỏu truực CREATESTRUCT trửụực khi
cửỷa soồ táo ra.
Cuoỏi cuứng trong phần khai baựo lụựp laứ macro :
DECLARE_DYNCREATE(CMainFrame)
Cho pheựp caực ủoỏi tửụùng thuoọc lụựp ủửụùc dn xuaỏt tửứ lụựp CObject
coự theồ ủửụùc táo ủoọng (dynamic) vaứo luực cháy chửụng trỡnh. Caực lụựp
document, view vaứ frame ủều chũu h trụù vieọc táo ủoọng caực ủoỏi tửụùng,
nẽn caực lụựp CVidu1Doc vaứ CVidu1View ủều coự macro
DECLARE_DYNCREATE() naứy nhử :
- DECLARE_DYNCREATE(CVidu1Doc) trẽn taọp tin Vidu1Doc.h
- DECLARE_DYNCREATE(CVidu1View) trẽn taọp tin Vidu1View.h
Nhửừng haứm naứo naốm giửừa caởp chổ thũ #ifdef _DEBUG …. #endif nhử

laứ
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
Cho bieỏt laứ caực haứm naứy chổ hoát ủoọng khi chửụng trỡnh ủửụùc biẽn
dũch theo phiẽn baỷn debug duứng gụừ roỏi chửụng trỡnh. Nhửng khi biẽn dũch theo
phiẽn baỷn Release (chửụng trỡnh ủaừ gụừ roỏi xong) ủeồ phãn phoỏi cho ngửụứi
sửỷ dúng thỡ caực haứm naứy seừ khõng naốm trong thaứnh phần chửụng trỡnh
object.
 Taọp tin Vidu1View.H
Trang 8
Lập trình C trên Win
Lụựp CVidu1View ủửụùc daón xuaỏt tửứ lụựp cụ sụỷ Cview. View ủửụùc xem
nhử laứ phaàn keỏt xuaỏt cuỷa chửụng trỡnh ra giaỏy hoaởc leõn maứn hỡnh.
#if!
defined(AFX_VIDU1VIEW_H__D46CA8EC_3131_454A_A608_9CD3144E2B54__I
NCLUDED_)
#defineAFX_VIDU1VIEW_H__D46CA8EC_3131_454A_A608_9CD3144E2B
54__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CVidu1View : public CView
{
protected: // create from serialization only
CVidu1View();
DECLARE_DYNCREATE(CVidu1View)
// Attributes
public:

CVidu1Doc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CVidu1View)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CVidu1View();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CVidu1View)
Trang 9
Lập trình C trên Win
// NOTE - the ClassWizard will add and remove member
functions here.
// DO NOT EDIT what you see in these blocks of generated

code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in Vidu1View.cpp
inline CVidu1Doc* CVidu1View::GetDocument()
{ return (CVidu1Doc*)m_pDocument; }
#endif
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before
the previous line.
#endif // !
defined(AFX_VIDU1VIEW_H__D46CA8EC_3131_454A_A608_9CD3144E2B54__I
NCLUDED_)
Tửụng tửù nhử caực taọp tin tiẽu ủề khaực, taọp tin tiẽu ủề CVidu1View. H
coự caực haứm khụỷi táo CVidu1View(), haứm huyỷ ~CVidu1View(), haứm kieồm
tra hụùp leọ AssertValid() vaứ haứm tuõn xoồ gụừ roỏi chửụng trỡnh Dump().
Vỡ lụựp View phaỷi ủóc taứi lieọu naứo ủoự ủeồ cho hieồn thũ (hoaởc in ) dửừ
kieọn, nẽn trong lụựp phaỷi khai baựo haứm CView::GetDocument() nhử sau:
Public:
CVidu1Doc* GetDocument();
Haứm naứy laỏy con troỷ chổ vaứo ủoỏi tửụùng taứi lieọu CVidu1Doc (lụựp
naứy ủửụùc dn xuaỏt tửứ CDocument) ủửụùc gaộn liền vụựi view. Khi coự con troỷ
rồi thỡ lụựp naứy mụựi coự theồ truy xuaỏt caực haứm thaứnh viẽn cuỷa lụựp taứi
lieọu CVidu1Doc.
Vỡ laứ view nẽn lụựp naứy phaỷi khai baựo haứm veừ hỡnh aỷnh taứi lieọu,
ủoự laứ haứm virtual OnDraw(). Ngoaứi ra trong vớ dú Vidu1 coự trỡnh ủụn File-
Print, vaứ File- Print Preview nẽn lụựp naứy cuừng phaỷi khai baựo luõn haứm
virtual in aỏn nhử sau:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);

virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
Taỏt caỷ caực haứm trẽn ủều sửỷ dúng ủeỏn moọt ủoỏi tửụùng CDC (thuoọc
giao dieọn ủồ hóa GDI) ủửụùc chổ về con troỷ pDC. Khi tõ, veừ cần ủeỏn caực
buựt veừ (pen) hoaởc có veừ (brush) vaứ ủãy laứ nhửừng taứi nguyẽn GDI.
Trang 10
Lập trình C trên Win
Taỏt caỷ caực haứm virtual treõn ủeàu naốm trong caực chuự giaỷi
{{AFX_VIRTUAL … }}AFX_VIRTUAL maứ ClassWizard seừ keỏt sinh ra.
Ngoaứi ra lụựp CVidu1View cuừng khai baựo message map (do macro
DECLARE_MESSAGE_MAP ) vaứ chửựa choó saỹn cho ClassWizard theõm baỏt
cửự haứm thaứnh vieõn giaỷi quyeỏt caực thoõng ủieọp, thoõng qua caực haứnh chuự
giaỷi {{AFX_MSG … }} AFX_MSG. Trong vớ duù hieọn chửa coự haứm giaỷi
quyeỏt naứo caỷ.
Cuoỏi cuứng laứ haứm inline caứi ủaởt haứm GetDocument () bao boùc bụỷi
chổ thũ trỡnh bieõn dũch #ifndef … #endif , vaứ chổ hieọn hửừu trong phieõn baỷn
debug
#ifndef _DEBUG // debug version in Vidu1View.cpp
inline CVidu1Doc* CVidu1View::GetDocument()
{ return (CVidu1Doc*)m_pDocument; }
#endif
 Taọp tin Vidu1Doc.H
Taọp tin naứy chửựa khai baựo lieõn quan ủeỏn taứi lieọu, taọp tin naứy khai
baựo lụựp CVidu1Doc thuoọc lụựp cụ sụỷ Cdocument
// Vidu1Doc.h : interface of the CVidu1Doc class
#if!
defined(AFX_VIDU1DOC_H__D00A42EA_1136_4442_9C89_003869BBC74B__I
NCLUDED_)
#defineAFX_VIDU1DOC_H__D00A42EA_1136_4442_9C89_003869BBC74
B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CVidu1Doc : public CDocument
{
protected: // create from serialization only
CVidu1Doc();
DECLARE_DYNCREATE(CVidu1Doc)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CVidu1Doc)
public:
virtual BOOL OnNewDocument();
Trang 11
Lập trình C trên Win
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CVidu1Doc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions

protected:
//{{AFX_MSG(CVidu1Doc)
// NOTE - the ClassWizard will add and remove member
functions here.
// DO NOT EDIT what you see in these blocks of generated
code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately
before the previous line.
#endif // !
defined(AFX_VIDU1DOC_H__D00A42EA_1136_4442_9C89_003869BBC74B__I
NCLUDED_)
Ngoaứi caực haứm khụỷi gaựn, haứm huyỷ, haứm kieồm tra hụùp leọ, haứm
tuõn xoồ noọi dung taứi lieọu khi gụừ roỏi chửụng trỡnh. Trong phần khai baựo
haứm virtual coự hai haứm liẽn quan ủeỏn taứi lieọu:
- Haứm virtual BOOL OnNewDocument() nhử laứ thaứnh phần cuỷa leọnh
File/ New ủeồ mụỷ taứi lieọu. Neỏu laứ taứi lieọu SDI khi ra leọnh File/New
thỡ haứm naứy khụỷi gaựn lái taứi lieọu hieọn hửừu thay vỡ táo moọt taứi
lieọu mụựi. Neỏu ửựng dúng laứ MDI thỡ leọnh trẽn seừ sửỷ dúng haứm
naứy ủeồ táo moọt taứi lieọu mụựi.
- Haứm virtual void Serialize(Carchive &ar) duứng ủeồ vieỏt hoaởc ủóc ủoỏi
tửụùng taứi lieọu lẽn moọt ủoỏi tửụùng Carchive hoaởc tửứ ủoỏi tửụùng
Carchive. ẹoỏi tửụùng Carchive nhử laứ moọt doứng dửừ lieọu nhũ phãn.
Haứm naứy mang tớnh chaỏt saỷn sinh haứng loát ủoỏi tửụùng do ủoự coự
chửừ Serial.
Trang 12

Lập trình C trên Win
Lụựp Document cho pheựp caỏt trửừ dửừ lieọu hoaởc ủoùc xuoỏng dửừ lieọu
tửứ moọt taọp tin goùi laứ taứi lieọu, cho pheựp Windows khai thaực nhieàu taứi
lieọu cuứng moọt luực. Lụựp Document hụùp taực chaởt cheừ vụựi lụựp view.
 Taọp tin Vidu1.RC
Taọp tin naứy chửựa caực taứi nguyeõn lieõn quan ủeỏn menu, phớm noựng,
hoọp hoọi thoaùi,…
//Microsoft Developer Studio generated resource script.
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
// Generated from the TEXTINCLUDE 2 resource.
#include "afxres.h"
#undef APSTUDIO_READONLY_SYMBOLS
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
// TEXTINCLUDE
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END

3 TEXTINCLUDE DISCARDABLE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) ||
defined(AFX_TARG_ENU)\r\n"
"#ifdef _WIN32\r\n"
"LANGUAGE 9, 1\r\n"
Trang 13
Lập trình C trên Win
"#pragma code_page(1252)\r\n"
"#endif //_WIN32\r\n"
"#include ""res\\Vidu1.rc2"" // non-Microsoft Visual C++ edited
resources\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#include ""afxprint.rc"" // printing/print preview resources\r\n"
"#endif\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
// Icon
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME ICON DISCARDABLE "res\\Vidu1.ico"
IDR_VIDU1TYPE ICON DISCARDABLE "res\\Vidu1Doc.ico"
// Bitmap
IDR_MAINFRAME BITMAP MOVEABLE PURE

"res\\Toolbar.bmp"
// Toolbar
IDR_MAINFRAME TOOLBAR DISCARDABLE 16, 15
BEGIN
BUTTON ID_FILE_NEW
BUTTON ID_FILE_OPEN
BUTTON ID_FILE_SAVE
SEPARATOR
BUTTON ID_EDIT_CUT
BUTTON ID_EDIT_COPY
BUTTON ID_EDIT_PASTE
SEPARATOR
BUTTON ID_FILE_PRINT
SEPARATOR
BUTTON ID_APP_ABOUT
END
// Menu
IDR_MAINFRAME MENU PRELOAD DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New\tCtrl+N", ID_FILE_NEW
MENUITEM "&Open \tCtrl+O", ID_FILE_OPEN
MENUITEM "&Save\tCtrl+S", ID_FILE_SAVE
MENUITEM "Save &As ", ID_FILE_SAVE_AS
Trang 14
Lập trình C trên Win
MENUITEM SEPARATOR
MENUITEM "&Print \tCtrl+P", ID_FILE_PRINT
MENUITEM "Print Pre&view", ID_FILE_PRINT_PREVIEW

MENUITEM "P&rint Setup ", ID_FILE_PRINT_SETUP
MENUITEM SEPARATOR
MENUITEM "Recent File", ID_FILE_MRU_FILE1,
GRAYED
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_APP_EXIT
END
POPUP "&Edit"
BEGIN
MENUITEM "&Undo\tCtrl+Z", ID_EDIT_UNDO
MENUITEM SEPARATOR
MENUITEM "Cu&t\tCtrl+X", ID_EDIT_CUT
MENUITEM "&Copy\tCtrl+C", ID_EDIT_COPY
MENUITEM "&Paste\tCtrl+V", ID_EDIT_PASTE
END
POPUP "&View"
BEGIN
MENUITEM "&Toolbar", ID_VIEW_TOOLBAR
MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR
END
POPUP "&Help"
BEGIN
MENUITEM "&About Vidu1 ", ID_APP_ABOUT
END
END
// Accelerator
IDR_MAINFRAME ACCELERATORS PRELOAD MOVEABLE PURE
BEGIN
"N", ID_FILE_NEW, VIRTKEY, CONTROL
"O", ID_FILE_OPEN, VIRTKEY, CONTROL

"S", ID_FILE_SAVE, VIRTKEY, CONTROL
"P", ID_FILE_PRINT, VIRTKEY, CONTROL
"Z", ID_EDIT_UNDO, VIRTKEY, CONTROL
"X", ID_EDIT_CUT, VIRTKEY, CONTROL
"C", ID_EDIT_COPY, VIRTKEY, CONTROL
"V", ID_EDIT_PASTE, VIRTKEY, CONTROL
VK_BACK, ID_EDIT_UNDO, VIRTKEY, ALT
VK_DELETE, ID_EDIT_CUT, VIRTKEY, SHIFT
VK_INSERT, ID_EDIT_COPY, VIRTKEY, CONTROL
VK_INSERT, ID_EDIT_PASTE, VIRTKEY, SHIFT
Trang 15
Lập trình C trên Win
VK_F6, ID_NEXT_PANE, VIRTKEY
VK_F6, ID_PREV_PANE, VIRTKEY, SHIFT
END
// Dialog
IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 235, 55
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION |
WS_SYSMENU
CAPTION "About Vidu1"
FONT 8, "MS Sans Serif"
BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
LTEXT "Vidu1 Version
1.0",IDC_STATIC,40,10,119,8,SS_NOPREFIX
LTEXT "Copyright (C) 2004",IDC_STATIC,40,25,119,8
DEFPUSHBUTTON "OK",IDOK,178,7,50,14,WS_GROUP
END
#ifndef _MAC
// Version

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "\0"
VALUE "FileDescription", "Vidu1 MFC Application\0"
VALUE "FileVersion", "1, 0, 0, 1\0"
VALUE "InternalName", "Vidu1\0"
VALUE "LegalCopyright", "Copyright (C) 2004\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "Vidu1.EXE\0"
VALUE "ProductName", "Vidu1 Application\0"
Trang 16
Lập trình C trên Win
VALUE "ProductVersion", "1, 0, 0, 1\0"
END
END

BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
// DESIGNINFO
ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 228
TOPMARGIN, 7
BOTTOMMARGIN, 48
END
END
#endif // APSTUDIO_INVOKED
// String Table
STRINGTABLE PRELOAD DISCARDABLE
BEGIN
IDR_MAINFRAME
"Vidu1\n\nVidu1\n\n\nVidu1.Document\nVidu1 Document"
END
STRINGTABLE PRELOAD DISCARDABLE
BEGIN
AFX_IDS_APP_TITLE "Vidu1"
AFX_IDS_IDLEMESSAGE "Ready"
END

STRINGTABLE DISCARDABLE
BEGIN
ID_INDICATOR_EXT "EXT"
ID_INDICATOR_CAPS "CAP"
ID_INDICATOR_NUM "NUM"
ID_INDICATOR_SCRL "SCRL"
ID_INDICATOR_OVR "OVR"
ID_INDICATOR_REC "REC"
END
Trang 17
Lập trình C trên Win
STRINGTABLE DISCARDABLE
BEGIN
ID_FILE_NEW "Create a new document\nNew"
ID_FILE_OPEN "Open an existing document\nOpen"
ID_FILE_CLOSE "Close the active document\nClose"
ID_FILE_SAVE "Save the active document\nSave"
ID_FILE_SAVE_AS "Save the active document with a new
name\nSave As"
ID_FILE_PAGE_SETUP "Change the printing options\nPage Setup"
ID_FILE_PRINT_SETUP "Change the printer and printing
options\nPrint Setup"
ID_FILE_PRINT "Print the active document\nPrint"
ID_FILE_PRINT_PREVIEW "Display full pages\nPrint Preview"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_APP_ABOUT "Display program information, version number
and copyright\nAbout"
ID_APP_EXIT "Quit the application; prompts to save

documents\nExit"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_FILE_MRU_FILE1 "Open this document"
ID_FILE_MRU_FILE2 "Open this document"
ID_FILE_MRU_FILE3 "Open this document"
ID_FILE_MRU_FILE4 "Open this document"
ID_FILE_MRU_FILE5 "Open this document"
ID_FILE_MRU_FILE6 "Open this document"
ID_FILE_MRU_FILE7 "Open this document"
ID_FILE_MRU_FILE8 "Open this document"
ID_FILE_MRU_FILE9 "Open this document"
ID_FILE_MRU_FILE10 "Open this document"
ID_FILE_MRU_FILE11 "Open this document"
ID_FILE_MRU_FILE12 "Open this document"
ID_FILE_MRU_FILE13 "Open this document"
ID_FILE_MRU_FILE14 "Open this document"
ID_FILE_MRU_FILE15 "Open this document"
ID_FILE_MRU_FILE16 "Open this document"
END
Trang 18
Lập trình C trên Win
STRINGTABLE DISCARDABLE
BEGIN
ID_NEXT_PANE "Switch to the next window pane\nNext Pane"
ID_PREV_PANE "Switch back to the previous window
pane\nPrevious Pane"
END
STRINGTABLE DISCARDABLE

BEGIN
ID_WINDOW_SPLIT "Split the active window into panes\nSplit"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_EDIT_CLEAR "Erase the selection\nErase"
ID_EDIT_CLEAR_ALL "Erase everything\nErase All"
ID_EDIT_COPY "Copy the selection and put it on the
Clipboard\nCopy"
ID_EDIT_CUT "Cut the selection and put it on the
Clipboard\nCut"
ID_EDIT_FIND "Find the specified text\nFind"
ID_EDIT_PASTE "Insert Clipboard contents\nPaste"
ID_EDIT_REPEAT "Repeat the last action\nRepeat"
ID_EDIT_REPLACE "Replace specific text with different
text\nReplace"
ID_EDIT_SELECT_ALL "Select the entire document\nSelect All"
ID_EDIT_UNDO "Undo the last action\nUndo"
ID_EDIT_REDO "Redo the previously undone action\nRedo"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_VIEW_TOOLBAR "Show or hide the toolbar\nToggle ToolBar"
ID_VIEW_STATUS_BAR "Show or hide the status bar\nToggle
StatusBar"
END
STRINGTABLE DISCARDABLE
BEGIN
AFX_IDS_SCSIZE "Change the window size"
AFX_IDS_SCMOVE "Change the window position"

AFX_IDS_SCMINIMIZE "Reduce the window to an icon"
Trang 19
Lập trình C trên Win
AFX_IDS_SCMAXIMIZE "Enlarge the window to full size"
AFX_IDS_SCNEXTWINDOW "Switch to the next document window"
AFX_IDS_SCPREVWINDOW "Switch to the previous document
window"
AFX_IDS_SCCLOSE "Close the active window and prompts to save
the documents"
END
STRINGTABLE DISCARDABLE
BEGIN
AFX_IDS_SCRESTORE "Restore the window to normal size"
AFX_IDS_SCTASKLIST "Activate Task List"
END
STRINGTABLE DISCARDABLE
BEGIN
AFX_IDS_PREVIEW_CLOSE "Close print preview mode\nCancel
Preview"
END
#endif // English (U.S.) resources
#ifndef APSTUDIO_INVOKED
// Generated from the TEXTINCLUDE 3 resource.
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1

#pragma code_page(1252)
#endif //_WIN32
#include "res\Vidu1.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#include "afxprint.rc" // printing/print preview resources
#endif
#endif // not APSTUDIO_INVOKED
 Taọp tin Vidu1.CPP
Taọp tin naứy ủũnh nghúa caực haứm ủaừ khai baựo trong lụựp CVidu1App, laứ
lụựp chửụng trỡnh chớnh.
// Vidu1.cpp : Defines the class behaviors for the application.
#include "stdafx.h"
#include "Vidu1.h"
Trang 20
Lập trình C trên Win
#include "MainFrm.h"
#include "Vidu1Doc.h"
#include "Vidu1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CVidu1App
BEGIN_MESSAGE_MAP(CVidu1App, CWinApp)
//{{AFX_MSG_MAP(CVidu1App)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping
macros here.
// DO NOT EDIT what you see in these blocks of generated

code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP,
CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
// CVidu1App construction
CVidu1App::CVidu1App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CVidu1App object
CVidu1App theApp;
// CVidu1App initialization
BOOL CVidu1App::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
Trang 21
Lập trình C trên Win
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in
a shared DLL

#else
Enable3dControlsStatic(); // Call this when linking to MFC
statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options
(including MRU)
// Register the application's document templates. Document
templates
// serve as the connection between documents, frame windows and
views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CVidu1Doc),
RUNTIME_CLASS(CMainFrame), // main SDI frame
window
RUNTIME_CLASS(CVidu1View));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);

m_pMainWnd->UpdateWindow();
//m_pMainWnd-> ShowWindow(SW_SHOWMAXIMIZED);
//m_pMainWnd->UpdateWindow();
return TRUE;
}
// CAboutDlg dialog used for App About
Trang 22
Lập trình C trên Win
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{

//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CVidu1App::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
// CVidu1App message handlers
Trang 23
Lập trình C trên Win
Phần chửựa message map cuỷa lụựp CVidu1App keỏt noỏi caực haứm thaứnh
viẽn nhử sau vaứ thõng ủieọp Windows:
BEGIN_MESSAGE_MAP(CVidu1App, CWinApp)
//{{AFX_MSG_MAP(CVidu1App)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
//}}AFX_MSG_MAP
// Standard file based document commands

ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP,
CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
- Keỏt noỏi thõng ủieọp ID_APP_ABOUT vụựi haứm thaứnh viẽn
OnAppAbout(). Message map naứy laứm cho chửụng trỡnh coự khaỷ naờng
ủaựp ửựng leọnh About trẽn trỡnh ủụn Help.
- Keỏt noỏi thõng ủieọp ID_FILE_VIEW vụựi haứm thaứnh viẽn
CwinApp::OnFileNew() cho pheựp chửụng trỡnh ủaựp ửựng leọnh trỡnh ủụn
File/ New vaứ dửùa trẽn haứm thaứnh viẽn OnFileNew() cuỷa lụựp cha
mé CwinApp vaứ thõng ủieọp ID_FILE_OPEN cuừng tửụng tửù vụựi
haứm thaứnh viẽn CwinApp::OnFileOpen().
- Haứm khụỷi dửùng CVidu1App::CVidu1App(): haứm naứy khõng coự
leọnh. Ngửụứi laọp trỡnh coự theồ thửùc hieọn khụỷi gaựn moọt giaự trũ
naứo ủoự.
- Táo moọt ủoỏi tửụùng cuỷa lụựp CVidu1App duy nhaỏt theo leọnh sau:
CVidu1App theApp;
- Haứm thaứnh viẽn InitInstance(): haứm naứy khụỷi gaựn nhửừng theồ
hieọn cuỷa lụựp CVidu1App baống caựch thửùc hieọn nhửừng cõng vieọc
sau:
o Gói haứm thaứnh viẽn AfxEnableControlContainer() cho pheựp
h trụù vieọc chửựa caực ủoỏi tửụùng OLE
o Náp nhửừng múc chón tửứ taọp tin .INI chuaồn sửỷ dúng haứm
SetRegistrykey()
o Náp danh saựch caực taọp tin ủửụùc sửỷ dúng gần ủãy nhaỏt bụỷi
haứm LoadStdProfileSetting()
o Cho ủaờng kyự ửựng dúng, khung cửỷa soồ vaứ lụựp view trong
document template cuỷa ửựng dúng thõng qua template

CsingleDocTemplate vaứ sửỷ dúng taực tửỷ new vaứ haứm
AddDocTemplate()
Trang 24
Lập trình C trên Win
o Cung caỏp ủoán maừ toỏi thieồu ủeồ xửỷ lyự caực ủoỏi múc phaựt
ủi tửứ doứng leọnh vaứ cho thi haứnh doứng leọnh bụỷi haứm
ProcessShellCommand() dửùa trẽn nhửừng thõng soỏ chuyeồn qua.
o Hieọn lẽn cửỷa soồ vaứ tõ veừ cửỷa soồ theo ủuựng thửùc tráng
thõng qua haứm ShowWindow() vaứ UpdateWindow()
- Haứm thaứnh viẽn OnAppAbout():
void CVidu1App::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
Leọnh thửự nhaỏt khai baựo theồ hieọn aboutDlg thuoọc lụựp hoọp hoọi thoái
CaboutDlg, coứn leọnh thửự hai chuyeồn thõng ủieọp C++ DoModal() cho ủoỏi
tửụùng aboutDlg ủeồ cho hieọn lẽn hoọp hoọi thoái modal about.
Taọp tin Vidu1.cpp coứn thieỏt laọp lụựp khung ủoỏi thoái CaboutDlg maứ
hoọp thoái About seừ duứng ủeỏn. Lụựp dialog khai baựo kieồu dửừ lieọu emun sửỷ
dúng ủeỏn haứng chuự giaỷi //{{AFX_DATA ….//}}AFX_DATA vụựi moọt vũ trớ
duy nhaỏt IDD ủửụùc gaựn bụỷi IDD_ABOUTBOX. Lụựp naứy cuừng khai baựo moọt
haứm khụỷi táo vaứ haứm virtual DaDataExchange().
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
Gói haứm khụỷi dửùng cuỷa lụựp cha mé Cdialog vaứ trao cho lụựp naứy trũ enum
IDD ủeồ gói taứi nguyẽn cuỷa hoọp thoái IDD_ABOUTBOX. ẹoán maừ cuỷa
haứm khụỷi dửùng chửựa nhửừng haứng chuự giaỷi /{{AFX_DATA_INIT
… //}}AFX_DATA_INIT daứnh ch saỹn ủeồ thẽm ủoán maừ khụỷi gaựn cho
hoọp thoái. Coứn haứm DoDataExchange() thõng qua ủoán maừ sau:
void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
Cuừng daứnh ch saỹn thõng qua haứng chuự giaỷi //{{AFX_DATA_MAP
…. //}}AFX_DATA_MAP ủeồ daứnh bieỏn trao ủoồi dửừ lieọu.
Cuoỏi cuứng taọp tin cuừng ủũnh nghúa message map ủoỏi vụựi lụựp dialog.
Map naứy hieọn rng, duứng daứnh ch saỹn coự theồ ủửa vaứo nhửừng múc vaứo
message map.
 Taọp tin STDAFX.CPP
Taọp tin naứy chổ coự leọnh STDAFX.h
 Taọp tin MainFrm.cpp
Taọp tin naứy chửựa caực leọnh thieỏt laọp khung cửỷa soồ chớnh cuỷa
ửựng dúng cuỷa lụựp CMainFrame. Taọp tin cho thaỏy phần message map
Trang 25

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×