vc 程式設計 base i

53
Confidential 1 VC VC 程程程程 程程程程 Base I Base I 報報報Jerry Chen TEL 0939-109232 Email: [email protected]

Upload: brynne-vang

Post on 01-Jan-2016

96 views

Category:

Documents


2 download

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 Presentation

TRANSCRIPT

Page 1: VC  程式設計  Base I

Confidential1

VC VC 程式設計 程式設計 Base IBase I

報告者: Jerry Chen

TEL : 0939-109232

Email: [email protected]

Page 2: VC  程式設計  Base I

Confidential2

ContentsContents

重要資料介紹

基本名詞與概念介紹

程式開發環境安置與範例

Q&A

Page 3: VC  程式設計  Base I

Confidential

參考

• Thinking in C++ 2nd edition Volume 2: Standard Libraries & Advanced Topics

• www.MindView.net

Page 4: VC  程式設計  Base I

Confidential

參考

Page 5: VC  程式設計  Base I

Confidential

好書介紹

• 程式設計領域裡,每個人都想飛,但是還沒有學會走之前,跑都別想! ( 深入淺出 / 侯俊傑 )

5

Page 6: VC  程式設計  Base I

Confidential

重要參考介紹 #2

• 對航海的人來說,擱淺的船就是燈塔! ( 荷蘭諺語 )

Page 7: VC  程式設計  Base I

Confidential7

基本名詞介紹基本名詞介紹

• 類別 (Class)

• 物件 (Object)

• 成員函數 (Member function)

• 成員變數 (Member variable)

• 動態連結 (Dynamic link library)

Page 8: VC  程式設計  Base I

Confidential8

類別 & 物件

類別 (Class)

物件 (Object)

Page 9: VC  程式設計  Base I

Confidential

類別 & 物件

Page 10: VC  程式設計  Base I

Confidential

程式重複使用 - 方法 1指定物件

• 寫程式如堆積木,可以重複使用是很重要的!

• 最簡易的方法是指另這個類別物件。– Light it; – Light A;

• Light 我們稱為類別。• 上訴的 it 或 A 物體,我們稱為 Light 類別的物

件。

Page 11: VC  程式設計  Base I

Confidential

程式重複使用 - 方法 2加入成員物件

• 在自己的類別 (Class) 中加入所需的成員物件(member Object)

Page 12: VC  程式設計  Base I

Confidential

程式重複使用 - 方法 3繼承

• 繼承 (Inheritance)

• 一個子類別繼承父類別 (Super class) 我們稱為延生類別 (Derived class) 、或繼承類別 (Inherited class) 、或子類別(Sub class) 、或後代類別 (Child class)

• 如果子類別繼承了一個以上的父類別 ,則稱為 Multiple Inheritance( 多重繼承 )。

• 一個形狀類別中有許多功能,可以被新的圓形、方形、三角形等類別繼承來使用。

Page 13: VC  程式設計  Base I

Confidential

函數 & 變數

成員函數 (Member function)

成員變數 (Member variable)

Page 14: VC  程式設計  Base I

Confidential

添加新函數

• 在三角形類別中,建立出新的功能,例如垂直翻轉成員函數 (Member function) 、水平翻轉成員函數。

Page 15: VC  程式設計  Base I

Confidential

Override function

• 子類別重新定義它所能看到的父類別中的 method(如 public, protected) 稱為覆寫 (Override) 。

Page 16: VC  程式設計  Base I

Confidential

• 所有 C 語言都需要宣告與定義才能使用。• 宣告 (Declaration) :

– 宣告的用意在於把變數或函數的名稱告知編譯器(Compiler) 。

– 宣告檔 (Header file) ,通常以 .h 作為附檔名!• 定義 (Definition) :

– 讓編譯器 (Compiler) 瞭解這個變數或函數已經存在於程式中的某個位置。也是讓編譯器製造出儲存空間給該變數或函數。

宣告 & 定義

Page 17: VC  程式設計  Base I

Confidential

函數宣告構造 (Function declaration syntax)

宣告 & 定義

變數宣告構造 (Variable declaration syntax)

Page 18: VC  程式設計  Base I

Confidential

宣告 & 定義

Page 19: VC  程式設計  Base I

Confidential

動態連結 (Dynamic link library)

Windows 三大動態連結檔協力廠商提供的動態連結檔

Page 20: VC  程式設計  Base I

Confidential

WindowsWindows 中的中的三大動態連結檔三大動態連結檔

