Windows Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Windows Programming

Description:

Windows Programming swpark_at_hufs.ac.kr – PowerPoint PPT presentation

Number of Views:70
Avg rating:3.0/5.0
Slides: 471
Provided by: Sang70
Category:

less

Transcript and Presenter's Notes

Title: Windows Programming


1
Windows Programming
  • ? ? ?
  • swpark_at_hufs.ac.kr
  • ???????? ???????

2
??
3
??
  • ???????
  • MFC? ??
  • MFC? ?? C? ??

4
???? ??? ?? ??
  • ????? ??? ??
  • ??? -gt ????? -gt ????
  • ?? ?? ?????
  • 1970?? - 1980??
  • ?????? ??
  • ??? ??? ??
  • ???? ??? ??
  • 1980??

5
???????
?? ??? ??
???
???
6
????? ?? ??(1)
  • ???
  • ???(???? ????)? ?????(??)? ??? ???? ??
  • ?? ??? ??(ADTabstract data type)
  • ???? ???? ??
  • ??(inheritance)
  • ?? ???(dynamic binding)
  • cf) Static binding
  • ???(polymorphism)
  • Overloading ??? ??? ?? ?? ??
  • Overriding ?? ????? ??? ??? ?? ????? ? ??
  • Template ??? ??? ?? ??? ??? ??

7
MFC? ?? C? ??
  • ???
  • ??
  • ??? ? ???
  • Virtual Function? ??? ?? ???

8
?????
  • ??? ??? ? ?? ??? ??
  • ?? ?? (member data)
  • ????? (member function)

???
???
?????
9
???? ??(1)
  • ??? ?? ??? ? ?? ??
  • ??? ??
  • ?? ??(name conflict) ??
  • ?? ??? ???
  • virtual base class? ??

10
???? ??(2)
  • class B virtual public A
  • ...
  • class C virtual public A
  • ...

A int x
B int y
C int z
D int z
11
???(1)
  • ???(constructor) ??
  • ??? ??? ???? ??
  • ??? ??
  • new ?(heap)? ?? ??
  • ???? ??(stack)? ?? ??
  • ???? ???? ?? ??? ?? ??
  • ???? ??? ??? ?? ??? ? ??? ??? ????? ??

12
???(2)
  • AA(int n) m_nNo(n)
  • BB(int i) A( i )
  • ptr new char i

A
int m_nNo
B
char ptr
A pA new B(3)
3
500
500
?/??/?? ??
? (heap) ??
13
???(1)
  • ???(destructor)? virtual ???
  • ???? ?? ??? ??? ??? ??? ?? ??
  • ? ??? new ?? ???? ???? ?? ??? ????? ??? ??? ??.

14
???(2)
  • A ptr new A
  • delete ptr
  • ptr new B(3)
  • delete ptr lt- ?? ??. A? ???? ???.

3
500
500
????? ??? (garbage)
?/??/?? ??
? (heap) ??
15
Virtual Function(1)
  • ?? ???(dynamic binding)
  • ????? ?? ?? ?? ??? ??? ??
  • vitual function table(hidden pointer)
  • ?? ???(static binding)

16
Virtual Function(2)
DrawObj
  • DrawObj p_obj
  • p_obj new Point
  • p_obj-gtDraw()
  • p_obj new Line
  • p_obj-gtDraw()
  • p_obj new PolyLine
  • p_obj-gtDraw()

int a
virtual Draw()
Point
Line
int x, y
Point start, end
virtual Draw()
virtual Draw() virtual Calc()
PolyLine
Point5 pt
virtual Draw()
17
Virtual Function - ??? ??
  • p_obj new DrawObj
  • p_obj-gtDraw()

p_obj new PolyLine p_obj-gtDraw()
50
250
100
350 430
vtbl 50
vtbl 180
virtual function table
int a
int a
180
550 430
Point start
Point end
p_obj new Line p_obj-gtDraw()
Point0 pt
250
DrawObjDraw
Point1 pt
350
pointer of virtual function table
Point2 pt
vtbl 100
LineDraw
Point3 pt
int a
430
LineCalc
Point4 pt
Point start
Point end
550
PolyLineDraw
Code ??
18
Virtual Function ?? ?
  • CObList list
  • DrawObj p_obj
  • p_obj new Line
  • list.AddTail(p_obj)
  • p_obj new Point
  • list.AddTail(p_obj)
  • . . . .
  • POSITION pos list.GetHeadPosition()
  • while(pos ! NULL)
  • p_obj (DrawObj)list.GetNext(pos)
  • p_obj-gtDraw()

List
Point
19
MFC ??
20
??
  • SDK? MFC? ??
  • MFC ??? ??
  • AppWizard? ??? ???? ??
  • Develop Studio ???
  • Hungarian ???

21
Windows API
  • Applicatoin Programming Interface
  • Windows System Calls
  • Windows 3.1
  • Win16 API
  • Windows 95/NT
  • Win32 API
  • C ?????

22
SDK ?????
  • SDK(Software Development Kit)
  • ??? ?????? ?? ?? ?? ?? ?????? ???? ?? ???????? ??
    ??? ????? ???
  • ??? ?????? ???? ??? ? ?? ???? ?? (??? API)
  • C ?????

23
???? ??? ?
  • ???(message)?
  • ????? ???? ???? ??
  • ?? (winuser.h)
  • ??? ?(queue)
  • ??? ????? ??? ??

???? ??? ???? ????? ?? ???? ???
?? ???? ??? ?? ???.
24
??? ??, ??? ????
  • ??? ??
  • ??? ??? ???? ??? ??? ??? ?? ??
  • ??? ????
  • ???? ?? ??

????
?? ????
???? ??? ???? ?? ??? ???? ??? ????? ????.
25
???? ?? ??
  • Message-driven operations
  • int WinMain(HINSTANCE ......)
  • . . .
  • InitApplication(hInstance)
  • InitInstance(hInstance)
  • . . .
  • . . .
  • while(GetMessage(....))
  • . . .
  • DispatchMessage(. . .)
  • . . .

???? ??? ???? ????? ?? ???? ??? ?? ???? ??? ??
???.
msg
??? ?
??
26
SDK ????? ?
  • include windows.h // SDK? API? ?? ??, ????
    ??? ?? ??
  • include generic.h // ? ???? ??? ??? ??? ????
    ???
  • // ??? ?? ??
  • HINSTANCE hInst // ???? ??? ?????.
  • HWND hMainWnd // ?? ??? ??? ??? ??.
  • int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE
    hPrevInstance,
  • LPSTR lpCmdLine, int nCmdShow)
  • MSG msg
  • if (!hPrevInstance)
  • if (!InitApplication(hInstance)) // ???
    ???? ????.
  • return FALSE
  • hInst hInstance // ???? ??? ?? ???
    ?????.
  • if (!InitInstance(hInstance, nCmdShow)) // ??
    ???? ????.
  • return FALSE

27
  • // ??? ??? ????.
  • while (GetMessage(msg, NULL, 0, 0))
  • TranslateMessage(msg)
  • DispatchMessage(msg)
  • return (msg.wParam)

28
InitApplication
  • BOOL InitApplication(HINSTANCE hInstance)
  • WNDCLASS wc // WNDCLASS? ??? ???? ??? ???
    ?????.
  • wc.style NULL
  • wc.lpfnWndProcMainWndProc // ???? ??? ????
    ??? ????
  • wc.cbClsExtra 0
  • wc.cbWndExtra 0
  • wc.hInstance hInstance // ???? ?? ?????
    ??? ????.
  • wc.hIcon LoadIcon(NULL, IDI_APPLICATION)//
    ? ???? ??? ??
  • wc.hCursor LoadCursor(NULL, IDC_ARROW) //
    ? ???? ?? ??
  • wc.hbrBackground GetStockObject(WHITE_BRUSH)
    // ??? ??
  • wc.lpszMenuName EX_Menu // ? ???? ???
    ????
  • wc.lpszClassName EX_WClass // ? ???? ???
    ??? ????.
  • return RegisterClass(wc) // ? ??? ????
    ????.

