WIN32編程
1.What should I know beforehand?
-
the concept of the window
-
the concept of the event drive
-
the applicant of messege in coding
-
object and the histance
2.Window
window is the base unit(單元) in Win applicant
3.Message
Message is used to describe the event happening.For a example, when the mouse knickdown,there will be a message to record(記錄) it. It will be convenient especially in programing the Interactive program(交互式程序).
4.Handle & Windows message
Handle is the basics of the whole windows programing.It is expressed by a PVOID type. Every Handle can mark the Unique object in application.The unique object can be a window,a button, a icon,a scroolbar,a outputDC(輸出設備) or a file...The application can visit
the information by Handle.
5.Here are some useful kinds of Handles
HWND
HISTANCE
HCURSOR
HDC
HBITMAP
HICON
HMENU
HFILE
HPEN
HBRUSH
HFONT
6.The construction of a windows message
7.Some frequent Windows Message
-
WM_LBUTTONDOWN
-
WM_KEYDOWN
-
WM_CHAR
-
WM_CREATE 調用CreateWindow時產生的消息
-
WM_CLOSE
-
WM_DESTROY
-
WM_PAINT ★★★
8.The construction of a WIn program source ".cpp"
入口函數WinMain+窗口函數Winproc
1. WinMain: do some definition and initiation.And it will produce the message circulation.The message ciculation is the kernel of the whole project.
2.WinProc: It is consist of a series of "switch".
9.Some datastructure
MSG
WNDCLASSEX
RECT
POINT
10.GDI,Graphics Device Interface
11.DC,Device context設備描述表
There exits three types of the DC
-
Display:屏幕顯示
-
Print:打印機
-
Storage:Bitmap
-
Message:設備數據恢復
12.DC & the relevant function
13.Here are three ways to Get the Device enviorment
-
BeginPaint(hwnd,&ps)
-
GetDC
-
GetDCEx
14. The Universal Applied (普遍應用的) Mapping(映射) mode
MM_TEXT
15.TextOut()
16.鍵盤輸入——>掃描碼——>虛擬碼
17.按鍵分爲系統按鍵和非系統按鍵
18.光標cursor 插字符caret
19.ScreenToClient()屏幕座標轉化爲窗口座標
20.Resource資源的使用
Resource.rc 定義資源,設定資源ID名稱,屬性,樣式等。
-
CHECKED
-
INACTIVE
-
MENUBARBREAK
-
GRAYED
-
WM_COMMAND消息中字參數wParam中包含選中菜單項的標識
-
加載菜單在窗口類中wndclass.lpszMenuname = ? OR 在創建窗口時加載菜單,此時要用到LoadMenu函數,在CreateWIndow的參數中設置菜單 OR 使用SetMenu動態加載菜單,提高靈活性。
-
EnableMenuItem()禁用或者激活菜單項 EnableMenuItem(hmenu,IDM_OPEN,MF_BYCOMMAND|MF_DISABLED)
-
SendMessage(hWnd,WM_DESTROY,0,0);這個向窗口發送消息的函數經常使用
21.內存環境的黃建及初始化工作一般通過相應消息WM_CREATE完成
22.位圖輸出至屏幕有兩個函數
-
Bitblt保持原始尺寸
-
StretchBlt()多了一個目標尺寸
MFC編程
1.CWnd類和消息映射機制隱藏了窗口函數WndProc,onMessage()
2.以Afx開頭的函數除了數據庫類函數和DDX函數外,都表示這是一個全局函數
3.控件
4.爲控件添加消息映射
-
聲明:afx_msg void OnBnclickedButton1();
-
消息映射:ON_BN_CLICKED(IDC_BUTTON1,&CAboutDlg::OnClickedButton1);
-
函數體:實現聲明
5.在應用程序中使用控件的時候,往往要獲取控件的指針或者控件的名稱。
CEdit *pEdit = (CEdit*)GetDlgItem(IDD_EDIT1);
默認返回的控件基類是CWnd,所以使用的時候往往要進行強制類型轉換。
6.UpdateData的作用
當爲控件添加變量且變量的類型是value的時候,控件中的內容和變量的值可能不一樣,所以先、
UpdateData(FALSE)刷新,當修改完變量的值之後,再UpdateData(TRUE)再次刷新,這樣在對話框中心的value就能顯示出來了。