• GDI32.dll (GDI32.lib)

• User32.dll (User32.lib)

• Kernel32.dll (Kernel32.lib)

• Commdlg.dll (Comdlg32.lib)

• Toolhelp.dll (TH32.lib)

20

Page 21: VC  程式設計  Base I

Confidential

協力廠商提供的動態連結檔

• PCI_M314.dll ( 先達 , Motion)

• PISODIO.dll ( 泓格 , IO)

• MultiCam.dll, EObjMs60d.dll…(Euresys, Vision)

• MapPro.dll ( 威嘉 , Barcode transfer)

Page 22: VC  程式設計  Base I

Confidential

綜合範例

Lighting Class

Page 23: VC  程式設計  Base I

Confidential

ComLighting 範例

Page 24: VC  程式設計  Base I

Confidential

CComPort 範例

Page 25: VC  程式設計  Base I

Confidential25

MFCMFC 介紹介紹

MFC Fundamentals & Architecture

Page 26: VC  程式設計  Base I

Confidential

What Is MFC?

Win32 API(SDK)

OLE ODBC

Windows BaseOS Services

Windows OS ServiceExtensions

Base MFCClasses

OLEClasses

ODBCClasses

MFC

Collections,Miscellaneous

Classes

Page 27: VC  程式設計  Base I

Confidential

MFC 構造 (Architecture)

• The Application Framework

• CWinApp Class

• CFrameWnd Class

• Documents and Views

• Document/View Interaction

• MFC Document Templates

Page 28: VC  程式設計  Base I

Confidential

The Application Framework

CWinApp CFrameWnd

CView

CDocument

CDocTemplateMYAPP.EXE

Page 29: VC  程式設計  Base I

Confidential

Documents and Views

DataData

Possible Views

017981687

5685446672

1971114595

805103592

5685446672

1971114595

Document

Page 30: VC  程式設計  Base I

Confidential

Document/View Interaction (for SDI)

Frame ObjectFrame Object

View ObjectView Object

GetDocument

GetActiveView

UpdateAllViews ,GetNextView

Document ObjectDocument Object

GetActiveDocument

AfxGetMainWnd() AfxGetApp()

Page 31: VC  程式設計  Base I

Confidential

General Approach to MFC Programming

CObject

CCmdTarget

CWnd

CYourViewCMainFrameCYourApp CYourDocCYourDlg

CViewCFrameWnd CDialog

CDocTemplate

CWinAppCWinApp

CDocument

Framework classes

CWinThreadCWinThread

Page 32: VC  程式設計  Base I

Confidential

Icon Resource

Page 33: VC  程式設計  Base I

Confidential33

Page 34: VC  程式設計  Base I

Confidential

程式開發環境安置

安裝 VC

設定關連環境程式製作

Page 35: VC  程式設計  Base I

Confidential

• http://www.freegroup.org/2010/06/visual-studio-2010-express/

• http://www.microsoft.com/express

Page 36: VC  程式設計  Base I

Confidential

安裝 VC

Page 37: VC  程式設計  Base I

Confidential

Page 38: VC  程式設計  Base I

Confidential

• 索取序號• 事實上,當你安裝完成

後還需要做一個動作:註冊。不用擔心,這只是微軟的一個驗證程序而已,過程完全免費。

Page 39: VC  程式設計  Base I

Confidential

環境設定

Page 40: VC  程式設計  Base I

Confidential40

Visual C++ Visual C++ 範例範例

Hello WordHello Word 範例範例

Page 41: VC  程式設計  Base I

Confidential

Page 42: VC  程式設計  Base I

Confidential

Page 43: VC  程式設計  Base I

Confidential

Page 44: VC  程式設計  Base I

Confidential

Page 45: VC  程式設計  Base I

Confidential

Page 46: VC  程式設計  Base I

Confidential

Debug Tools in Visual C++

Build controls

Standard

Debug

Watch

WizardBar

Step Into (F11)

Step over (F10)

Go (F5)

Build (F7)

Page 47: VC  程式設計  Base I

Confidential

Page 48: VC  程式設計  Base I

Confidential

ClassWizard (Ctrl+W)

Page 49: VC  程式設計  Base I

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

Page 50: VC  程式設計  Base I

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);• }

Page 51: VC  程式設計  Base I

Confidential

Page 52: VC  程式設計  Base I

Confidential

Page 53: VC  程式設計  Base I

Confidential53

Q&AQ&A