29
InitInstance
  • BOOL InitInstance(HINSTANCE hInstance, int
    nCmdShow)
  • HWND hWnd
  • hMainWnd hWnd CreateWindow(
  • EX_WClass, // ????? ???? ??? ???
    ??
  • EX Program, // ???? ???? ????.
  • WS_OVERLAPPEDWINDOW, // ???? ???? ????.
  • CW_USEDEFAULT, // ???? ?? X ??
  • CW_USEDEFAULT, // ???? ?? Y ??
  • CW_USEDEFAULT, // ???? ?
  • CW_USEDEFAULT, // ???? ??
  • NULL, // ?? ???? ??
  • NULL,
  • hInstance, // ? ???? ?? ????? ??
  • NULL
  • )
  • if (!hWnd) return FALSE // ???? ?????
  • ShowWindow(hWnd, nCmdShow) // ?? ???? ???
    ???? WM_PAINT ??
    UpdateWindow(hWnd) // WM_PAINT ???? ??
    ??????.
  • return TRUE

30
??? ???(1)
  • WS_OVERLAPPED ??? ? ?? ???? ????.
  • WS_SYSMENU ???? ??? ??? ???.
  • WS_CAPTION ???? ????? ????.
  • WS_THICKFRAME ???? ????? ????? ??.
  • WS_MINIMIZEBOX ?? ??? ??? ???? ???? ???.
  • WS_MAXIMIZEBOX ?? ??? ??? ???? ???? ???.
  • WS_CHILD ?? ???? ?? ???? ????.
  • WS_VISIBLE ???? ??? ??? ???? ??? ??.
  • WS_BORDER ???? ???? ???.
  • WS_MAXIMIZE ???? ?? ?? ??? ????.
  • WS_MINIMIZE ???? ??? ???? ????.
  • WS_HSCROLL ???? ?? ????? ?? ????.
  • WS_VSCROLL ???? ?? ????? ?? ????.

31
??? ???(2)
  • WS_POPUP ?? ???? ????. ??? WS_CHILD?
  • ?? ??? ? ??.
  • WS_CLIPSIBLINGS ?? ??? ?? ????? ??? ??? ??
  • ? ??? ?? ???? ?? ??? ?? ???
  • ? ???? ???? ???? ??. ? ????
  • ?? ??? ?? ?? ????? ?? ? ???
  • ? ???? ??? ??? ? ??.
  • WS_CLIPCHILDREN ?? ???? ???? ??? ?? ???? ?
  • ??? ????. ?? ???? ??? ?? ??
  • ? ??.
  • define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED
    WS_CAPTION \
  • WS_SYSMENU WS_THICKFRAME \
  • WS_MINIMIZEBOX WS_MAXIMIZEBOX)

32
??? ???? MainWndProc
  • long APIENTRY MainWndProc(HWND hWnd, UINT
    message, WPARAM wParam, LPARAM lParam)
  • switch (message)
  • case WM_COMMAND // ???? ?? ??? ???? ????
    ???
  • case ID_FILE_EXIT
  • SendMessage(hWnd, WM_CLOSE, 0, 0)
  • break
  • case WM_PAINT // ???? ??? ??? ????? ? ?
    ???? ???
  • HDC hDC
  • PAINTSTRUCT ps
  • hDC BeginPaint(hWnd, ps)
  • TextOut(hDC, 10, 10, Hello, everybody,
    16)
  • EndPaint(hWnd, ps)
  • break

33
  • case WM_DESTROY // ???? ???? ??? ???? ???
  • PostQuitMessage(0)
  • break
  • default // ???? ?? ???? ???.
  • return DefWindowProc(hWnd, message,
    wParam, lParam)
  • return 0

34
generic.h resource.h
  • generic.h
  • include resource.h
  • int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int)
  • BOOL InitApplication(HANDLE)
  • BOOL InitInstance(HANDLE, int)
  • long APIENTRY MainWndProc(HWND, UINT, WPARAM,
    LPARAM)
  • resource.h
  • define ID_FILE_EXIT 100

35
generic.rc
  • include "resource.h"
  • define APSTUDIO_READONLY_SYMBOLS
  • include "afxres.h"
  • undef APSTUDIO_READONLY_SYMBOLS
  • // Korean resources
  • if !defined(AFX_RESOURCE_DLL)
    defined(AFX_TARG_KOR)
  • ifdef _WIN32
  • LANGUAGE LANG_KOREAN, SUBLANG_DEFAULT
  • pragma code_page(949)
  • endif //_WIN32
  • // Menu
  • EX_Menu MENU DISCARDABLE
  • BEGIN
  • POPUP "File"
  • BEGIN
  • MENUITEM "Exit",
    ID_FILE_EXIT
  • END
  • END
  • ifdef APSTUDIO_INVOKED
  • endif // Korean resources
  • ifndef APSTUDIO_INVOKED
  • // Generated from the TEXTINCLUDE 3 resource.

36
??(Handle)
  • ????? ???? ?? ?? ??
  • ?) ??? ?? (HWND)
  • ???? ?? ? ??? ?? ?? ???? ?? ????? ??? ??? ??
  • ?? ?? ??? H? ???.
  • UINT??? ???
  • define UINT HANDLE
  • define HANDLE HWND

37
??
  • BOOL ?, ??? ???? ???? int??? ??? ????
  • TRUE, FALSE ?? ???.
  • LPSTR char ??? ?? ???, ? char ? ??.
  • Long Pointer to STRing? ????.
  • LPCTSTR? const char ? ??.
  • HWND ????? ???? ?? ???? ???? ?? ??
  • HINSTANCE ????? ??? ?? ?????? ???? ?? ??
  • UINT unsigned int? ??. Win32??? 4 ???
  • HANDLE ?? ?? ??? ??? ???? ??. UINT? ??
    typedef ?? ??? ???. H? ???? ?? ??
  • ??? ?? ?????? typedef ??? ??? ?.
  • WPARAM UINT??? ???. ???? ???? ?? ??? ???.
  • LPARAM LONG???? ???. ???? ???? ?? ?? ??

38
?? ???(1)
  • WM_CREATE ???? ??? ? ????. ??? ??? CreateWindow
    API?
  • ????? ? ????. ? ??? ????? ??? ???
  • ???? ?? ?????. ?? ???? ??? ???.
  • WM_SIZE ???? ??? ???? ??. ? ???? ???? ? ??
  • WM_PAINT? ??? ????.
  • WM_PAINT ???? ??? ??? ????? ??? ????? ?? ??
  • ??? ?? ??? ???? ?????. InvalidateRect? ??
  • API? ????? ?? ????.
  • WM_COMMAND ???? ???? ??? ???? ??
  • WM_CLOSE ???? ???? ??? ???? ??(Close)? ??? ??.
  • DefWindowProc ??? WM_CLOSE ???? ???
  • WM_DESTROY ???? ??

39
?? ???(2)
  • WM_DESTROY ???? ???? ??? ????. ???? ?
  • ? ??? ????? ???? ??? ????
  • ??? ?? ????? ???? ??? ???.
  • ?? ???? WM_DESTROY ??? ?????
  • ? ????? PostQuitMessage ??? ????
  • ?? ?????.
  • WM_QUIT PostQuitMessage ??? ???? ? ???? ?
  • ??? ??? ?? ???? ??. ??? ???
  • ? ? ???? ???? GetMessage ??? ??
  • ?? FALSE? ?? ??? ??? ??? ???
  • ?? ????? ????.

40
MFC?
  • ??? ?????
  • ???? ?? (??? ??? ??)
  • ?????? ?????(application framework)
  • AppWizard
  • ClassWizard
  • Project Workspace

41
MFC ??
  • MFC? SDK API? ??? ???? ??? ????? ?? ?
  • ?? ????? SDK API? ?? ?? ? ??
  • Handle? ??? ??? ?

??????
MFC
SDK API
????
42
? MFC ???
  • ??? ??
  • ??? ??? ???? ???? ???? ??????
  • ??? ???? ??
  • ????? ??? ???
  • ?????? ?????(application framework) ??
  • ?? ?? ??
  • ?? ??? ???

43
Handle? ??? ?? - SDK(1)
  • RECT rc
  • GetClientRect(hWnd, rc)
  • MoveWinodw(hWnd, x, y, x2, y2, TRUE)

