vc 程式設計 base i
DESCRIPTION
VC 程式設計 Base I. 報告者: Jerry Chen TEL : 0939-109232 Email: [email protected]. Contents. 重要資料介紹. 基本名詞與概念介紹. 程式開發環境安置與範例. Q&A. 參考. Thinking in C++ 2nd edition Volume 2: Standard Libraries & Advanced Topics www.MindView.net. 參考. 好書介紹. 程式設計領域裡,每個人都想飛,但是還沒有學會走之前,跑都別想! ( 深入淺出 / 侯俊傑 ). - PowerPoint PPT PresentationTRANSCRIPT
Confidential1
VC VC 程式設計 程式設計 Base IBase I
報告者: Jerry Chen
TEL : 0939-109232
Email: [email protected]
Confidential2
ContentsContents
重要資料介紹
基本名詞與概念介紹
程式開發環境安置與範例
Q&A
Confidential
參考
• Thinking in C++ 2nd edition Volume 2: Standard Libraries & Advanced Topics
• www.MindView.net
Confidential
參考
Confidential
好書介紹
• 程式設計領域裡,每個人都想飛,但是還沒有學會走之前,跑都別想! ( 深入淺出 / 侯俊傑 )
5
Confidential
重要參考介紹 #2
• 對航海的人來說,擱淺的船就是燈塔! ( 荷蘭諺語 )
Confidential7
基本名詞介紹基本名詞介紹
• 類別 (Class)
• 物件 (Object)
• 成員函數 (Member function)
• 成員變數 (Member variable)
• 動態連結 (Dynamic link library)
Confidential8
類別 & 物件
類別 (Class)
物件 (Object)
Confidential
類別 & 物件
Confidential
程式重複使用 - 方法 1指定物件
• 寫程式如堆積木,可以重複使用是很重要的!
• 最簡易的方法是指另這個類別物件。– Light it; – Light A;
• Light 我們稱為類別。• 上訴的 it 或 A 物體,我們稱為 Light 類別的物
件。
Confidential
程式重複使用 - 方法 2加入成員物件
• 在自己的類別 (Class) 中加入所需的成員物件(member Object)
Confidential
程式重複使用 - 方法 3繼承
• 繼承 (Inheritance)
• 一個子類別繼承父類別 (Super class) 我們稱為延生類別 (Derived class) 、或繼承類別 (Inherited class) 、或子類別(Sub class) 、或後代類別 (Child class)
• 如果子類別繼承了一個以上的父類別 ,則稱為 Multiple Inheritance( 多重繼承 )。
• 一個形狀類別中有許多功能,可以被新的圓形、方形、三角形等類別繼承來使用。
Confidential
函數 & 變數
成員函數 (Member function)
成員變數 (Member variable)
Confidential
添加新函數
• 在三角形類別中,建立出新的功能,例如垂直翻轉成員函數 (Member function) 、水平翻轉成員函數。
Confidential
Override function
• 子類別重新定義它所能看到的父類別中的 method(如 public, protected) 稱為覆寫 (Override) 。
Confidential
• 所有 C 語言都需要宣告與定義才能使用。• 宣告 (Declaration) :
– 宣告的用意在於把變數或函數的名稱告知編譯器(Compiler) 。
– 宣告檔 (Header file) ,通常以 .h 作為附檔名!• 定義 (Definition) :
– 讓編譯器 (Compiler) 瞭解這個變數或函數已經存在於程式中的某個位置。也是讓編譯器製造出儲存空間給該變數或函數。
宣告 & 定義
Confidential
函數宣告構造 (Function declaration syntax)
宣告 & 定義
變數宣告構造 (Variable declaration syntax)
Confidential
宣告 & 定義
Confidential
動態連結 (Dynamic link library)
Windows 三大動態連結檔協力廠商提供的動態連結檔
Confidential
WindowsWindows 中的中的三大動態連結檔三大動態連結檔
• GDI32.dll (GDI32.lib)
• User32.dll (User32.lib)
• Kernel32.dll (Kernel32.lib)
• Commdlg.dll (Comdlg32.lib)
• Toolhelp.dll (TH32.lib)
20
Confidential
協力廠商提供的動態連結檔
• PCI_M314.dll ( 先達 , Motion)
• PISODIO.dll ( 泓格 , IO)
• MultiCam.dll, EObjMs60d.dll…(Euresys, Vision)
• MapPro.dll ( 威嘉 , Barcode transfer)
Confidential
綜合範例
Lighting Class
Confidential
ComLighting 範例
Confidential
CComPort 範例
Confidential25
MFCMFC 介紹介紹
MFC Fundamentals & Architecture
Confidential
What Is MFC?
Win32 API(SDK)
OLE ODBC
Windows BaseOS Services
Windows OS ServiceExtensions
Base MFCClasses
OLEClasses
ODBCClasses
MFC
Collections,Miscellaneous
Classes
Confidential
MFC 構造 (Architecture)
• The Application Framework
• CWinApp Class
• CFrameWnd Class
• Documents and Views
• Document/View Interaction
• MFC Document Templates
Confidential
The Application Framework
CWinApp CFrameWnd
CView
CDocument
CDocTemplateMYAPP.EXE
Confidential
Documents and Views
DataData
Possible Views
017981687
5685446672
1971114595
805103592
5685446672
1971114595
Document
Confidential
Document/View Interaction (for SDI)
Frame ObjectFrame Object
View ObjectView Object
GetDocument
GetActiveView
UpdateAllViews ,GetNextView
Document ObjectDocument Object
GetActiveDocument
AfxGetMainWnd() AfxGetApp()
Confidential
General Approach to MFC Programming
CObject
CCmdTarget
CWnd
CYourViewCMainFrameCYourApp CYourDocCYourDlg
CViewCFrameWnd CDialog
CDocTemplate
CWinAppCWinApp
CDocument
Framework classes
CWinThreadCWinThread
Confidential
Icon Resource
Confidential33
Confidential
程式開發環境安置
安裝 VC
設定關連環境程式製作
Confidential
• http://www.freegroup.org/2010/06/visual-studio-2010-express/
• http://www.microsoft.com/express
Confidential
安裝 VC
Confidential
Confidential
• 索取序號• 事實上,當你安裝完成
後還需要做一個動作:註冊。不用擔心,這只是微軟的一個驗證程序而已,過程完全免費。
Confidential
環境設定
Confidential40
Visual C++ Visual C++ 範例範例
Hello WordHello Word 範例範例
Confidential
Confidential
Confidential
Confidential
Confidential
Confidential
Debug Tools in Visual C++
Build controls
Standard
Debug
Watch
WizardBar
Step Into (F11)
Step over (F10)
Go (F5)
Build (F7)
Confidential
Confidential
ClassWizard (Ctrl+W)
Confidential
BEGIN_MESSAGE_MAP(CFirstView, CView) //{{AFX_MSG_MAP(CMainFrame) ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CFirstView, CView) //{{AFX_MSG_MAP(CMainFrame) ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)END_MESSAGE_MAP()
class CFirstView : public CView{ .../ Generated message map functionsprotected: //{{AFX_MSG(CFirstView) afx_msg void OnLButtonDown(UINT nFlags, CPoint point); //}}AFX_MSG DECLARE_MESSAGE_MAP()};
class CFirstView : public CView{ .../ Generated message map functionsprotected: //{{AFX_MSG(CFirstView) afx_msg void OnLButtonDown(UINT nFlags, CPoint point); //}}AFX_MSG DECLARE_MESSAGE_MAP()};
.H file
.CPP file
Confidential
• void CTest1View::OnLButtonDown(UINT nFlags, CPoint point) • {• // TODO: Add your message handler code here and/or call default• CString sOutput;• sOutput.Format("x=%d, y=%d",point.x,point.y);•• CClientDC dc(this);• dc.TextOut(point.x,point.y,sOutput);•• CView::OnLButtonDown(nFlags, point);• }
Confidential
Confidential
Confidential53
Q&AQ&A