9/13/2011 ክኧ 0ኈ ኞኤ ኛW ኛW ኘW ϯ@WINDOWS 9/13/2011 Н trình Windows ዕ ዛዘ: (2-1-0-4) ± Lý ዅ: 30 ዅ ± Bài ኼ: 15 ዅ ዌ ኹ tiên ዅ: ± Ngôn ዟ ኼ trình C, C++ ± ኼ¿ዛዔ¯ዎዛዘ ኼ¿ 2 9/13/2011 г dung ዛዓ ዐ quan ኼ trình Windows (4LT + 1BT) ዛዓ ኼ trình Windows VC++/MFC (15LT + 6BT) ዛዓ͵Ǥዒ ዎ ዚ ¯ nâng cao ± ዛ ዉ liên ዅ ¯ዒ (DLL) (3LT + 2BT) ± ዏ (Thread) (3LT + 2BT) ± Windows Socket (2LT + 2BT) ዛዓ4 ዠዜዙ ȋ͵ + 2BT) Bài ኼ ዔ ኼ¿ 3 9/13/2011 Tài Ъ tham И Ivor ǯǡΪΪʹͲͳͲ Programming Windows with MFC 2nd VC++ and MFC Programming 2nd Sams teach yourself VC++ in 21 days MSDN http://www.functionx.com/visualc/ ኼ¿ 4 9/13/2011 мд б quan Н trình Windows 1.1 ዓ ኼ trình Windows (1T) 1.2 ኸ trúc ዚ ዛዓ trình Windows (2T) 1.3 Microsoft Foundation Classes (MFC) 1.4 ኼ trình Windows ዔ VC++ 2008 (1LT + 1BT) ኼ¿ 5 9/13/2011 1.1 д И Ч Н trình Windows Windows: ¯ዏ ዌ ዠ quan, tài nguyên ¯ ኮ ዙ thân ዉ ዔ ዛዕ ዞ ዙ thông qua giao ዉ ¯ዏ ዌ Windows Các ዜ ዙ có giao ዉ ዛዓ tác ዎ nhau: ± Windows, title bar, toolbar, menu bar, status bar ± Thanh ዠ ¯ዓ: File, Edit, Tool, Helpǥ ± ዒ : ዛዕ ዜ ¯ chung: Edit Control, Button Control, CheckboxǥǤ ኼ¿ 6 ̴ ȌǢȀȀ ¯ዋ Ǥ m_listbox- >AddString( "Ong A" ); m_listbox- >AddString( "Ba B" ); m_listbox- >AddString( "Co C" ); ȀȀዒȋỵ¯ዉኹዞ¯ዛዘ ዌዝ m_edit->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, CRect(200, 100, 280, 120), this, 1010); return 0; } ኼ¿ 215 215 9/13/2011 еȂ ÀкȋЦȌ void CControlDemoDlg::OnLbnSelchangeListBox() { CString info; int iSel = m_listbox->GetCurSel(); ȋαα̴ȌȀȀØ ×ዠ ዌ L6HO 7KuFKӑQPөFÿҫXWLrQ m_listbox->GetText(iSel, info ); m_edit->SetWindowText( info); } ኼ¿ 216 216 9/13/2011 ʹǤǤͶǤͶǤеȋͳȌ ዔý ȋዒኼኹዑዘኼዔ ኹዞ ዛዔ Ȍ ȋȌ Hàm Create() BOOL Create ( ǡȀȀ const RECT& rect, CWnd* pParentWnd, UINT nID ); ǣ ǣ ± ̴ ǣ ዋኼ ዊ¯ዛዘ ዌዝ Ǥ ± ̴ ǣዛ ዋዛዕዠ ± ̴ǣዛ ×ኼዒዔ ኼ¿ 217 217 9/13/2011 еȋʹȌȂ Hàm thành viên ዛዓዠ nhóm: ± General Operations: int GetCountȋȌዎዙ ዌ ǡǡǥ GetLBText() ኸ ዚኹዞ ± String Operations: AddString, DeleteString, InsertString, ResetContentǡǥ Xem MSDN ኼ¿ 218 218 9/13/2011 еȋ͵ȌȂ пýсЪ ዠዉ²ዞý ON_CBN_SELCHANGE(IDC_COMBO1, &CControlDemoDlg::OnCbnSelchangeCombo1) ኼ¿ 219 219 9/13/2011 еȋͶȌȂ Àк m_pComboBox->Create( WS_CHILD|WS_VISIBLE|WS_VSCROLL|CBS_DROPDOWNLIST, CRect(10,10,200,100), pParentWnd, IDC_COMBO1); void CControlDemoDlg::OnCbnSelchangeCombo1() { CString info; int iSel = m_Combobox.GetCurSel( ); if (iSel == LB_ERR) // no selection iSel = 0; m_pComboBox- >GetLBText( iSel, info ); m_edit->SetWindowText( info ); } ኼ¿ 220 220 9/13/2011 ʹǤǤͶǤͷǤеȋͳȌ ዔý¯ ±ዠ ዌ ዋȋ£ȀȌዒ¯ ¯Ǥ ዛዕ¯°ዔዒȋ¯ዉ ዋዎ ዌȌ Hàm Create() virtual BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID ); ኼ¿ 221 221 9/13/2011 CSpinButtonCtrl (2) Ȃ Hàm thành viên CWnd* SetBuddy (CWnd* pWndBuddy); ȀȀኊ¯ዋ¯ዎዛዘዒኼȋȌ¯ ዑዘ CWnd* GetBuddy( ); ȋȌǢȀȀዅኼዛዔ £ void SetRange ( int nLower, int nUpper); ȀȀኊ¯ዋዋዅ² ዚï£ Ǥ void GetRange ( int &nLower, int &nUpper); ȋȌǢȀȀ0ዋï£ int GetPos( int &nPos); ኼ¿ 222 222 9/13/2011 CSpinButtonCtrl (4) Ȃ Àк int CControlDemoDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; m_editAge.Create ( WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER, CRect( 135, 45, 190, 65 ), this, IDC_EDIT); static CSpinButtonCtrl m_spinAge; m_spinAge.Create ( WS_CHILD | WS_VISIBLE | UDS_ARROWKEYS | UDS_SETBUDDYINT | UDS_ALIGNRIGHT, CRect(0,0,1,1), this, IDC_SPIN); ̴ǤȋͳȌǢȀȀዛዔ £ m_spinAge.SetRange( 15, 80 ); m_spinAge.SetBuddy ( &m_editAge ); return 0; } ኼ¿ 223 223 9/13/2011 ʹǤǤͶǤǤеȋͳȌ ዔýዛዘ ዛዓዠ ዒ Àǣ ± Tick Marks ± ǣ ± Orientation: Horizontal & vertical Hàm Create() virtual BOOL Create( ǡȀȀ̴ǡ̴ǡǥ const RECT& rect, CWnd* pParentWnd, UINT nID ); ኼ¿ 224 224 9/13/2011 еȋʹȌȂ Hàm thành viên void SetRange(int nMin, int nMax, BOOL bRedraw = FALSE); void SetPos(int nPos); int GetPosȋȌǡǥǤ CWnd* SetBuddy (CWnd* pWndBuddy); CWnd* GetBuddy( ); ȋȌǢȀȀኸዋዛዔ ȋ ȌǢȀȀዅኼዛዔ void SetRangeMin(int nMin, BOOL bRedraw = FALSE); GetRangeMin(); void SetTicFreq(int nFreq); Xem MSDN ኼ¿ 225 225