44
Handle? ??? ?? - MFC(1)
  • class CWnd public CCmdTarget
  • HWND m_hWnd
  • ...
  • BOOL GetClientRect(LPRECT lpRect)
  • BOOL MoveWindow(int x,int y,int width,int
    height,BOOL bDrawTRUE)
  • ...
  • BOOL CWndGetClientRect(LPRECT lpRect) --gt
    inline ??? ???? ?? ??? ???
  • GetClientRect(m_hWnd, lpRect)
  • BOOL CWndMoveWindow(int x, int y, int width,
    int height, BOOL bDraw)
  • MoveWindow(m_hWnd, x, y, width, height)

45
Handle? ??? ?? - SDK(2)
  • HDC hDC GetDC(hWnd)
  • Rectangle(hDC, 10, 10, 100, 100)
  • TextOut(hDC, 10, 10, Sample, 6)
  • ReleaseDC(hWnd, hDC)

46
Handle? ??? ?? - MFC(2)
  • class CDC public CObject
  • HDC m_hDC
  • . . . .
  • BOOL Rectangle(int x1, int y1, int x2, int y2)
  • BOOL TextOut(int x, int y, LPSTR lpStr, int
    size)
  • BOOL CDCRectangle(int x1, int y1, int x2, int
    y2)
  • Rectangle(m_hDC, x1, y1, x2, y2)
  • BOOL CDC TextOut(int x, int y, LPSTR lpStr, int
    size)
  • TextOut(m_hDC, x, y, lpStr, size)

47
SDK - ?? ?? ? ??
  • SDK
  • HDC hDC
  • hDC GetDC(hWnd) // ?? ??
  • Rectangle(hDC,10,10,100,100)
  • TextOut(hDC,10,10,Sample,6)
  • ReleaseDC(hWnd, hDC) // ??? ??? ????
    ??.

48
C? ??(???/???) - MFC
  • CClientDC dc(this)
  • dc.Rectangle(10, 10, 100, 100)
  • dc.TextOut(10,10,Sample,6)
  • // ??? ??
  • CClientDCCClientDC(CWnd pWnd)
  • m_hWnd pWnd-gtGetSafeHwnd() // ??? ??? ???.
  • m_hDC GetDC(m_hWnd) // ???? Device
    Context? ??
  • CClientDCCClientDC()
  • ReleaseDC(m_hWnd, m_hDC) // Device
    Context? ????.

49
C? ?? - ????
  • SDK
  • int MessageBox(HWND hWnd, LPCSTR lpszText, LPCSTR
    lpszTitle, UNIT flag)
  • InvalidateRect(HWND hWnd, LPCRECT lpRect, BOOL
    bErase)
  • MFC
  • int AfxMessageBox(LPCSTR lpszText, UINT nType
    MB_OK, UINT nIDHelp 0)
  • void InvalidateRect(LPCRECT lpRect, BOOL bErase
    TRUE)

50
C? ?? - ?? ??
  • ?? ?? ??(function overloading)
  • BOOL Rectangle(int x1, int y1, int x2, int y2)
  • BOOL Rectangle(LPCRECT lpRect)
  • ??? ?? ??(operator overloading)
  • CRect a, b, c
  • c.left a.left b.left c a b
  • c.right a.right b.right
  • c.top a.top b.top
  • c.bottom a.bottom b.bottom

51
MFC ??? ??
  • ?? ??? ???
  • ??? API ???
  • ?????? ????? ???
  • ? ?? ??? ???
  • ???? ?? ???

52
?? ??? ???
  • CObject ?? ???? ?? ???
  • ?? ?? ???
  • CException, CArchiveException, CFileException,
    CMemoryException, CNotSupportedException,
    COleException, CDBException, CResourceException,
    CUserException
  • ???(collection) ???
  • CByteArray, CWordArray, CDWordArray, CPtrArray,
    CObArray, CStringArray, CUintArray
  • CObList, CPtrList, CStringList
  • CMapPtrToWord, CMapPtrToPtr, CMapStringToOb,
    CMapStringToPtr, CMapStringToString,
    CMapWordToOb, CMapWordToPtr
  • ?? ??? ???
  • Cstring
  • ?? ???
  • CFile, CStdioFile, CMemFile
  • ?? ? ?? ??(time span) ???
  • CTime, CTimeSpan
  • ??
  • CPoint, CSize, CRect?

53
??? API ??? (1)
  • ?? ?????? ???? ???
  • CCmdTarget, CCmdUI, CWinThread, CWinApp
  • ?? ??? ?? ???
  • CSyncObject, CCriticalSection, CSemaphore,
    CMutex, CEvent, CSingleLock, CMultiLock
  • ?? ???? ?? ???
  • CCommandLineInfo, CWaitCursor
  • ?? Cmenu
  • CWnd ?? ??? ???? ?? ???
  • ??? ???(frame window)
  • CFrameWindow, CMDIFrameWindow, CMDIChildWnd
  • CWnd ?? ???
  • CDialog, ??? ???(CButton, CListBox, CEdit ?)

54
??? API ??? (2)
  • ?????
  • CFileDialog, CColorDialog, CFontDialog,
    CPrintDialog, CFindReplaceDialog
  • ????? DDX/DDV
  • CDataExchange
  • ??? ???
  • CButton, CBitmapButton, CComboBox, CEdit,
    CStatic, CScrollBar, CListBox, CCheckListBox,
    CVBControl
  • CAnimateCtrl, CDragListBox, CHeaderCtrl,
    CHotKeyCtrl, CImageList, CListCtrl,
    CProgressCtrl, CRichEditCtrl, CSliderCtrl,
    CSpinButtonCtrl, CStatusBarCtrl, CTabCtrl,
    CToolBarCtrl, CToolTipCtrl, CTreeCtrl
  • GDI ? ?? ?? ???
  • CPaintDC, CWindowDC, CClientDC, CMetaFileDC
  • CGdiObject, CFont, CPen, CBrush, CBitmap,
    CPalette, CRgn

55
?????? ????? ???
  • ??/? ?? ???
  • CDocTemplate, CSingleDocTemplate,
    CMultiDocTemplate
  • CDocument, Cview
  • ?? ?? ???(context-sensitive help)

56
? ?? ??? ???
  • ??? ?(enhanced view)
  • CScrollView, CFormView
  • ??? ? CEditView, CListView, CRichEditView,
    CTreeView
  • ?? ???
  • CSplitterWnd
  • ??? ?
  • CControlBar
  • CToolBar, CStatusBar, CDialogBar

57
???? ?? ??? (1)
  • OLE ??
  • OLE Document
  • CDocItem, COleServerItem, COleClientItem,
    COleDocument, COleLinkingDoc, COleServerDoc,
    COleIPFrameWnd
  • ??? ???(class factories)
  • COleObjectFactory, COleTemplateServer
  • ?????(automation)
  • ??? ??? ??
  • COleDataSource, COleDataObject, COleDropSource,
    COleDropTarget
  • OLE ???
  • COleControl, COlePropertyPage, COleControlModule,
    COleObjectFactoryEx, COleConnectionPoint,
    CPropExchange, CFontHolder, CPictureHolder

58
???? ?? ???(2)
  • ODBC ??
  • CDatabase, CRecordset, CFiledExchange,
    CLongBinary, CRecordView
  • DAO ??
  • CDaoWorkspace, CDaoDatabase, CDaoRecordset,
    CDaoRecordView, CDaoQueryDef, CDaoTableDef,
    CDaoException, CDaoFiledExchange
  • MAPI ??
  • Winsock ??
  • CAsyncSocket, Csocket
  • ? ??? ??
  • CHEdit, CBEdit
  • ?? 16 ?? ??

