Professional Documents
Culture Documents
LP TRNH WINDOWS
Gii thiu v MFC, Visual C++ 6.0 Cc loi ng dng trong Visual C++ 6.0 X l chut, bn phm MessageBox
Trn Ngc Bo Email: tnbao.dhsp@gmail.com
NI DUNG
Gii thiu v MFC Microsoft Visual C++ 6.0 Cc loi ng dng trong windows Chng trnh MFC u tin X l chut v bn phm Message Box
NI DUNG
Gii thiu v MFC Microsoft Visual C++ 6.0 Cc loi ng dng trong windows Chng trnh MFC u tin X l chut v bn phm Message Box
NI DUNG
Gii thiu v MFC Microsoft Visual C++ 6.0 Cc loi ng dng trong windows Chng trnh MFC u tin X l chut v bn phm Message Box
NI DUNG
Gii thiu v MFC Microsoft Visual C++ 6.0 Cc loi ng dng trong windows Chng trnh MFC u tin X l chut v bn phm Message Box
NI DUNG
Gii thiu v MFC Microsoft Visual C++ 6.0 Cc loi ng dng trong windows Chng trnh MFC u tin X l chut v bn phm Message Box
CWinThread
CWnd
CWinApp
CFrameWnd
CMyApp
CMainWindow
lpCmdLine,
MyRegisterClass(hInstance); Hin th ca s // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) Message Loop { return FALSE; } // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
ng k lp ca s
WinMain
ng k lp ca s To lp ca s Hin th ca s Message Loop
CMyApp
BOOL CMyApp::InitInstance () { m_pMainWnd = new CMainWindow; m_pMainWnd->ShowWindow (m_nCmdShow); m_pMainWnd->UpdateWindow (); return TRUE; }
ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style wcex.lpfnWndProc wcex.cbClsExtra wcex.cbWndExtra wcex.hInstance wcex.hIcon wcex.hCursor wcex.hbrBackground wcex.lpszMenuName wcex.lpszClassName wcex.hIconSm return RegisterClassEx(&wcex); }
= CS_HREDRAW | CS_VREDRAW; = (WNDPROC)WndProc; = 0; = 0; = hInstance; = LoadIcon(hInstance, (LPCTSTR)IDI_BAI02); = LoadCursor(NULL, IDC_ARROW); = (HBRUSH)(COLOR_WINDOW+1); = (LPCSTR)IDC_BAI02; = szWindowClass; = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
To lp ca s
WinMain
ng k lp ca s To lp ca s Hin th ca s Message Loop
CMainWindow
CMainWindow::CMainWindow () { Create (NULL, _T ("The Hello Application")); }
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; }
Hm to lp ca s
CMainWindow
CMainWindow::CMainWindow () { Create (NULL, _T ("The Hello Application")); }
BOOL Create (LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle = WS_OVERLAPPEDWINDOW, const RECT& rect = rectDefault, CWnd* pParentWnd = NULL, LPCTSTR lpszMenuName = NULL, DWORD dwExStyle = 0, CCreateContext* pContext = NULL)
Cc tham s trong hm to lp ca s
Thuc tnh
lpszClassName dwStyle rect pParentWnd lpszMenuName dwExStyle pContext
Tn lp ca s Kiu dng ca s Kch thc v v tr ban u ca ca s Ca s cha, NULL ca s khng c ca s cha Thc n lin quan n ca s, NULL ngha lca s khng c Menu Kiu m rng ca ca s S dng trong ng dng Documents/Views
ngha
lpszWindowName Tiu ca s
ngha
Hin th ca s
WinMain
ng k lp ca s To lp ca s Hin th ca s Message Loop
CMainWindow
BOOL CMyApp::InitInstance () { m_pMainWnd = new CMainWindow; m_pMainWnd->ShowWindow (m_nCmdShow); m_pMainWnd->UpdateWindow (); return TRUE; }
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; }
Vng lp v x l thng ip
while (GetMessage (&msg, NULL, 0, 0)) { ng k TranslateMessagelp ca s (&msg); To lp ca s DispatchMessage (&msg); } Hin th ca s
Message Loop LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_PAINT: hdc = BeginPaint (hwnd, &ps); Ellipse (hdc, 0, 0, 200, 100); EndPaint (hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam); }
WinMain
CMainWindow
Message Map
V d:
WM_PAINT s c chuyn thnh OnPaint WM_MOUSEMOVE s c chuyn thnh OnMouseMove WM_LBUTTONDOWN s c chuyn thnh OnLButtonDown
Ci t x l Message
BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd) ON_WM_PAINT () ON_WM_LBUTTONDOWN() END_MESSAGE_MAP () Void CMainWindow::OnPaint() { } Void CMainWindow::OnLButtonDown(UINT nFlags, CPoint point) { }
NI DUNG
Gii thiu v MFC Microsoft Visual C++ 6.0 Cc loi ng dng trong windows Chng trnh MFC u tin X l chut v bn phm Message Box
X l thng ip chut
Message WM_LBUTTONDOWN WM_LBUTTONUP WM_LBUTTONBLCLK WM_RBUTTONDOWN WM_RBUTTONUP WM_RBUTTONBLCLK WM_MOUSEMOVE Afx function
afx_msg void OnLButtonDown(UINT, CPoint) afx_msg void OnLButtonUp(UINT, CPoint) afx_msg void OnLButtonDblClk(UINT, CPoint)
afx_msg void OnRButtonDown(UINT, CPoint) afx_msg void OnRButtonUp(UINT, CPoint) afx_msg void OnRButtonDblClk(UINT, CPoint) afx_msg void OnMouseMove(UINT, CPoint)
Kt qu x l thng ip chut
Kt qu x l thng ip chut
NI DUNG
Gii thiu v MFC Microsoft Visual C++ 6.0 Cc loi ng dng trong windows Chng trnh MFC u tin X l chut v bn phm Message Box
Chn Cancel
MB_ICONSTOP
MB_ICONEXCLAMATION
to lp hp thng bo vi Icon nh trn ta s dng hm MessageBox nh sau: int nRes = MessageBox (Do you want to continue ?, My Application, MB_YESNO |
MB_ICONQUESTION )
to lp hp thng bo vi Icon nh trn ta s dng hm MessageBox nh sau: int nRes = MessageBox (Do you want to save the changes to Document1 ?, Microsoft Office Word, MB_YESNOCANCEL |
MB_ICONEXCLAMATION )