Presentation is loading. Please wait.

Presentation is loading. Please wait.

Windows 程式設計 (使用 C++ / C#)

Similar presentations


Presentation on theme: "Windows 程式設計 (使用 C++ / C#)"— Presentation transcript:

1 Windows 程式設計 (使用 C++ / C#)
PART 2 徐振家 July 2004 Copyright 2004 C.H.

2 課程摘要 Part 1 Part 2 Part 3 Part 4 前言 UI 基礎觀念 C# Windows Form 程式設計
MFC 程式設計 ATL/WTL 程式設計 Part 4 Process and thread control in Win32 native Process and thread control in .Net Copyright 2004 C.H.

3 C# Windows Form 程式設計 .Net Framework version 1.1 Copyright 2004 C.H.

4 前言 課程目的 課本 可以快速地建構基本的 Windows 程式 了解基本的觀念 學習各種 controls 的用法
Programming Microsoft Windows with C# Charles Petzold Microsoft Press 2002 Copyright 2004 C.H.

5 實機演練 簡單的計算機程式 習題 VisualStudio 2003 IDE 的操作 處理 control 的 event
Form layout 如何設定 properties 處理 control 的 event Trace 自動產生的 code 習題 以這個程式為基礎,做一個 .Net 版的小算盤 Copyright 2004 C.H.

6 GDI 與 GDI+ 視窗上所有的東西都是畫上去的 Windows GDI .Net 使用 GDI+
包括文字、圖形、各種 control … Windows GDI Graphics Device Interface,也稱為繪圖引擎 與裝置無關的繪圖 API 在畫布 (Drawing Canvas) 上畫圖,又稱裝置內容 (Device Context) Win32 系統皆相容,但較舊的系統會有些限制 (e.g. DC 佔的記憶體不得超過 16KB) .Net 使用 GDI+ GDI 的加強版本 (特別是繪圖效果與記憶體管理) 未來將與 DirectX 系列合流提供硬體加速功能 Copyright 2004 C.H.

7 GDI+ 的基本觀念 GDI+ 並不限用於 .Net GDI+ 是物件導向式的 GDI+ 並未附在 Windows 中
Native code 依然可以使用 GDI+,許多 C++ 程式均利用 GDI+ 來顯示圖檔 (e.g. JPEG) GDI+ 是物件導向式的 繪圖的行為必須透過 Graphics 物件而為之 繪圖過程中的資料必須透過物件來存放 / 串流 (serialization) GDI+ 並未附在 Windows 中 你仍必須安裝 .Net Runtime 或自行將 gdiplus.dll 加到你的 setup 程式中才能使用 GDI+ Copyright 2004 C.H.

8 實機演練 直接在 client area 畫文字 MessageBox 的使用 hellowin1.cs hellowin2.cs
Paint event handler Font, Brush, Coordinates hellowin3.cs OnPaint() 的使用 課本第四章範例選讀 Reflection csc /target:winexe *.cs Copyright 2004 C.H.

9 基本的繪圖類別 Point, PointF Size, SizeF Rectangle, RectangleF
GDI+ 才支援浮點數的結構,GDI 沒有 Color, SystemColors GDI+ 有條件支援 alpha channel,GDI 沒有 Pen 畫線和弧線用的 Brushes 畫文字、將某個區域塗顏色 Copyright 2004 C.H.

10 Graphics Object Graphics 物件不能 new,也不能繼承,你只能從其他人手中拿來
OnPaint 或 Paint event handler 在 control 或 form 上 CreateGraphics PrintPage event handler Owner-draw 的 control 的某些 event 會主動傳一個來 Graphics.FromImage PrinterSettings.MeasurementGraphics 從 native Win32 拿 Graphics.FromHwnd 或 Graphics.FromHdc Copyright 2004 C.H.

11 基本的繪圖 GDI+ 是 stateless programming 課本第五章範例
仍然有些繪圖模式可以 globally set 如 anti-alias, image interpolation, … 課本第五章範例 畫線、畫弧 畫矩形、畫橢圓 (圓形是橢圓的一種)、畫派圖 多邊形與著色 Copyright 2004 C.H.


Download ppt "Windows 程式設計 (使用 C++ / C#)"

Similar presentations


Ads by Google