59
?? ? ?? ??
Component Gallery
MFC ??
AppWizard
?? ????
MFC
Custom AppWizard
60
AppWizard? ?? Project ??(1)
  • Project ?? (project ?? Obedit)
  • New ?? (MFC AppWizard (.exe)
  • Database, OLE ??
  • None
  • Multiple document ??

61
AppWizard? ?? Project ??(2)
  • Advanced Options
  • File extension obe File type ID
    Obedit.Document
  • Main frame caption Obedit
  • Doc type name Obedit Filter name Obedit
    Files(.obe)
  • File new name Obedit File type name Obedit
    Document
  • MFC library ?? ??
  • As a shared DLL (MFC42.DLL ??)
  • Base class ??
  • CObeditView ???? ?? ???? CScrollView ??

62
Developer Studio
  • Project Workspace
  • ??? ?(class view)
  • ??? ?(resource view, AppStudio ??)
  • ?? ?(file view)
  • ?? ?(info view)
  • ?? ??
  • source code browser / wizard bar / resource
    editor
  • online help

63
??? ?/?? ?/??? ?
64
??? ?(class view)
  • ???? ?? ? ?? ??
  • ??? ??? ??? ??? ???? ? ??? ??? ??
  • ?? ?? ??
  • ?? ?? ??
  • ?? ??? ?? ??
  • ?? ?? ??

65
?? ?(file view)
  • ????? ?? ???? ??
  • ?????? ?? ??
  • (.net) ??? ???

66
Hungarian ???
  • Type Prefix ? ??
  • char c cDirSeperator
  • BOOL b bIsSending
  • int n nVariableCount
  • UINT n nMyUnsignedInt
  • WORD w wListID
  • LONG l lAxisRatio
  • DWORD dw dwPackedmessage
  • (pointer) p pWnd
  • FAR lp lpWnd
  • LPSTR lpsz lpszFileName z? NULL? ???
  • handle h hWnd ??
  • callback lpfn lpfnHookProc ?? ???

67
Hungarian ??? - MFC ??
  • Type Prefix ?
  • CRect rect rectScroll
  • CPoint pt ptMouseClick
  • CSize sz szRectangle
  • CString str strFind
  • CWnd Wnd WndControl
  • CWnd pWnd pWndDialog

68
Hungarian ??? - Symbol
  • Type Prefix ? ??
  • ?? ????? ?? IDR_ IDR_MAINFRAME
    1-0x6FFF
  • Dialog ??? IDD_ IDD_ABOUT 1-0x6FFF
  • Dialog ??? Help context ID HIDD_ HIDD_HELP_ABOUT 0
    x2001- 0x26FF
  • (for context-sensitive help)
  • ??? ??? IDB_ IDB_SMILEY 1-0x6FFF
  • ?? ??? IDC_ IDC_HAND 1-0x6FFF
  • ??? ???
  • menu, toolbar command ID_ ID_CIRCLE_TOOL 0x8000-0
    xDFFF
  • Command help context HID_ HID_CIRCLE_TOOL 0x1800-0
    x1DFF
  • Message box prompt IDP_ IDP_FATALERROR 8-0xDFFF
  • Message box help context HIDP_ HIDP_FATALERROR 0x3
    008-0x3DFF
  • String ??? IDS_ IDS_ERROR12 1-0x7FFF
  • ????? ???? control IDC_ IDC_COMBO1 8-0xDFFF

69
MFC? ?? ?? ??
70
MFC? ??(1)
  • ?? ???? ??? ? ??
  • Open ?? ??
  • ?? ??? ???? ??? ?? ??
  • ?? ?? ????? ??? ???.
  • ???? ??? ?? ?? ??? ??. ?? MDI ?????? ?? ???? ??
    ??. SDI ??????? ?? ?? ?? ?? ??? ????.
  • ??? ????? ??? ?? ???? ?????. ? ??? ??? ??? ??
    ????? ????.
  • ???? ??? ??? ???. ? ??? ??? ?? ???
    ???(invalidate)?? ?????.

71
MFC? ??(2)
  • ?? ???? ?? ? ? (3?)
  • ??
  • ??? ??? ??
  • ????? ?? ? ?? ??

72
CDocument
  • class CDocument public CCmdTarget
  • ...
  • void OnFileOpen() // ???? ??? ???? ????.
  • BOOL GetOpenFileName(LPCTSTR) // ?????? ??
    ????? ??
  • // ?? ???? ???? ?? (pure virtual function)
  • virtual void Serialize(CFile cfile) 0
  • CWnd GetWindow() // ?? ??? ??? ???? ??? ????
    ??
  • ...

73
CDocumentOnFileOpen
  • void CDocumentOnFileOpen()
  • CString szFileName // CString? ????? ????
    ???
  • if (!GetOpenFileName(szFileName)) // ?????
    ??? ?? ?????
  • return // ?????.
  • CFile cfile(szFileName) // CFile? MFC?? ??
    I/O? ??
  • cfile.Open() // ??? ????.
  • Serialize(cfile) // ??? ??? ?????(user? ??)
  • cfile.Close() // ??? ???.
  • CWnd pWnd GetWindow() // ? ??? ??? ????
    ??? ???
  • pWnd-gtInvalidate(NULL) // ?? ? ??? ????
    WN_PAINT ???
  • // ??

74
CMyDocument ???
  • // CDocument? ?? ?? ???? ??(MFC class)
  • // ???? ?????
  • class CMyDocument public CDocument
  • // My data structure
  • int m_nNumOfObjects
  • Objects obj100
  • public
  • void Serialize(CFile cfile) // virtual
    function

75
WinMain
  • int WinMain(HINSTANCE hInstance, HINSTANCE
    hPrevInstance,
  • LPSTR lpCmdLine, int nCmdShow)
  • if (!hPrevInstance) // ???? ????
    ????
  • InitApplication(hInstance) // ??? ????
    ????.
  • InitInstance(hInstance) // ?? ????
    ????.
  • while(GetMessage(....)) // ??? ??
  • ....
  • DispatchMessage(...) // ???? ???
    ????? ??
  • // ????? ???? ?? ?? ??? ???.
  • ....
  • return msg.wParam

76
MFC? WinMain
  • MFC\SRC\winmain.cpp
  • CWinApp ???? ??
  • CWinAppInitApplication
  • CWinAppInitInstance
  • CWinAppRun
  • CWinAppExitInstance
  • InitInstance, ExitInstance ? override ?? ?? ??
  • ?? ??? ???

77
SDI
  • CObeditApp -gt CWinApp
  • CMainFrame -gt CMDIFrameWnd
  • CObeditDoc -gt CDocument
  • CObeditView -gt CView

78
MDI
  • CObeditApp -gt CWinApp
  • CMainFrame -gt CMDIFrameWnd
  • CChildFrame -gt CMDIChildWnd
  • CObeditDoc -gt CDocument
  • CObeditView -gt CView

79
Document/View ??
?????
2. ? ??? ????.
????
1. ???? ??? ???
3. ???? ????.
80
?? ??
  • CWinApp
  • ??? ?? ????? ???? ???
  • CDocument
  • ?? ????? ????? ???? ???
  • CView
  • ?? ????? ??? ??? ???? ???
  • ??? document?? ?? ?? view? ??? ? ??
  • ?) ???, Visual C ??? ?

81
CObeditApp ???
  • class CObeditApp public CWinApp
  • public
  • CObeditApp()
  • //AFX_VIRTUAL(CObeditApp)
  • public
  • virtual BOOL InitInstance() // ????? ???
  • //AFX_VIRTUAL
  • //AFX_MSG(CObeditApp)
  • afx_msg void OnAppAbout()
  • ...
  • //AFX_MSG

82
InitInstance ??
  • BOOL CObeditAppInitInstance()
  • ....
  • LoadStdProfileSettings() // ?? INI ?? option?
    ????
  • CMultiDocTemplate pDocTemplate
  • pDocTemplate new CMultiDocTemplate(
  • IDR_OBEDITTYPE,
  • RUNTIME_CLASS(CObeditDoc),
  • RUNTIME_CLASS(CChildFrame),
  • RUNTIME_CLASS(CObeditView))
  • AddDocTemplate(pDocTemplate) // View-Doc ??
  • CMainFrame pMainFrame new CMainFrame //
    main window ??
  • if (!pMainFrame-gtLoadFrame(IDR_MAINFRAME))
  • return FALSE
  • m_pMainWnd pMainFrame

83
  • ...
  • RegisterShellFileTypes(TRUE) // ??? icon,
    ??? ??
  • CCommandLineInfo cmdInfo
  • ParseCommandLine(cmdInfo)
  • if (!ProcessShellCommand(cmdInfo))
  • return FALSE
  • pMainFrame-gtShowWindow(m_nCmdShow)
  • pMainFrame-gtUpdateWindow()
  • return TRUE

