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

33 319 0
Lập trình C trên Win doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

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 [...]... CVidu 1Doc thuo c lụựp c sụỷ Cdocument // Vidu 1Doc. h : interface of the CVidu 1Doc class #if! defined(AFX_VIDU 1DOC_ H D00A42EA_1136_4442_ 9C8 9_003869BBC74B I NCLUDED_) #defineAFX_VIDU 1DOC_ H D00A42EA_1136_4442_ 9C8 9_003869BBC74 B INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CVidu 1Doc : public CDocument { protected: // create from serialization only CVidu 1Doc( ); DECLARE_DYNCREATE(CVidu 1Doc) ... 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... CVidu1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } // CVidu1View diagnostics #ifdef _DEBUG void CVidu1View::AssertValid() const { CView::AssertValid(); } void CVidu1View::Dump(CDumpContext& dc) const { CView::Dump(dc); } CVidu 1Doc* CVidu1View::GetDocument() // non-debug version is inline { ASSERT(m_pDocument>IsKindOf(RUNTIME_CLASS(CVidu 1Doc) )); return (CVidu 1Doc* )m_pDocument;... dúng vụựi ca c thaứnh phần c baỷn, thỡ ClassWizard laứ moọt c ng c tỡm hoa c quaỷn lyự moọt Trang 31 Lập trình C trên Win vaứi loái ủoỏi tửụùng, ủa c bieọt loái lụựp ủoỏi tửụùng thuo c m c tiẽu cuỷa ca c leọnh (command target) maứ MFC gói laứ lụựp CcmdTarget ẹeồ sửỷ dúng ClassWizard thử c hieọn chón menu View/ClassWizard Menu cuỷa ClassWizard bao gồm 5 tab cho chử c naờng ủa c bieọt cuỷa ClassWizard:... ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() // CVidu1View construction/destruction CVidu1View::CVidu1View() { } CVidu1View::~CVidu1View() { } BOOL CVidu1View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } // CVidu1View drawing void CVidu1View::OnDraw(CDC*... IDR_MAINFRAME, RUNTIME_CLASS(CVidu 1Doc) , 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,... DECLARE_DYNCREATE(CVidu 1Doc) // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CVidu 1Doc) public: virtual BOOL OnNewDocument(); Trang 11 Lập trình C trên Win virtual void Serialize(CArchive& ar); //}}AFX_VIRTUAL // Implementation public: virtual ~CVidu 1Doc( ); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc)... !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs int xSize= ::GetSystemMetrics(SM_CXSCREEN); int ySize= ::GetSystemMetrics(SM_CYSCREEN); cs.cx=xSize *9/10; cs.cy=ySize *9/10; cs.x=(xSize - cs.cx )/2; cs.y=(ySize - cs.cy )/2; cs.style &= ~FWS_ADDTOTITLE; cs.style &= ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX); cs.style &= ~WS_THICKFRAME;... Trong vớ dú 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 b c bụỷi chổ thũ trỡnh biẽn dũch #ifndef … #endif , vaứ chổ hieọn hửừu trong phiẽn baỷn debug #ifndef _DEBUG // debug version in Vidu1View.cpp inline CVidu 1Doc* CVidu1View::GetDocument() { return (CVidu 1Doc* )m_pDocument; } #endif  Taọp tin Vidu 1Doc. H Taọp tin naứy chửựa khai baựo liẽn... - OnNewDocument() haứm trieọu gói haứm OnNewDocument() cuỷa lụựp cha mé Cdocument táo moọt taứi lieọu mụựi, vaứ traỷ về moọt trũ Bool Ngoaứi ra haứm naứy chửứa ch ủeồ thẽm ca c ủoán maừ - Serialize() : haứm naứy coự saỹn nhaựnh IF … ELSE coự theồ hoa c trửừ ủoỏi tửụùng hoa c ủo c ủoỏi tửụùng, sửỷ dúng ca c ta c tửỷ >> hoa c . Ghi chuự CWinApp Cvd1App Vd1.cpp CDocument Cvd 1Doc Vidu 1Doc. cpp CView Cvd1View Vidu1View.cpp CFrameWnd CmainFrame MainFrm.cpp CMDIChildWnd CchildFrame ChildFrm.cpp  Taọp tin RESOURCE.H Taọ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. 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 CVidu 1Doc vaứ CVidu1View

Ngày đăng: 27/06/2014, 11:20

Từ khóa liên quan

Mục lục

  • Ùng duùng Single Document:

Tài liệu cùng người dùng

Tài liệu liên quan