84
Obedit.ini ??
  • Recent File List
  • File1D\obedit\step8\new.OBE
  • File2D\obedit\step7\test4.OBE

85
????? ??
  • INI ?? ?? ? ??
  • UINT GetProfileInt(LPCTSTR lpszSection, LPCTSTR
    lpszEntry, int nDefault)
  • CString GetProfileString(LPCTSTR lpszSection,
    LPCTSTR lpszEntry, LPCTSTR lpszDefault NULL)
  • BOOL WriteProfileInt(LPCTSTR lpszSection, LPCTSTR
    lpszEntry, int nValue)
  • BOOL WriteProfileString( LPCTSTR lpszSection,
    LPCTSTR lpszEntry, LPCTSTR lpszValue )
  • ?????? ?? ? ??
  • void SetRegistryKey( LPCTSTR lpszRegistryKey )
  • void SetRegistryKey( UINT nIDRegistryKey )

86
?????
  • void CObeditAppLoadStdProfileSettings()
  • // ???? ??? ?? ??? ????.
  • // GetProfileInt...
  • //
  • CWinAppLoadStdProfileSettings() // ?? ?? ??

87
??? ??
  • WM_CREATE
  • OnCreate ?? ??

88
CMainFrame ???
  • class CMainFrame public CMDIFrameWnd
  • DECLARE_DYNAMIC(CMainFrame)
  • ....
  • protected
  • CStatusBar m_wndStatusBar
  • CToolBar m_wndToolBar
  • protected
  • //AFX_MSG(CMainFrame)
  • afx_msg int OnCreate(LPCREATESTRUCT
  • lpCreateStruct)
  • //AFX_MSG
  • DECLARE_MESSAGE_MAP() // ??? ?

89
OnCreate ??
90
MFC MDI ????? ??? ??
MDI ?? ???
???
?? ??
MDI ????? ???
???
MDI ?? ???
? ???
91
CObeditView ???
  • class CObeditView public CView
  • ....
  • public
  • CObeditDoc GetDocument() // ?? ??? ?????
    ??? ??
  • ....
  • //AFX_VIRTUAL(CObeditView)
  • public
  • virtual void OnDraw(CDC pDC) // WM_PAINT?
    ?? ? ??
  • virtual BOOL PreCreateWindow(CREATESTRUCT
    cs)
  • protected
  • virtual BOOL OnPreparePrinting(CPrintInfo
    pInfo)
  • virtual void OnBeginPrinting(CDC pDC,
    CPrintInfo pInfo)
  • virtual void OnEndPrinting(CDC pDC,
    CPrintInfo pInfo)
  • //AFX_VIRTUAL
  • ....

92
?? CView ????
  • GetDocument ?? ??? ?? ????? ?? ???? ????.
  • AddDocTemplate ??? ?? m_pDocument ???
  • MFC? ?? ??? ? ??? ???
  • OnInitialUpdate ?? ?? ???? ? ????.
  • OnDraw ?? ??? ??????? ??? ??? ?? ????.
  • OnPrint ?? ??? ??????? ??? ???? ??
  • OnUpdate ??????? ??? ????? ? ??????
  • ?? ????.

93
CObeditDoc ???
  • class CObeditDoc public CDocument
  • ....
  • //AFX_VIRTAUL(CObeditDoc)
  • public
  • virtual BOOL OnNewDocument()
  • virtual void Serialize(CArchive ar) // file
    I/O
  • //AFX_VIRTUAL
  • ....

94
?? CDocument ?? ??
  • IsModified ??????? ??? ????? ??? ?? ???
  • ?? ??? ????.
  • SetModifiedFlag ??????? ??? ?????? ????.
  • UpdateAllViews ??????? ??? ???? ? ? ??? ???
  • ??? ????. ? ???? ????? OnUpdate
  • ??? ???.
  • DeleteContent ??????? ?? ? ????. ? ? ??????
  • ? ?? ??? ?? ??.
  • OnNewDocument ???? File ??? New ??? ???? ???.
  • OnOpenDocument ???? File ??? Open ??? ???? ???.
  • OnSaveDocument ???? File ??? Save ??? ???? ???.
  • OnCloseDocument ???? File ??? Close ??? ???? ???.

95
?? ? ??
  • Document class? ??? ??? ?? view object? ???? ???
    ??
  • CPtrList m_viewList
  • View?? ??
  • Document ??
  • UpdateAllViews ??

96
UpdateAllViews
97
UI ???
98
?? ??
  • File Object View Window
    Help
  • New Line Toolbar New Window
    About
  • Open Ellipse Status Bar Cascade
    Time
  • Close Rectangle Color Bar
    Title
  • Save --------- ----------
    Arrange Icons
  • Save As Pen Attribute Zoom
  • ----------
  • Print
  • Print Preview
  • Print Setup
  • ----------
  • Send
  • Summary Info
  • ----------
  • Recent File
  • ----------
  • Exit

99
?? ??? ??
  • ??? ???
  • IDR_MAINFRAME(child window? ?? ?)
  • IDR_OBEDITTYPE

100
?? ??
?? ???
  • Line ID_OBJECT_LINE Draw a line\nLine
  • Ellipse ID_OBJECT_ELLIPSE Draw a
    ellipse\nEllipse
  • Rectangle ID_OBJECT_RECTANGLE Draw a
    rectangle\nRectangle
  • Pen Attribute ID_OBJECT_PENATTR Change the
    attribute of a
  • pen\nPen
  • Color Bar ID_VIEW_COLORBAR Show or hide color
    palette
  • Zoom\tCtrlZ ID_VIEW_ZOOM Set zoom
    ratio
  • ID_SEPARATOR(??? ??)

MEMU ID
???
101
??? ??
  • ??? ?? Accelerator ??

102
??? ??
103
??? ??
  • ??? ???
  • IDR_MAINFRAME

104
?? ??
  • ??? ToolBar ??

105
MyToolBar.h ??
  • Class CMyToolBar public CToolBarCtrl -gt
    CToolBar? ??
  • (.net??? ?? ??)
  • // Construction
  • public
  • CMyToolBar()
  • // Attributes
  • . . . .

106
MyToolBar.cpp ??
  • BEGIN_MESSAGE_MAP(CMyToolBar, CToolBarCtrl) -gt
    CToolBar? ??
  • //AFX_MSG_MAP(CMyToolBar)
  • // NOTE - the ClassWizard will add and
    remove mapping ..
  • //AFX_MSG_MAP
  • END_MESSAGE_MAP()

107
MainFrm.h ??
  • include MyToolBar.h // ??
  • class CMainFrame public CMDIFrameWnd
  • DECLARE_DYNAMIC(CMainFrame)
  • public
  • CMainFrame()
  • . . . .
  • protected
  • CStatusBar m_wndStatusBar
  • CToolBar m_wndToolBar -gt CMyToolBar
    m_wndToolBar? ??

108
??? ??
  • obedit.rc
  • ???? ??? ??? ????? ???
  • ??? ??? ??

109
Obedit.rc ??
  • IDR_MAINFRAME TOOLBAR DISCARDABLE 16,15
  • BEGIN
  • BUTTON ID_FILE_NEW
  • BUTTON ID_FILE_OPEN
  • BUTTON ID_FILE_SAVE
  • SEPARATOR
  • BUTTON ID_OBJECT_LINE
  • BUTTON ID_OBJECT_ELLIPSE
  • BUTTON ID_OBJECT_RECTANGLE
  • SEPARATOR
  • BUTTON ID_OBJECT_PENATTR
  • BUTTON ID_FILE_PRINT
  • BUTTON ID_APP_ABOUT
  • SEPARATOR
  • SEPARATOR // 12?? ???? ?? ?? (0?? ???)
  • SEPARATOR
  • SEPARATOR // 14?? ??????? ?? ??
  • END

110
MainFrame? ?? ??
  • CMainFrame? ?? ??
  • CScrollBar m_zoomScroll
  • CStatic m_zoomStatic

111
CMainFrameOnCreate ??
  • int CMainFrameOnCreate(LPCREATESTRUCT
    lpCreateStruct)
  • . . .
  • EnableDocking(CBRS_ALIGN_ANY)
  • DockControlBar(m_wndToolBar)
  • CRect rect
  • // Scroll Bar ??
  • m_wndToolBar.SetButtonInfo(12, ID_ZOOMSCROLL,
    TBBS_SEPARATOR, 80)
  • m_wndToolBar.GetItemRect(12, rect)
  • rect.top 3
  • if (!m_wndToolBar.m_zoomScroll.Create(WS_VISIBL
    E SBS_HORZ
  • WS_TABSTOP, rect, m_wndToolBar,
    ID_ZOOMSCROLL))
  • return -1

80 ??
Resource Symbol? ??
112
  • // ??? ??? ??
  • m_wndToolBar.SetButtonInfo(14, ID_ZOOMSTATIC,
    TBBS_SEPARATOR, 60)
  • m_wndToolBar.GetItemRect(14, rect)
  • rect.top 6
  • if (!m_wndToolBar.m_zoomStatic.Create(??,
    WS_VISIBLE SS_LEFT
  • WS_TABSTOP, rect, m_wndToolBar,
    ID_ZOOMSTATIC))
  • return -1
  • return 0

Resource Symbol? ??
113
??? ?? ??
  • define ID_ZOOMSCROLL 101 // ??? ??? ???? ??
    ??? ??
  • // ???? ?? ??? ???

?? ??
114
??? ??
115
CToolBar ???? ?? ??
  • CommandToIndex ?? ID? ?? ??? ???? ?? ?? ???? ????
    ??.
  • 0?? ??.
  • GetItemID CommandToIndex?? ??? ??? ?????? ?? ID?
    ????.
  • Create ??? ????.
  • EnableDocking ??? ??? ??? ? ??? ???? ??? ???? ??
    ??
  • ?? ? ???? ????.
  • GetBarStyle ??? ???? ????.
  • SetBarStyle ??? ???? ????.
  • GetButtonInfo ?? ??? ?? ??? ????.
  • SetButtonInfo ?? ??? ??? ????.
  • GetCount ?? ??? ??? ????(SEPARATOR ??).
  • GetItemRect ?? ID? ?? ? ??? ????? ??? ????.
  • LoadBitmap ?? ??? ?? ?? ???? ????.
  • SetHeight ??? ?? ??? ????.
  • SetSizes ??? ??? ????.

116
???(Status Bar)
  • ?? ??
  • CStatusBar ????? ???.
  • CStatusBar ????? Create ??? ???? ??? ???? ??
  • SetIndicator ??? ???? ? ??? ???? ??? ID? ?????.
  • static UINT indicators
  • ID_SEPARATOR, // status line indicator
  • ID_INDICATOR_CAPS,
  • ID_INDICATOR_NUM,
  • ID_INDICATOR_SCRL,

117
??? ???
??? ??
??
????
???
?? ?? ???
118
Pane ??? ??
  • SetWindowText ??? ??? ??
  • Command UI ???? SetText ?? ??
  • void CMainFrameOnUpdateIndicatorTime(CCmdUI
    pCmdUI)
  • pCmdUI-gtSetText(Pane? ??)
  • SetPaneText ?? ??
  • CStatusBar bar
  • bar.SetPaneText(0, Pane? ??)

119
???? ??(1)
  • indicators ?? ??(MainFrm.cpp)
  • static UINT indicators
  • ID_SEPARATOR, // status line indicator
  • ID_SEPARATOR, // ??
  • ID_INDICATOR_CAPS,
  • ID_INDICATOR_NUM,
  • ID_INDICATOR_SCRL,

120
???? ??(2)
  • CMainFrame ???? OnCreate ?? ??
  • int CMainFrameOnCreate(LPCREATESTRUCT
    lpCreateStruct)
  • ...
  • DockControlBar(m_wndToolBar)
  • m_wndStatusBar.SetPaneInfo(1,ID_INDICATOR_TIME,
    SBPS_NORMAL,60)
  • return 0
  • 1? ???? ? ?? ?? ????.
  • ?? ????? ??
  • Resource Symbol? ???? ID_INDICATOR_TIME ??

121
?? ??
  • ??? ???? ???? ?? UI ????? ??
  • View ??? ClassWizard ??
  • Object IDs ID_INDICATOR TIME
  • Messages UPDATE_COMMAND_UI
  • ?? ?? (OnUpdateIndicatorTime)
  • void CMainFrameOnUpdateIndicatorTime(CCmdUI
    pCmdUI)
  • char timebuf12
  • _strtime(timebuf)
  • pCmdUI-gtSetText(timebuf)
  • ??? ??? ?? ?? ?? ??

122
MFC? ?? ?? ??
  • AfxGetApp ????? ???? ???? ????? ??
  • ???? ????.
  • AfxGetAppName ????? ??? ????.
  • AfxGetInstanceHandle ????? ???? ??? ????.
  • AfxGetMainWnd ?? ??? ??? ????? ?? ????
  • ????.
  • GetCurrentMessage ?? ?? ?? ???? ?? ??? ?????
  • ????. ??? ??? ??? ??? ????
  • ? ?? ???? ?? ? ????.
  • AfxSocketInit ??? ??? ????? ?? ???.
  • AfxBeginThread ??? ???? ????.
  • AfxEndThread ??? ???? ???.
  • AfxGetThread ?? ?? ?? ???? ?? ???
  • (CWinThread)? ????.

123
?? ? ??? ??
  • ??? ????? ??? ??? ??
  • Add Class/New?? CMyColorBar ??? ??
  • ?? ???? CToolBarCtrl? ??
  • MyColorBar.cpp, MyColorBar.h?? CToolBarCtrl?
    CToolBar? ??
  • ??? ? ?? Image ??? Adjust Colors... ?? ? ??? ? ??

124
?? ??? ??
  • ??? ??? ??? Toolbar ??
  • ??? ???? (MyColorBar.cpp? ??)
  • COLORREF color16
  • RGB( 0, 0, 0), RGB(255,255,255),
  • RGB(192,192,192), RGB(128,128,128),
  • RGB(255, 0, 0), RGB(255,255, 0),
  • RGB( 0,255, 0), RGB( 0,255,255),
  • RGB( 0, 0,255), RGB(255, 0,255),
  • RGB(128, 0, 0), RGB(128,128, 0),
  • RGB( 0,128, 0), RGB( 0,128,128),
  • RGB( 0, 0,128), RGB(128, 0,128)

125
?? ??
  • Image ??
  • Adjust Colors...

126
ColorBar ??
  • include MyColorBar.h
  • class CMainFrame public CMDIFrameWnd
  • DECLARE_DYNAMIC(CMainFrame)
  • ...
  • protected
  • CToolBar m_wndToolBar
  • CMyColorBar m_wndColorBar
  • ...

127
  • int CMainFrameOnCreate(LPCREATESTRUCT
    lpCreateStruct)
  • ....
  • m_wndStatusBar.SetPaneInfo(1,ID_INDICATOR_TIME,
    SBPS_NORMAL,60)
  • if (!m_wndColorBar.Create(this,WS_CHILD
    WS_VISIBLE
  • CBRS_SIZE_FIXED CBRS_LEFT
    CBRS_FLYBY, ID_COLORBAR)
  • !m_wndColorBar.LoadToolBar(IDR_MYCOLORBAR))
  • return FALSE
  • m_wndColorBar.SetColumns(2)
  • m_wndColorBar.EnableDocking(CBRS_ALIGN_LEFT
    CBRS_ALIGN_RIGHT)
  • DockControlBar(m_wndColorBar)
  • return 0

128
  • void CMyColorBarSetColumns(UINT nColumn)
  • int nCount GetToolBarCtrl().GetButtonCount()
  • for(int i 0 i lt nCount i)
  • UINT nStyle GetButtonStyle(i)
  • BOOL bWrap (((i1) nColumn) 0)
  • if (bWrap)
  • nStyle TBBS_WRAPPED
  • else
  • nStyle TBBS_WRAPPED
  • SetButtonStyle(i, nStyle)
  • Invalidate()
  • GetParentFrmae()-gtRecalcLayout()

129
?? ?? ??
130
??? ??? ???
CDrawObject
CLine
CEllipse
CRectangle
131
??? ???
  • class CDrawObject public CObject
  • protected
  • CDrawObject(WORD objType, COLORREF crColor,
    int nPenStyle,
  • int nPenWidth)
  • public
  • COLORREF m_crColor // ? ??? ??
  • int m_nPenStyle // ?? ??? ?? ?? ???.
    PS_SOLID,
  • // PS_DOT,PS_DASH,PS_DASHD
    OT,PS_DASHDOTDOT
  • // ?? ?? ????.
  • int m_nPenWidth // ?? ??? ?? ?? ?
  • int m_rcRect // ??? ??? ????.
  • public
  • WORD m_wObjType // ? ????? ??? ????. ?
    ??? ????
  • // ?? ?? ?? enum
    ObjectType? objectLine,
  • // objectRectangle,
    objectEllipse ?? ???
  • // ? ? ??.

132
  • enum ObjectType
  • objectLine, objectEllipse, objectRectangle
  • virtual CDrawObject()
  • virtual void DrawObject(CDC pDC) 0 //
    pure virtual function
  • virtual void SetStartPoint(CPoint pt)
    m_rcRdct.TopLeft() pt
  • virtual void SetEndPoint(CPoint pt)
    m_rcRect.BottomRight()pt
  • virtual CPoint GetStartPoint() return
    m_rcRect.TopLeft()
  • virtual CPoint GetEndPoint() return
    m_rcRect.BottomRight()
  • virtual void GetBoundingRect(CRect pRect)
  • virtual void Serialize(CArchive ar)
  • ifdef _DEBUG
  • virtual void AssertValid() const // ??? ??
    ??
  • virtual void Dump(CDumpContext dc) const //
    ??? ??? ???
  • //
    ????
  • endif

133
  • class CLine public CDrawObject
  • protected
  • DECLARE_SERIAL(CLine)
  • public
  • CLine()
  • CLine(COLORREF crColor, int nPenStyle, int
    nPenWidth)
  • virtual CLine()
  • virtual void DrawObject(CDC pDC)
  • virtual void Serialize(CArchive ar)
  • ifdef _DEBUG
  • virtual void AssertValid() const
  • virtual void Dump(CDumpContext dc) const
  • endif

134
  • class CEllipse public CDrawObject
  • protected
  • DECLARE_SERIAL(CEllipse)
  • public
  • CEllipse()
  • CEllipse(COLORREF crColor, int nPenStyle, int
    nPenWidth)
  • virtual CEllipse()
  • virtual void DrawObject(CDC pDC)
  • virtual void Serialize(CAarchive ar)
  • ifdef _DEBUG
  • virtual void AssertValid() const
  • virtual void Dump(CDumpContext dc) const
  • endif

135
  • class CRectangle public CDrawObject
  • protected
  • DECLARE_SERIAL(CRectangle)
  • public
  • CRectangle()
  • CRectangle(COLORREF crColor, int nPenStyle,
    int nPenWidth)
  • virtual CEllipse()
  • virtual void DrawObject(CDC pDC)
  • virtual void Serialize(CAarchive ar)
  • ifdef _DEBUG
  • virtual void AssertValid() const
  • virtual void Dump(CDumpContext dc) const
  • endif

136
  • include stdafx.h
  • include DrawObj.h
  • CDrawObjectCDrawObject(WORD objType, COLORREF
    crColor, int nPenStyle, int nPenWidth)
  • m_wObjType(objType), m_crColor(crColor),
    m_nPenStyle(nPenStyle), m_nPenWidth(nPenWidth)
  • m_rcRect.SetRectEmpty()
  • CDrawObjectCDrawObject()
  • void CDrawObjectGetBoundingRect(CRect pRect)
  • pRect-gtleft min(m_rcRect.left,
    m_rcRect.right)
  • pRect-gtright max(m_rcRect.left,
    m_rcRect.right)
  • pRect-gttop min(m_rcRect.top,
    m_rcRect.bottom)
  • pRect-gtbottom max(m_rcRect.top,
    m_rcRect.bottom)

137
  • void CDrawObjectSerialize(CArchive ar)
  • if (ar.IsStoring())
  • else
  • ifdef _DEBUG
  • void CDrawObjectAssertValid() const
  • CObjectAssertValid()
  • void CDrawObjectDump(CDumpContext dc) const
  • CObjectDump(dc)

138
  • IMPLEMENT_SERIAL(CLine, CObject, 1)
  • CLineCLine()
  • CDrawObject(objectLine, RGB(0,0,0), PS_SOLID,
    1)
  • CLineCLine(COLORREF crColor, int nPenStyle, int
    nPenWidth)
  • CDrawObject(objectLine, crColor, nPenStyle,
    nPenWidth)
  • CLineCLine()
  • void CLineDrawObject(CDC pDC)
  • CPen pen, ppenOld
  • pen.CreatePen(m_nPenStyle, m_nPenWidth,
    m_crColor)
  • ppenOld pDC-gtSelectObject(pen)
  • pDC-gtMoveTo(m_rcRect.TopLeft())

139
  • void CLineSerialize(CArchive ar)
  • CDrawObjectSerialize(ar)
  • if (ar.IsStoring())
  • else
  • ifdef _DEBUG
  • void CLineAssertValid() const
  • CDrawObjectAssertValid()
  • void CLineDump(CDumpContext dc) const

140
  • IMPLEMENT_SERIAL(CEllipse, CObject, 1)
  • CEllipseCEllipse()
  • CDrawObject(objectEllipse,RGB(0,0,0),PS_SOLID,1
    )
  • CEllipseCEllipse(COLORREF crColor, int
    nPenStyle, int nPenWidth)
  • CDrawObject(objectEllipse, crColor, nPenStyle,
    nPenWidth)
  • void CEllipseDrawObject(CDC pDC)
  • CBrush br, pbrOld
  • CPen pen, ppenOld
  • br.CreateSolidBrush(m_crColor)
  • pen.CreatePen(m_nPenStyle, m_nPenWidth,
    m_crColor)
  • pbrOld pDC-gtSelectObject(br)
  • ppenOld pDC-gtSelectObject(pen)
  • pDC-gtEllipse(m_rcRect)

141
  • CEllipseCEllipse()
  • void CEllipseSerialize(CArchive ar)
  • CDrawObjectSerialize(ar)
  • if (ar.IsStoring())
  • else
  • ifdef _DEBUG
  • void CEllipseAssertValid() const
  • CDrawObjectAssertValid()

142
  • IMPLEMENT_SERIAL(CRectangle, CObject, 1)
  • CRectangleCRectangle()
  • CDrawObject(objectRectangle,RGB(0,0,0),PS_SOLD,1
    )
  • CRectangleCRectangle(COLORREF crColor,int
    nPenStyle,int nPenWidth)
  • CDrawObject(objectEllipse, crColor, nPenStyle,
    nPenWidth)
  • void CRectangleDrawObject(CDC pDC)
  • CBrush br, pbrOld
  • CPen pen, ppenOld
  • br.CreateSolidBrush(m_crColor)
  • pen.CreatePen(m_nPenStyle, m_nPenWidth,
    m_crColor)
  • pbrOld pDC-gtSelectObject(br)
  • ppenOld pDC-gtSelectObject(pen)
  • pDC-gtRectangle(m_rcRect)

143
  • CRectangleCRectangle()
  • void CRectangleSerialize(CArchive ar)
  • CDrawObjectSerialize(ar)
  • if (ar.IsStoring())
  • else
  • ifdef _DEBUG
  • void CRectangleAssertValid() const
  • CDrawObjectAssertValid()

144
??? ??????? ??
?? ????
WIN32 API
GDI (Graphic Device Interface)
???? ????
?? ?? ??
145
DirectX
  • ??? 3.1? ??? ?? ?? ?? ??? ??
  • ?? (WinG)
  • DirectDraw
  • DirectX? ??? ?? ?????
  • DirectPlay
  • ???? ??? ???? ??? ? ?? ?????
  • DirectSound
  • ??? ??? ??? ?? ?????
  • DirectInput
  • ???? ?? ??? ??? ? ?? ?????

146
???? ????
  • Device Context
  • ??? ?????? ?? ??? ???? ?
  • ????? ? ? ?, ?, ???, ??(???), ?? ?? ??? ??? ??
    ??? ??
  • ??? ???? GDI ?? ?? ??
  • ?? ?? DC ?? ??? ??
  • GetDC ReleaseDC

147
DC? ??
  • CClientDC
  • ???? ????? ??
  • CWindowDC
  • ??? ?? ???? ????
  • ???? ???, ?? ?? ??? ??? ??
  • CPaintDC
  • WM_PAINT ???? ??

148
??? ??????? ?? ??
??? ??? ???? ????? ??? ???.
GDI? ??? ?? ??? ??? ???.
???? ????? ????.
149
SDK??? ?? ?? ?? ??
1. ??? ?? ????(CreatePen, CreateSolidBrush).
2. ???? ????? ???(GetDC? BeginPaint).
3. 2?? ?? ????149 ????? ??? ?? 1?? ?? ??? ??
???(SelectObject). ????? ?? ???? ??? ?? ????.
4. GDI? ??? ?? ??? ????.
5. 3?? ??? ??? ??? ??? ?? ???? ???(SelectObject).
6. ???? ????? ??? ????? ????.
7. 1?? ?? ??? ?? ????(DeleteObject).
150
CDC ???? ?? ??(1)
  • CreateCompatibleDC ??? ??? DC? ?? ??? ?? DC?
  • ???? ???.
  • GetSafeHdc ?? ????? ???? ?? ???? ????
  • ??? ????.
  • IsPrinting ??? DC?? ???? ??? ????.
  • SetROP2 ?????? ????? ????.
  • SetBkColor ???? ?? ???? ????.
  • SetTextColor ???? ?? ???? ????.
  • MoveTo, LineTo ??? ??? ????.
  • Arc, ArcTo ??? ???? ????.
  • PolyDraw ??? ??? ????? ????? ??
  • PloyLine ??? ????? ???? ??
  • Polygon ??? ????? ???? ?? ?? ???
  • ?? ???

151
CDC ???? ?? ??(2)
  • PolyBezier ??? ????? ????? ???? ??
  • InvertRect ??? ??? ????? ????.
  • DrawIcon ??? ??? ??? ???? ????.
  • Draw3dRect ???? ???? ???? ????.
  • Ellipse ??(? ??)? ???? ????.
  • Pie ???? ???? ????.
  • Rectangle ???? ???? ????.
  • RountRect ???? ?? ???? ???? ????.
  • SetPixel ?? ??? ????.
  • BitBlt ? ???? ????? ??? ?? ???? ?????
  • ????.
  • TextOut ??? ??? ???? ????.
  • DrawText ??? ??? ?? ???? ????.

152
View ??? ??(1)
  • include DrawObj.h
  • class CObeditView public CScrollView
  • ....
  • // Attributes
  • public
  • CObeditDoc GetDocument()
  • int m_nSelectedColorID // ?? ?? ????? ??? ???
    ???
  • COLORREF m_crCurColor // ?? ????? ??? ???
    ???? RGB ?
  • int m_nPenStyle // ?? ??? ? ???
  • int m_nPenWidth // ?? ??? ?? ??
  • CDrawObject m_pCurDrawObject // ?? ????? ??
    ??
  • WORD m_wCurDrawObject // ?? ??? ??? ????
    ????.
  • ....

153
View ??? ??(2)
  • extern COLORREF color16
  • CObeditViewCObeditView()
  • m_nSelectedColorID 0 // ???? ???? ?? ????
    ??? ???
  • m_crCurColor colorm_nSelectedColorID //
    ??? ??? ???? ?
  • m_nPenStyle PS_SOLID // ?? ?? ???
  • m_nPenWidth 1
  • m_pCurDrawObject NULL
  • m_wCurDrawObject CDrawObjectobjectLine

154
?? ?? ?? ??
  • ??? ??? ?? ?? ?? ??

155
?? ?? ??
  • void CObeditViewOnObjectLine()
  • m_wCurDrawObject CDrawObjectobjectLine
  • void CObeditViewOnObjectRectangle()
  • m_wCurDrawObject CDrawObjectobjectRectangle
  • void CObeditViewOnObjectEllipse()
  • m_wCurDrawObject CDrawObjectobjectEllipse

156
??? UPDATE_COMMAND_UI
  • void CObeditViewOnUpdateObjectLine(CCmdUI
    pCmdUI)
  • pCmdUI-gtSetCheck(m_wCurDrawObject
    CDrawObjectobjectLine)
  • void CObeditViewOnUpdateObjectRectangle(CCmdUI
    pCmdUI)
  • pCmdUI-gtSetCheck(m_wCurDrawObject
    rawObjectobjectRectangle)
  • void CObeditViewOnUpdateObjectRectangle(CCmdUI
    pCmdUI)
  • pCmdUI-gtSetCheck(m_wCurDrawObject
    DrawObjectobjectRectangle)

157
?? ??
  • void CObeditViewOnPalettecolor1() // ?? ??? ??
    ??. 16? ??
  • m_nSelectedColorID 0
  • m_crCurColor color0
  • void CObeditViewOnUpdatecolor1(CCmdIO pCmdUI)
  • pCmdUI-gtSetCheck(m_nSelectedColorID 0)

158
Message Map
  • ?? ??? ????? ??
  • BEGIN_MESSAGE_MAP(CObeditView, CScrollView)
  • //AFX_MSG_MAP(CObeditView)
  • ON_COMMAND(ID_OBJECT_ELIIPSE, OnObjectEllipse)
  • ON_UPDATE_COMMAND_UI(ID_OBJECT_ELLIPSE,
    OnUpdateObjectEllise)
  • ON_COMMAND(ID_OBJECT_LINE, OnObjectLine)
  • ON_UPDATE_COMMAND_UI(ID_OBJECT_LINE,
    OnUpdateObjectLine)
  • ON_COMMAND(ID_OBJECT_RECTANGLE,
    OnObjectRectangle)
  • ON_UPDATE_COMMAND_UI(ID_OBJECT_RECTANGLE,
    OnUpdateObjectRectangle)
  • //AFX_MSG_MAP
  • //Standard printing commands
  • ON_COMMAND(ID_FILE_PRINT, CScrollViewOnFilePri
    nt)
  • ON_COMMAND(ID_FILE_PRINT_DIRECT,
    CScrollViewOnFilePrint)
  • ON_COMMAND(ID_FILE_PRINT_PREVIEW,
    CScrollViewOnFilePrintPreview)
  • END_MESSAGE_MAP()

159
???? ?? ??? ??
  • ?????? ??? ???? ???
  • ???
  • ???
  • ???
  • ??? ???? ??? ???? ???? ???? ???
  • ???
  • ??? ?
  • ??

160
??? ?? ???
  • ??
  • WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP
  • ?? ? ?? (virtual keycode) - lParam
  • ?? 0 - 15 ?? ?? ??
  • ?? 16 - 23 ?? ?? ??
  • (??? ????? ?? ?? ? ??)
  • ?? 24 ?? ? ?? (1 ???, 0 ??)
  • ?? 25 - 26 ??? ??
  • ?? 27 - 28 ??? ????? ????? ??
  • ?? 29 ???? ?? (1 Alt ?? ??, 0 ? ??)
  • ?? 30 ?? ?? ?? (1 ?? ??? ???, 0 ??)
  • ?? 31 ?? ?? ?? ??
  • (1 ?? ???? ?, 0 ???? ?)

161
?? ?? ???
  • ??
  • WM_CHAR, WM_SYSCHAR
  • ??? ?? ??
  • ??? ??? ?? ?(SDK??? TranslateMessage ??? ??? ???
  • WM_KEYDOWN --gt WM_CHAR --gt WM_KEYUP
  • ??? ??? ?? ?(? ENTER)
  • WM_KEYDOWN --gt WM_KEYUP
  • ??
  • wParam ??? ??
  • lParam WM_KEYDOWN, WM_KEYUP??? ??

162
??? ???? ??
  • ??? ???? ??
  • WM_LBUTTONDBLCLK
  • WM_LBUTTONDOWN
  • WM_LBUTTONUP
  • WM_MOUSEMOVE
  • WM_RBUTTONDBLCLK
  • WM_RBUTTONDOWN
  • WM_RBUTTONUP
  • ???? ?? Pixel ??

163
??? ???? ???
1
t1?? t2 ???? 1? ???? ??? ???? ????, t2?
Write a Comment
User Comments (0)
About PowerShow.com