737

Самоучитель Visual C++

Embed Size (px)

Citation preview

- -

681.3.06 - 32 Windows. . , . , , . (DLL). Visual C++.

: . .

. . Visual C++ .NET. .: -, 2002. 736 : . ISBN 5-94157-032-5 . . , 2002 , "-", 2002

02429 24.07.00. 28.02.02. 70x100Vi6. . . . . 59,34. 4000 . 629 "-", 198005, -, ., 29. , 77.99.1.953..950.3.99 01.03.1999 . . " " , . 198005, -, ., 29.

,

1 2 3 7 911

? , I.

1. Windows MFC 2. , 3. II.

13 13 17 19 20 25 25 29 35 39 40 41 43 55 55 55 69 82 82 87 9399

4.

101 101

IV 5. Windows 3.x Win32 , Windows Properties 6. (GDI) - - 7.

: 110 119 125 136 136 138 141 141 142 143 145 146 148 153 154 154 159 159 162 162 163 165 166 173 173 175 176 179 181 185 189 195 195 202 208 208 218 218 222 232

CFile CArchive CFile

V

8. , 9. 10. MFC III. VISUAL C++

236236 238 244 250 254 255 256 258 272 285 286 293 294 294 299 309

315

11. , Visual C++ Visual C++ C++ C++ , , . ....

317317 318 320 322 324 326 328 329 333 335 336 338 341 344 344 347 352 353 355 357

VI

12. Windows 13. ..: HTML 14. , ASSERT TRACE new delete

360361 361 363 365 366 367 367 369 377 387 387 388 389 403 403 404 407 412 437 441 446 446 473 477 480 481 481 485 486 511 513 513 515 519 524 526 526 528 529 530 531 531 535

VII

15.

:

538539 539 540 542 542 543 544 545 547 548 549 550 555 555 562 579 583 587 587 588599

MFC MFC DHMain DEF MFC 16. Internet Winlnet Web- IV.

1. - - , 2. Visual C + + Standard File .". File / New File / Open ,

601 601 602 603 604 605 605 605 612 612 614 615 617 618 620 ...623 625 625 625 628

-

VIII File / Close File / Add New Item File / Add Existing Item File / Add Project File / Open Solution File / Close Solution File j Save File / Save As File / Advanced Save Options File / Save All File j Source Control File / Page Setup File / Print : File / Recent Files File / Recent Projects , File / Exit Edit... Edit / Undo Edit j Redo Edit j Cut Edit I Copy Edit / Paste Edit / Delete Edit / Select All Edit / Find and Replace Edit / Go To Edit/ Insert File As Text... Edit / Advanced Edit / Bookmarks Edit / Outlining Edit j IntelliSense View View / Open View j Open With View / Solution Explorer View / Class View View / Server Explorer View / Resource View View / Properties Window View / Toolbox View / Web Browser View / Other Windows View / Show Tasks View / Toolbars View / Full Screen View / Navigate Backward View / Navigate Forward View / Property Pages

630 630 630 631 631 632 632 632 633 633 634 634 635 635 635 636 636 637 637 638 638 638 638 638 647 647 648 650 651 655 657 657 657 657 659 659 659 :...659 661 661 661 662 662 662 664 664 664

Project Project / Add Class Project / Add Function Project / Add Variable ? Project / Add Resource Project / Add New Item Project / Add Existing Item Project / New Folder Project / Unload Project Project / Add Web Reference Project / Set as StartUp Project Project / Properties Build Build / Build Build / Rebuild All.... Build / Clean Build / Batch Build Build / Configuration Manager Build / Compile Build / Deploy Debug Debug / Windows Debug / Start Debug / Break All Debug / Stop Debugging Debug / Detach All Debug / RestaiX Debug / Apply Code Changes Debug / Processes Debug / Exceptions Debug / Step Into Debug / Step Over Debug / Step Out Debug / QuickWatch Debug / New Breakpoint Debug / Clear All Breakpoints Debug / Disable Breakpoint Debug / Save Dump As Tools Tools / Debug Processes Tools / Connect to Database Tools / Connect to Server Tools / Customize Toolbox Tools / Add-in Manager Tools / Build Comment Web Pages...: Tools / Macros

IX 664 666 666 666 668 668 669 669 669 670 670 671 671 671 671 672 672 673 673 673 673 673 ...675 675 675 675 675 675 675 676 676 676 677 677 677 679 679 679 679 680 680 680 680 681 683 684

:

Tools / ActiveX Control Test Container Tools / Create GUID Tools / Error Lookup Tools / MFC/ATL Trace Tool Tools / OLE/COM Object Viewer Tools / Spy++ Tools / External Tools Tools / Customize Tools / Options Window...; Window / New Window Window / Split Window / Dockable Window / Hide Window / Floating Window / Auto Hide , Window / Auto Hide All Window / New Horizontal Tab Group Window / New Vertical Tab Group Window / Move to Next Tab Group Window / Move to Previous Tab Group Window / Close All Documents Window / Windows Help i Help / Dynamic Help Help / Contents Help / Index Help / Search Help / Index results Help / Search results Visual Studio.NET Solution Explorer Class View Properties Watch Breakpoints 3. 684 684 686 686 687 687 :.687 689 689 691 691 691 692 692 692 692 692 694 694 695 695 :....695 696 696 696 697 698 698 699 699 700 700 701 701 701 704 704 705 707 709

,

Windows "", "", . , , , . , , . , , , . . Windows - , , . Visual Studio.NET, Microsoft. , , , . , , , . , Visual Studio 6.0, Windows 95, Windows 98 . , , ( ) , . : -, , -, Microsoft, . Visual Studio.NET, 32- Windows 95,

2

Windows 98 Windows NT. Internet- , . , , 16- Windows DOS. , . , , , , , . , , . , Microsoft . , , , Visual Studio.NET. - #, , . , C++. Visual C + + , Visual Studio.NET, 6.0, Microsoft Foundation Classes MFC , .

Visual C + + , C++. , MFC, , . , DOS. . Microsoft. , DOS, Windows . Visual Studio.NET , , , .

, Microsoft Visual Studio.NET C++ Builder Inprise, , , , Windows. , . , Windows .: Visual C++, . , AppWizard, , MFC. Visual C + + , , , . , , , : DOS , Windows, , , Windows 3.x , 32- , , , , , , . , C++ Windows. , , , . , , , DOS , , Turbo Vision Borland, . , . , , , .

, Windows, , . , . I. . , Windows. -

4

/, MFC. 1. . , , . , MS DOS. 2. , . /. , . 3. . .

II. . , . 4. . , . 5. . , Windows . 6. . Windows (GDI). 7. . Windows. 8. . Windows , . , , , . 9. . Windows.

5

. 10. . Visual C + + , , . . III. Visual C++. , , . Visual C++ , , . . 11. , Visual C++. , Visual C++. , . . . , . , . 12. Windows. Windows , Windows . . . 13. . , , , , , . , ,

, . , . . 14. . . . , Visual C++ . 15. . , , . , , . , . 16. Internet. Microsoft Visual Studio.NET, , Internet. Winlnet Web. , , Visual C + + . 1. - . , , , , . MFC , . 2. Visual C++. Visual C++ . " ", . , , . -

7

, . 3. . SAMPLES.EXE, Visual C++. , MSDN. . , , , , . , , . , . , .

, . . , , , : void CMainFrame::Dump(CDumpContexts dc) const { CMDIFrameWnd::Dump(dc); } , , . ! 1. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if ( !m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD I WS__VISIBLE I CBRS_TOP t CBRS GRIPPER | CBRS_TOOLTIPS I CBRS_FLYBY I CBRS SIZE DYNAMIC) || !m wndToolBar.LoadToolBar(IDR MAINFRAME)) j

TRACEO("Failed to create toolbar\n"); return -1; // fail to create

i (!m_wndStatusBar.Create(this) I f I !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) fTRACEO("Failed to create status bar\n"); return - 1 ; // fail to create

// TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking (CBRS__ALIGN_ANY) ; DockControlBar(&m_wndToolBar); return 0;

, , , . : i n t , CMainFrame, DockControlBar . . , , . , , , . , . : c o b j e c t : : S e r i a l i z e . , , , , , . , . , . : Open, File | New . . ( ) . : , . . , (+). : ++. . : . . : . 5.

9

Visual Studio.NET : IBM PC Intel Pentium II 450 ; 256 ; 3 ; SVGA , 800x600 ; CD-ROM; Microsoft ; Windows 98, Windows ME, Windows NT Windows 2000. , .

I

1. 2. , 3.

1

Visual Studio.NET , , . , Windows, , , , . , , , . , Visual Studio.NET, , , , . , MFC (Microsoft Foundation Classes) Application Wizard. Visual C++ . MFC Visual C++. Windows . Visual C++. MFC : ; ; ; . , Visual C++,

Microsoft , , , . , . , -

14

I.

, , , Visual C + + , , . , . , . Windows, ActiveX, . , , , . . Dialog . MFC: 1. File | New | Project ( | | ) New Project ( ) Standard (). New Project ( ), . 1.1. iNew Project i* Templates: | Visual C# Projects i i_J Visual C++ Projects 1 Visual FoxPro Projects 1 I Setup and Deployment Projects : _] Other Projects ) Visual Studio Solutions 3 Windows Application

Wb e Application

3 ~ i d CsLrrCnobr a b y onlwry ls i a W La t i r s o SI Wrrotl ea n W Srie L C r e e by o b v b c iBrowse...

A project for creating an application with a W d w u e interface no s sr i Nm: ae Location:More

I WindowsApplicationl E\ o u e t a d Settings\Nick\fvly D c m nsVs a- jl :D c m ns n o u e t\ iu l

Project wil be created at E:\,. ,N kM D c m nsV u l Su i Projects\WindowsApplicationl, \ i \ y o u e t \ i a t do c s

. 1.1. New Project

1.

15

2. Project Types ( ) Visual C + + Projects ( Visual C++). New Project ( ) , . 1.2.

Project T p s y e: I Vs a B s Projects i u l ai c | Visual C Projects # j S t p a d D p y e t Project5 eu n e l m n o [J Otfw Projects ) Vs a Su i S l to s i u l t do oui n

Xm lts e pae : ] A L Project A L S r e A L S r e T T ev r T ev r i Project W b Service e C so ut m Wizard Extended Stored Pro... Makefile Project

A project that u e the Active T m l t Library. ss e pe aName: Location: ^ Add to Solution ; ; E ^.Documents and Settirig5\Administrator\My Documen j ^ j (' Close Solution Browse...

Project wil be created at E;\...\Administrator\My D c m nsV u l Su i Projects\ o u e t \ i a t do s a e. *More j | OK "Cancel

. 1.2. Visual C++ Projects 3. Templates () MFC Application ( MFC), Name () "Dialog" . MFC Application Wizard - Dialog ( MFC), . 1.3.

4. Application Type ( ). MFC Application Wizard ( MFC) , . 1.4. 5. Application type ( ) Dialog based () Finish (). MFC Application Wiza^i , . 1.5. Visual Studio.NET Toolbox (), . Toolbox () 3, .

16

I.

Welcome to the M C Application Wizard F This wizard generates an MC application project with the properties you specify. F

Application T p ye

C m o n D c m n S p ot Click Finish from any window to accept the current settings. o pud ou e t u p r D c m n T m l t Strings After you create the project, see the project's readme.txt file for information o u e t e pae about the project features and files that are generated. D t b s S p ot aa a e u p r U e Interface Features sr A v n e Features da c d Generated Ca s s l se

These are the current project settings: Multiple document interface No database support rjo c m o n document support o pud

"finish" j] C n e acl. 1.. MFC Application Wizard - Dialog IMFC Application Wteard aloe i Application Type J Specify Document/View architecture support, language, and interface style options for your application, Application type:" Single document

J1?!E

Project style: Windows Explorer (i MFC standard Use of MFC: (V Use MFC in a shared DLL Use MFC in a static library

lication Type Compound Document Support Document Template Strings Database Support User Interface Features '... Advanced Features:

* Multiple documents '* Dialog based

P Multiple top-level documents W Document/View architecture support Resource language: I English (United States)

:

Generated Classes

. 1.4. Application Type

1. '.. Dialog -Microsoft W5Ualt++[desion1 file Edit View Project guild Debug ^ ^ ' ^ ^ ^ '*'* Tools Wndow Help > Debug rf*Te

17i _|gj X | 15 --I1 *? "

*t

IsKindOf(RUNTIME_CLASS(CMDIDoc))); return (CMDIDoc*)m_pDocument; ) #endif //_DEBUG // CMDIView 2.4, ' . , , , , . CMDiview ID_FILE_PRINT, ID_FILE_PRINT_DIRECT ID_FILE_PRINT_PREVIEW. CView: :OnFilePrint CView: :OnFilePrintPreview. , .

34

I.

cwnd: : PreCreatewindow , cwnd. PreCreatewindow . cview: :OnDraw . (GDI) onDraw . 6, 10. OnDraw, 2.4, . CMDIDOC, cview: :GetDocument. /, . CDocument, . , . . onDraw ASSERT_VALID, . , MFC, . A s s e r t v a l i d . , , , ASSERT A s s e r t v a l i d . 14. CView::OnPreparePrinting, CView::OnBeginPrinting

cview: :onEndPrinting . 10. CMDiview, , CMDIDOC CObject::Assertvalid CObject::Dump, . , GetDocument. , ' : , , , (inline). GetDocument , , , , .

2. ,

35

. , , , . , .

. ? , . , , , , . , , . * . MDI.cpp, CMDIAPP, 2.5. ! 2.5. MDI.cpp // MDI.cpp . \

tnld " t a x h icue s d f . " #nld "D." icue MIh #nld "anr." icue MiFmh #nld "hlFmh icue Cidr." tnld " D D c h icue M I o . " tnld " D V e . " icue M I i w h #fe _EU idf DBG #eienwDBGNW dfn e EU_E #ni edf// CMDIApp

36

I.

BEGIN_MESSAGE_MAP(CMDIApp, CWinApp) ON__COMMAND(ID_APP_ABOUT, OnAppAbout)// ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) // ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) END_MESSAGE_MAP() // CMDIApp CMDIApp::CMDIApp() // : . // // InitInstance

// CMDIApp CMDIApp theApp; // CMDIApp BOOL CMDIApp::Initlnstance() { CWinApp::Initlnstance(); // OLE if {!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; ) AfxEnableControlContamer () ; // / // // , // . // , // . // : - // , ,

2. , SetRegistryKey (JT ("Local AppWizard-Generated Applications")); LoadStdProfileSettings(4); // INI // ( ) // . // , CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate(IDR_MDITYPE, RUNTIME_CLASS(CMDIDoc), RUNTIME_CLASS(CChildFrame), // //

37

RUNTIME_CLASS(CMDIView)); AddDocTemplate(pDocTemplate); // CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame (IDR_MAINFRAME) ) return FALSE; m_pMainWnd = pMainFrame; // , , // MDI m_pMainWnd // DragAcceptFiles. // , // CCommandLinelnfo cmdlnfo; ParseCommandLine(cmdlnfo); // // // if . /RegServer, /Register, /Unregserver /Unregister, FALSE, (!ProcessShellCommand(cmdlnfo))

return FALSE; // pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow() ; return TRUE;

// CAboutDlg class CAboutDlg : public CDialog i

38 public: CAboutDlg(); // enum { IDD = IDD_ABOUTBOX } ;

I.

protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV // protected: DECLARE_MESSAGE_MAP ()

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)

void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX) ; } BEGIN_MESSAGE_MAP (CAboutDlg, CDialog) END_MESSAGE_MAP() // void CMDIApp::OnAppAbout() CAboutDlg aboutDlg; aboutDlg.DoModal(); } // CMDIApp CMDIApp cwinApp, , , cwinThread. , . 32- Windows 16 , ""

2. ,

39

. , . 16- Windows , . . "" , 32- Windows, , , . , , , . . 12. , MFC, , cwinApp. winMain, MFC. i n i t i n s t a n c e , , .

i n i t i n s t a n c e . Afxoielnit, OLE . AfxEnableControiContainer, OLE. SetRegistryKey , ini, Windows. , . File (), , . 2.1. L o a d s t d P r o f i i e S e t t i n g s . 7. , i n i t i n s t a n c e .

40 I&RichApp - RichAppl ; ; ? 8 1 ^ File Edit V w F r a W d w H l e om t n o e i i p Nw e Ctrl+N Open... Ctrl+O Cs l e o Sv ae Ctrl+S S v As... ae Print Pe i w rv e Print Setup.., 1 EM n flOKyrieHTbi\FIRST\Fourth : o \ 2 E\ r i A KM H bF 5 \ hd :Ma O y e T \ I TT r lR i3 :\ AOKyMeHTbi\FIRST\Second 4 :\ AOKyMeHTbi\FIRST\Rrst Exit

I. i D i x l

4 . J- .- -1> ^

-

'

!

.

1

h

'

r i ' , '>:.*,.

' .

',

r

,,

; ' : V.-.-,*

- ' ,

'-.--*

.,-;

-.--;.--"

. 2.1.

, . . : IDR_MDITYPE; CMDIDOC; cchildFrame, CMainFraim; CMDiview. CMuitiDocTempiate ( csingieDocTempiate). , , . , RUNTIME_CLASS , . .

2. ,

41

. . , . , , , . . , . Visual C++ 6.0, (CMultiDocTemplate CSingleDocTemplate)

(cchiidFrame CMainFrame). , Microsoft : 7.0 ( ). CMuitiDocTemplate cchiidFrame , CMainFraim . RUNTIME CLASS , . ( ) DECLARE__DYNACREATE, IMPLEMENT_DYNACREATE . cwinApp::AddDocTempiate, . . , , , , . , .

, CMainFrame. , CFrameWnd, . , CFrameWnd, CFrameWnd: :LoadFrame,

42

I.

, , CMainFrame. , , , , . LoadFrame CFrameWnd: : C r e a t e .

LoadFrame . mpMainwnd, . . ccommandLineinfo, . ParseCommandLme. ParseCommandLine CcommandLineinfo: : ParseParam, ccommandLineinfo. ProcessShelicommand, , . ProcessShelicommand , , . . Microsoft , Visual C++ - , , . , , . , . , , , , . ? ? . - . MFC , . ? , ProcessShelicommand, , . , , return, , ProcessShelicommand.

2. ,

43

, Windows . cwnd: :Showwindow , , , , . i n i t i n s t a n c e cwinApp: :m_nCmdshow. , . i n i t i n s t a n c e cwnd: :updatewindow, WM__PAINT , . WM_PAINT, . , , TRUE. . 13, .

MFC Application Wizard , . . MDI. MDI : 1. File | Open Solution ( | ). Open Solution ( ), . 2.2. 2. MDI MDI. . 3. View | Class View ( | ) ++. Class View MDI ( ), . 2.3. 4. Class View ( ) MDI Add | Add Class ( | ). Add Class MDI ( ), . 2.4.

44 I Open Solution L o in: | ' [ Visual Studio Project; ok_ l Brush I Console History_JDateTime ZjDDB I DialogZJDIB

I.

f-J

L - Tools -

I RichApp _1SDI :ZJ Sheet _ l Text _J Tool ZjVSMacros

My Projects

Desktop

_ J Edit App _JHelp J_jLine JjUst LlMDI Multi _ J PrintI Progress _ll Reflect

Favorite;

t File name:

F s o tp : [o t n F s e f y e s uo e l i li l i

zl

Cne acl

. 2.2. Open Solution

. 2.3. Class View - MDI

2. , I Add Class-MDI Templates: ~ n p n " TransicEC 5aT A L OE B T LD C nu e osmr A L OE B T LD AL T Provider Performanc...

45

A L Property T Pg ae

A L Sm l Generic Class T i pe Object

M C Class F Add a MC class, n FOpen I

M C Class F

MC O B F DC

Cancel

Help

. 2 . 4 . Add Class - M D I

I MFC Class Wizard - MDI

Welcome to the MFC Class Wizard This wizard adds a class that inherits from M C to your project. Options may change F depending on the base class selected. DHTMl resource ID:

Automation Creatable by type ID

" Finish I C n e acl. 2 . 5 . MFC Class Wizard - M D I Help

46

I.

5. Templates () MFC Class ( MFC) Open (). MFC Class Wizard - MDI ( MFC), . 2.5. 6. Class name ( ) CMyDoc, Base class ( ) CDocument Finish (). . 7. .. 46 CMyView, CView.

8. Class View ( ) MDI, CMDiApp, . 2.6, i n i t i n s t a n c e . MDI.cpp, .

!MDI Global Functions and Variables Eg Macros and Constants % CAboutDIg * CChildFrarne ' CMainFrame Bases and Interfaces * Maps CMDIApp(void) $ Initlnstance(void) OnAppAbout(void) *>* CMDIDoc * CMDIView * J CMyDoc * f CMyView +

. 2.6. MDI 9. i n i t i n s t a n c e 2.6.I 2.6. I n i t i n s t a n c e // CMDIApp BOOL CMDIApp::Initinstance() CWinApp::Initinstance();

2. , II OLE if ( .'AfxOlelnit ){

47

AfxMessageBox (IDP__OLE_INIT_FAILED) ; return FALSE; } AfxEnableControlContainer();

// // // , // . // , // . // : - // , , // SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(4); // INI // ( ) // . // , CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate(IDR_MDITYPE, RUNTIME_CLASS(CMDIDoc), RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CMDIView)); AddDocTemplate(pDocTemplate); // //

CMultiDocTemplate* pMyDocTemplate; pMyDocTemplate = new CMultiDocTemplate(IDR_MYTYPE, RUNTIME_CLASS(CMyDoc), RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CMyView)); AddDocTemplate(pMyDocTemplate); // CMainFrame* pMainFrame = new CMainFrame; // //

48

I.

if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m pMainWnd = pMainFrame; // , , // MDI m_pMainWnd // DragAcceptFiles. // , // CCommandLinelnfo cmdlnfo; ParseCommandLine(cmdlnfo); // . // /RegServer, /Register, /Unregserver // /Unregister, FALSE, if ( ! ProcessShellCommand(cmdlnfo)) return E'ALSE; // pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow() ; return TRUE;

10. MDI.cpp #inciude "MDiview.h" : #include "MyDoc.h" #include "MyView.h" 11. Class View ( ) cMyview. MyView.h. 12. 2.7. I 2.7 MyView.h ttpragma once #include "MyDoc.h" // CMyView class CMyView : public CView { DECLARE DYNCREATE(CMyView)

2. , protected: CMyView();

49

// , // virtual -CMyView();

// public: CMyDoc* GetDocument() const; public: virtual void OnDraw(CDC* pDC); // #ifdef J3EBUG virtual void AssertValid() const; virtual void Dump(CDumpContextS dc) const; #endif protected: DECLARE MESSAGE MAP()

ttifndef DEBUG // MyView.cpp inline CMyDoc* CMyView::GetDocument() const { return (CMyDoc*)m_pDocuraent; } #endif 13. Class View ( ) CMyView OnDraw. MyView.cpp, . 14. OnDraw 2.8.:

I 2.8 OnDraw

// CMyView void CMyView::OnDraw(CDC* pDC) CMyDoc* pDoc = GetDocument() ' ASSERT_VALID(pDoc) ;

50

I.

15. Dump , 2.9. ! 2.9 GetDocument CMyDoc* CMyView::GetDocument() const { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc))) ; r e t u r n (CMyDoc*)m_pDocument; // //

16. View | Resource View ( | ) ++. Resource View ( ). 17. MDI, , MDI.rc Add Resource ( ). Add Resource ( ), . 2.7.

I A d Resource d R s uc type; eo r e jg| Bm p ta i ji C r o us r ^ | Dao ilg J HM O TL _]) Icon Sj M n eu be string T b al e 44 T ob r ola[ Version

Import,..Custom.. Cancel Help

. 2.7. Add Resource 18. Resource type ( ) Icon () Import (). Import. 19. /res Files of type ( ) Icon Files ( ). Import () , . 2.8 20. MDIDoc. .

2. ,

51

Lookjn: : History

_J.\ti M I D

zi -

X . - os |-

!

M Projects y:

'. -M

D st p e ko

Favorites : r--" '. M N t ok y ew r Filename: I

zJ

. 2 . 8 . I m p o r t

Oe j pn Cne acl __^ f __ t*

21. Resource View ( ) IDI_ICONI Properties (). Properties (), . 2.9.

j I o Nd I o R > c n oe c n e Condition | res'iiconl ,ILU IDI ICON1 Russian

!

:

ID Language

I Filename | Specifies the name of the file that contains the data for this resource. . 2 . 9 . P r o p e r t i e s

' , :

22. ID ( ) IDR_MYTYPE.

52

I.

23. Resource View ( ) String Table ( ) String Table ( ). . 24. IDR_MDITYPE Caption () "\nMDI\nMDI\nMDI Documents *.mdi\n.mdi\nMDI.Document\ nMDI.Document". , . 2.10.'.. MDI - Microsoft Visual C+ + fdesjgnj - 158.,13|||^1^^^| Fiie Jb -4J , ^'1 x

-JffJ

i

Ei dt J '

4*^

prOjerr Vf S

guild

Cebug

Inois

Window P 1

help D^tug j l i ^c^t i . Resource View - MDI * MDI _ J MDI re*1 4+ i (!&^"1" j Dialog

7 - - 1 " -"* 9 ?

"

MDI.rt (String )*

I D _ _ _ L lakl128 I RM I F A E D A RM N A XD ^ P J I L F J S A P TT E 57344 57345 59136 59137 59138 59139 59140 59141 57600 57601 57602 57603 57604 57605 57606 57607 57609 5""664

Cactltn MDIJ"

A XI SI L M S A F_ _ E ESG D D I _ DC T RE T DI 1 A O _ X N . , I JJ I A O _ A S D t OC T R C P ft I J OC T R J M DN I A O JU I J DC T R. C L D M I A O .S R I J DC T R J R D W I A O JV I I DC T R. E D N I A O .P C ID.JILE J E JW I _ IEO E DF _ P M L ID^FILEjILOSF. I _ IE5 V D FL _ A E I _ IES V _ S D FL _ A E A I _ T E> G _ E U DF L JA F5 T P I _ L _ RM _ E U DFEP I T5 T P I _ IEP I T D FL _ RN I FL _ RM _ R V. D I E P I T P E ., A PA O T i: _ P _ E U up t Otu |Dehug

Ready EXT CAP NUM SCRL OVR REC Create a new document\nNew Open an existing dcicument\nOpen Close the active document\nOose Save the active document\nSave Save the active document with a new name\ri5ave As Change the printing optionst.riPage Setup Change the printer and printing options\nPrint Setup Print the active document\nprmt Display full pages\nprmt Preview DKplav proqram inforrnath , vf-t>.iun njmber and cop^ nght\iAbout

-

J Icon__] _J _ J IOPJ-1AINFRAME [English (U.5 ICR^MDITYPE [English (U.S.)] IDP_MfTVPE

++

j_ J _ J

MenuPT_MANIFE5T String Table

-

Sttmq Table [English (U.S.)] + _ J Toolbar+

f 'et^ian

| I ~ J J

f

l

"

1 Prop^rtie^ _ J i String Editor BlrEd

*

* _]

1 (Name) 1 5 Beady i output :'l . ^ Properties | 0 -.;.:. i...: H^:; :

. 2 . 1 0 .

25. ID ( ) , . . IDR__MYTYPE. 26. Caption () "\nMy\nMy\nMy Dopuments *.my\n.my\nMy.Document\nMy.Document". 27. Resource View ( ) Menu (), IDR MDITYPE ().

2. ,

53

28. Menu () Paste (). IDR_MDITYPEI. 29. IDR_MDITYPEI ID ( ) Properties () IDR_MYTYPE. 30. . New (), . 2.11.

. 2.11. New 31. . New () . 32. File | Open ( | ) Open () . Open (). 33. Files of type ( ) , . 2.12. 34. Open () . , , . , , , GetDocument , . , . Visual C++ , , , , , , MFC Class Wizard, CDocument GetDocument.

54

I.

. 2 . 1 2 . Open

, , , CDocument, . , , , MFC Application Wizard. Get Document OnDraw. , . , CMDIAPP: : i n i t i n s t a n c e , . . , , , , . , . , , New (), , Open () Save As ( ), , . 13 .

3

, MFC, /, . , Windows. , - , , . , , . , , - , . , , , , , .

Windows , . , : , , , , , , . .

Visual C++ , , . , , , , ,3 . 629

56

I.

, , . Resource.h, . , , , . #include, , afxres.rc afxprint.rc. , , , Resource View ( ). , . , , . Visual C++ 6.0 . Visual Studio.NET Visual FoxPro, C + + . . D l g - M r s f Vs a C + [ e i n - Dao i H D . io a i o ot i u l + d sg j i l gc O cEdit Jflew Project Build Eebug Format lools

gle

Window

!

" g Dialogic (IDD_...IALOG - Dialog) |

& - 3 1 Dialog - _J Dialog re j Dialog IDDJBOUTBOX [Englis ^ J Icon _J P-T_MANIFEST + J 5trmg Table _ J Version

,1

i

i |

i | Cne acl

\i I ; ! T O : Pc d o c nr s C O ae a g o to l il l

| jI Dialog Node IDIgRes

(Name)Ready

. .1.

3.

57

Dialog, 1. , 1 . MFC Application Wizard . 3.1. Dialog , . , , : 1. , , - Resource View ( ), View | Resource View ( | ) ++. Resource View. - , Microsoft , Resource View ( ) . 2. TODO: Place dialog controls here, , . . 3. Dialog.rc , , Dialog. IDD DIALOGDIALOG. Resource View ( ) Properties () . Properties () , : I D D D I A L O G D I A L O G Properties (). ; ; , , , , . .

View | Properties Window ( | );

4. Properties () Language (). . 5. "Russian" (). 6. . Properties () .

58

I.

7. Caption () Appearance ( ) " ". 8. Output ( ). , , , , . . 200x320 . 9. Toolbox (). , . 3.2.. Dialoa- Microsoft V ^ t H [ d . M ^ U i H B H H i File Edit View Project guild Eebug Fu/niat T n yndow tHp nK .|-^-.=* $ Toolbox ,ja Dialog Editor ., General f ^PC nte

R, '" -o *

> Debug

-

:

i3

T

ext

"

i& sv

1 ' X

Resource View - Dialog4

X.

uxj | OK Caned 1 J

rc*

' '

^ IDD.ABOUTBOX [English (U.S.)) 5 IDD_DIALOG_DIALOG [English (U.S.)] ?T_MANIFEST 5trmg Table Version

\\

!

i j j 1

Properties

9

X ^J

| IDD_DIALOG_DIALOG (Dialog)

|::|S* [oi|-/ 1 (Name) 0 [S1 Properties \0 ,r KIi j!"" 2 0 x 3 0 0 2

Ready

J

-

. .2. Toolbox 10. Dialog Editor ( ), . 3.3. 11. Static Text ( ), , ,

3.

59

. , . 3.4.

Ee E t ^ w Po c g i bg Fgtruat lools Wdw Hp r d e r j t u eu i i i e l d no e i lP . * % ' Ctalgg Editor 1^ Pointer Buttun fx Check Box ab| Edit Control Combo Bo> List Box l"*] Group Box (* Radio Button Static Text ( $ | Picture Control EB Horizontal Scroll Bar Vertical Scroll Bar 0- Slider Control # Spin Control EE3 Progress Control Hot Key ?2J List Control ffc Tree Control C 3 Tab Control Q Animation Control Ao Rich Edit 2.0 Control General Ready | ' z\ (name) 6*Properties | ~ " '..I- I':

| i i i i i i i ill 1 10>

x

Resource View - Dialog

4

x

1 1 1 l

ig re jolog ^ IDD_ABOUTBO)i [English (U.5.)] 3| IDD_DIAH:'G_WALOG [English (U.S.)] con JT_MAflIFEST Ihrg Table Version

Caned

:

_iJ 3--". Properties flDD_DIALOG_DIALOG (Dialog) ^ C .

1 * aReso...| * X J^J

jTT) $i [] -/ "

. 3 . 3 . Dialog Editor

12. Caption () Properties () " ". 13. Edit Control ( ) Toolbox (), . . , , . ( ). , , , , .

60

I. .

. Dialog - Microsoft Visual C++ [design] - DMlog.rc (J5> Ble Ed* Bew Eroject guild P_ebug Forniat Iools Window Help

j p ' - e 4

I IT1! I?', - -

Debug ^ t Resource View - Dialog igrc* Dialog 3| IDD_ABOUTBOX [English (U.S.)] 3 IDD_OIALOG_DIALOG [English (U.S.)] ^con f!T_MANIFEST String Table /ersion

Sb, Dialogic (IDD...ALOG - Dialog)* |

Ready

. .4. , , . . , . , , . , . 3.5. 14. ID ( ) Misc ( ) Properties () I D C E D I T I IDC_EDIT_BOX.

3. Dialog - Microsoft Visual ++ [design] - ^ " :

.i t x Resource View - Dialog .grc* Jiaioa 3 IDD_ABOUTBO>! [English (U.S,)] 3] IDD_DIftLOS_DIALOS [English (U.S.)] tcon (T_MANIFE5T jtrmg Table Version

Dialog.rc (IDO..ALOG - Dialog)*

*i

| Sme e t bx ap d o l i

?

Bitmap Caption Chert Edge Flat

False ? False False

Caption Specifies the text displayed by the control. _>J Ready Properties | & i i >

" 23,165

;!"* 10x56

. .8. . 26. Toolbox () Group Box ( ), . 27. Captions () Properties () " ". 28. Toolbox () Radio Button () . 29. Properties () IDC_EDIT_SWITCH, Caption () " " True Group (), Misc ( ).

3.

65

30. .. 28 29 , . IDC_SPIN_SWITCH " ". Group (). , . 3.9. Dialog - Microsoft Visual C + + [design] - - (>_01

i E t Sw Eo c g d Qbg Fr a l o W o Hp d e r e t u eu o t o k n w e i t f i l i m id l3' J ^ LRESULT CPagel::OnWizardNext(void) { // CSheet* parent = (CSheet*) GetParent(); // CButton* checkBox = (CButton*) GetDlgItem( IDC_CHECK ); if( !checkBox->GetCheck() ) // { MessageBox(" "); return -1; j

// , p a r e n t - > SetActivePage( p a r e n t - > GetPageIndex{ &parent-> m_page3) r e t u r n CPropertyPage::OnWizardNext();

17. 18.

Page3.cpp. , 3.10.

I 3.10. // BOOL ::OnSetActive(void){

CPropertySheet* p a r e n t = (CPropertySheet*) G e t P a r e n t ( ) ; p a r e n t - > SetWizardButtons(PSWIZB NEXT [ PSWIZB BACK);

3. return CPropertyPage::OnSetActive();

95

// ' SetActivePage( parent-> GetPagelndex ( &parent-> mjpagel) + 1 return CPropertyPage::OnWizardBack() ;

// Finish void ::OnClickedCheck(void) { // CSheet* parent = (CSheet*) GetParent ; // CButton* checkBox = (CButton*) GetDlgItem( IDC_CHECK if( !checkBox->GetCheck() ) // checkBox->SetCheck( 0 ); else checkBox->SetCheck( 1 ) ; parent->SetFinishText("Finish") ;

// Next> LRESULT ::OnWizardNext(void) { // CSheet* parent = (CSheet*) GetParent ; // , parent-> SetActivePage( parent-> GetPagelndex( &parent-> m_page2) 1 ) return CPropertyPage::OnWizardNext();

I. 19. . , . 3.24. , Next () 3, 2, . , Next (), 2. 2 . 3 ?, , . 3.28.

. 3.28. ? CPropertysheet:: setActivePage. , , . . , 0, , . AddPage. , SetActivePage onWizardNext onwizardBack, , , . CPropertysheet: :setFinishText. , Finish (). , Back () Next () Finish () ( , ), , . -

3.

97

? Back () Next (). , . , Finish (), OnWizardFinish, . OnWizardFinish . , . OnSetActive , setwizardButtons. , , Finish () Cancel () ( Help () ). , . , Back () . Finish () , , , , . Finish () , , . , . , OnWizardFinish . . OnWizardFinish, , . . CButton: :Getcheck ( ) CButton: :Setcheck ( ).

II

4. 5. 6. 7. 8. 9. 10.

4

3 . , , . , , . . , , . , . . , .

List List, List , . : 1. , I, List. 2. Dialog () Resource View ( ). IDD_LIST_DIALOG Properties (). Properties (). 3. Language (). . 4. Russian (). 5. Output () . 6. Caption () Properties () " ".

102

II.

7. Caption () Properties () "". 8. . 9. Toolbox () List Box () , , . , . 4.1. oft Vs a C + [ e i n J - U4 i u l + d sg E t Im Eo c f* Eeu Fr a I o fi d w Hp d i r e t t >bg o t o l n o e l m s l iiil - & Q & t, KA ' ' - ' Dbg eu

,

mm

\.

So, Ltr ( D J.I L G - Do ) | i.c I J. O a g . D A ilI"

i t x i! Rsue V - Lt ? er e s oc iw i - 3 Lt 3i s - _J utr* s.c - _ Dlg Ja io 3DAOTO [ns ID U X Eg .B B i l 3|D_IT AO IDS_IL G LD + ]cn Io _ J RT_M^FEST * _ ] Strug Table + J Version

Proportles

J C . T ( i t o C nr l L E J I JI Lsb x o to) IB D S [77] h [a] -/ i Group ID Tabstop (Name) False IDC.LIST True

Ready

. 4 . 1 .

10. Toolbox () Static Text ( ) . 11. Caption () Properties () " ".

4.

103

12. Toolbox () Edit Box ( ) . 13. Properties () I D C E D I T . , . 4.2.

Ls - M r s f Vs a C+ + [ e i n - Ls.c (D LS 0 i t i o ot i u l c d sg } i tr I O I T E i #w Po c B d Qbg Fr a l o W o y l d e r e t u eu amt o l n w e t j l i s id p jp - _J \F~ H * " Dbg eu H -U [5J. % Ust.rc (D _ I. A O - Dialog)* | I D L.J L G i],,,i, ,,, *J

I I > R s uc Vw L t eore e i i s

:

- List - _|List.rc* - _J Dialog 3 ] IDD_ABOUTBOX [Engli! ^ IDD_LI5T_DIALOG + : ( Icon + _J RT .MANIFEST _J String Table + _ J Version

__ Sample edit box

flDC_EDIT (edit Control) IEdBoxEjJ QT] Si [ a ] -/

Go p ru I D T bt p a so (Name)

Fs ae l I CE I D _D T Tu re

Ready

. 4.2. 14. Toolbox () Button () . 15. ID ( ) Properties () IDCADD, Caption () "&". 16. , .. 14 15, IDCDELETE "&". , . 4.3.

104

II.

B E t yw Eo c g d Pbg Fr a I o Sno tjelp e d e r et u _ u o t o l S w l i j j l e i m s Id *! J ' t S H S * Ri *" ' ' - < * W." Dbg eu % U tr ( DU. L G - Dao ) | s.c I _ .I O D A i l g*i I. . 2=1

, list - Microsoft Visual C++ [design] - (IDOJLISI'JWWOtf?

1 I X ' Rsue Vw - list _ _ ? eor ^ e c i _ . - _J Ls.e i tr * - _] Do ag il J3|DAOTO [ n s IDB UB X E g . i l I 3 D _ITWL G I DL _ AO 5 j * L I o Jc n ! A _J R_ AF5 T NT M IE ;! _| Sr g Tb tu ae l + | Vrrn ea s

j Sample edit box

1

Properties

iD _ EEE ( ut n C nr l I CDLT B to o to) Gu rp o Fs ae l D I D_ EEE I C LT D Tbtp T e as o r u(

E^1 Properties | nJ in help Ready ," 166, 97* j l * 14 X50

. 4..

17. Cancel () Caption () Properties () "". 18. I D C L I S T ControlEvents ( ) Properties (). , . 19. LBNDBLCLK. . 20. , , OnLbnDbiclkList, -. 4.4. 21. . , CListDig, -

4.

105

.

JIDC_LIST (Listbox Control) I B dt r L E io QT] a, m [ 7 } L NE R P C B _R S A E L NKLO U B _ LF C S I L NSL A CL B _ EC N E L NSL HN E B _ EC A G L NSTO U B _ EF C S N T E E HN E M HMC A GD < d > O L n bcHs A d nb D l l it

.B _ BCK L ND L L ' Indicates that the u e h s d u l - lc e the left m ue s r a o beci k d os button in the control . 4.4. Properties 22. , ControlEvents ( ) Properties (). , . 23. BNCLICKED. . 24. , , OnBnciickedAdd. 25. . . 26. .. 2225 . 27. Class View ( ), List. 28. CListDig Add | Add Variable ( | ). Add Member Variable Wizard - List ( ), . 4.5. 29. Control variable ( ). Control ID ( ) Control type ( ) . 30. Control ID ( ) IDC_EDIT.

106Add Member Variable Wizard - List

II. xj

Welcome to the Add Member Variable Wizard This wizard adds a m m e variable to your class, struct, or union. e br

Access:Variable type: jbool Variable name:

~ Control variable

!

C o m m e n t

(//

n o t a t i o n

n o t

r e q u i r e d ) :

"J Fs nh ii Cne acl Hp e l

"

. 4.5. 31. Category () Value (), Variable name ( ) m_Edit Finish (). 32. .. 28 29 Control ID ( ) IDC__LIST. 33. Control (), Variable name ( ) m_List Finish (). 34. ListDlg.cpp 4.1. : 4.1. CListDlg // void CListDlg::OnLbnDblclkList(){

j

CString Temp; i f ( m_List.GetCurSel() != LB_ERR )

//

4.

107

II m_List.GetText (m__List .GetCurSel () , Temp) ; // SetDlglteraText(IDC_EDIT, Temp);

// Add void CListDlg::OnBnClickedAdd(){

// // m_List.AddString(m Edit); //

UpdateData();

// Delete void CListDlg::OnBnClickedDelete() { if( m_List.GetCurSel() != LB_ERR ) // m_List.DeleteString(m_List.GetCurSel); // UpdateData(); . //

35. . , . , . 4.6. 36. 37. "" . . "" . .

38. "" . . , List Box () Behavior () Properties () Sort () True (), . 39. . "", . 4.7.

108

II. V I

-J X

I

I

. 4.6. I- ( J I

I

. 4.7.

40. , . , , . 4.8. .

4.

109

, , . Visual C++. .1

DTOpOH

. 4.8.

OnLbnDbicikList cstring Temp , cListBox: :GetText, . , cwnd: :SetDigitemText, Temp . , . onBnciickedAdd : UpdateData , CListBox: :Addstring . onBnclickedDelete , cUstBox: :GetCurSel, , , . , CListBox: :Deietestring, , . , , CListBox: :Setsel, , -

110

II.

, TRUE, , FALSE, .

Progress, , . : 1. 2. , 1. Progress. Dialog () Resource View ( ). IDD__PROGRESS_DIALOG . Properties (). Language (). . Russian (). Output ( ) . Caption () Properties () " ". . Cancel () Caption () Properties () . .

3. 4. 5. 6. 7. 8.

9.

10. Toolbox () Progress ( ) . , . . ID ( ) Properties () IDCPROGRESS. , . 4.9. 12. Toolbox () Slider Control ( ) . 13. ID ( ) Properties () I D C S L I D E R .

4.

111

file t Vw Po c g d Qbg Fr a To y not telp d e r f t u eu o t os j t r i c l i m l y ^p - U - u^ LJ ^ ^ s r ' '" Dbg eu ^ Po r s .c (. L G - Dialog)* j r ge sr IA O . * .1..., ,;,,,,.' ' '7.7,

.- Progress - Microsoft Visual C+*ld^dn}~P

- L

' i+ U f* ^ T X Rsue V - Pgs fl1 X e r e r rs oc iw oe Prr_ris g P ga -o es j b D ^D_ OTO [ns ( . IDBU X Eg U A B ih l ^|D_RGE5A G ID ORS_IL P DO + |cn Io * RMNS J T AF T _ I E + j Sn Tb t g ae r l i + _J Vro _ ein s

| IDC PROGRESS (Progress Bar

P prs r ei oe tDisabted Help ID Visible

False False True

()

Ray ed

E* Pprs | Q Dnk hp l re oe t i va e r l i;H"J 16, j j Hx?i2

. 4.9. 14. AutoTicks ( ), entEdge () TickMarks ( ) True (). 15. , , . , . 4.10. 16. Toolbox () Picture Control () . 17. ID ( ) Properties () IDCPICTURE. 18. Sunken () True (). 19. . 4.11.

112

II.

El E* tfew Eroiect B id Cbg F r a Iods fflndow U p ie ul e u am t e lJ - J J - i. Ql \ 0 3 ' " 4. . > Dbg eu

- ;.! Jj Po r s .: (. L G - D l g" | r ge s IAO i o ) . ai

1 t X , Rsre Vw - Pors- ^ Jt X erj e rges a t c P Po r s r ges - Q Po rs.e rges * r -i _J Do ag il ^D_BU O [ ns ( IO OT X E gh U A B il] IDD_PROGRESS_DIALOG + ]Icon I _| RT_MANIFE5T * _ J String Table + ] Version

3 -

lJU

Properties _ j IDC.SLIDER (Slider Control)

Disabled Help ID Visible

False" False True

I (Name)

,

& Properties | D (i- i "ip j " 29x212

Ray ed

''"I 16,66

. 4 . 1 0 .

20. Toolbox () Button () . 21. ID ( ) Properties () IDC_RESET. 22. Caption () "&". , . 4.12. 23. , ControlEvents ( ) Properties (). , . 24. BN_CLICKED. . 25. , , OnBnClickedReset.

4.

113

E E t yw Eo c Bd Pbg Fr a I os Mdw Hp e d e r e t u su o t o l no e l i j i i l j m l J - ' d ' ^ i i & 9 F ' 1 -'", v i Dbg 5 ' eu P__l- ' -.. SEE ], ! |) Po r s r (. L G - Dao ) | r gecc IAO i l g* . *i ; J T

. Progress - Microsoft Visual C++{design]

d*

] t X ; Rsue V - Pgs _? > ! e r e r rs _ < oc m oe " ~ ~(p P g s r rs oe '-' _ P gs.* J r rs oe r e J -, _1 Do ag il. IDD_ABOUTBOX [English (U iP 3 roD_PRCX3RES5_DIALOG * _ J Icon i i *' 1 RT_MANIFEST ]'. _J String + ^ j Version

I

1 I Properties _jIDC_PICTOREt (Picture Control _, Disabled Help ID Visible False False True

1

(Name)

! * Properties | 0 : i M p ,

Ra y ed

"I 177lO8

jf* 20x212

. 4 . 1 1 . 26. . . 27. Class View ( ) CProgressDig. 28. Properties () Messages (). , . 29. WM_HSCROLL. . 30. , , cmHScroii, . 4.13. 31. . , CProgressDig . 32. CProgressDig Add | Add Variable ( | -

114

II. ). Add Member Variable Wizard ( ).

**.. Po r s - M r s f V u l C r ges i o ot i a + c s F E t Vw Po c Bd bg Fr a To Wo Hp i d e r e t u eu o t os n w e l e i i j l i m l id l la] Sj Po r s j (. L G - Dialog)* | r ge sc I A O . , r:. ,.7:7,7:7,, ,,. []. ; ;,..:;

- . Text

, .? is [ x R s uc Vw - Po r s eo re e r ges i ^ X P Progress - _j Po r s , re* r ge s f " ID l g io a 3 D _B UB X [ n ls (U, I DA O T O E gi h 3] toD_PROGRE55_DlALOG + ] Icon + _J R_ A FS TMNE T I + j String T b ae l + jV ri n es o jj ,

I

Po ete r p ri s ] 1 CRST (Button Control) D _ EE Q ] 4 -/ ' T * . Hp I e D Fs l ae l O nr Dw Fs we r a* a l Vb se ii l Te r u

1.4

.

(Name)

Eg Properties | Q .

Ray ed

T ; 97, 167

i n 14x50

. 4.12.

| CProgressDIg

VCCodeClass

d

*

W M I G E T D L G C O O E

j j

WM_GETMINMA! 3 4 10 11 17 18 24 25:

" 5 12 19 26

2D 31. 03.2001

. 4.23.

4.

133

38. . . 39. . , . , , . 4.24.MV

14.03.2001

1< 5 12 19 26

2001 . 1 8 15 22 29 2 9 16 23 30

t 1 Be 4 3 10 11 17 18 24 25 31

6 7 13 20 21 27 28

: 31. 03.2001

[ j|

(

. 4 . 2 4 . IA- !

17-38-59 5 12 19 26

2 . 1 2 8 6 7 13 4 15 16 20 21 22 23 27 28 29 30 3 10 17 24 31

8 4 11 18 25

: 31.03.2001

[

:|

!

. 4 . 2 5 .

134

II.

40. . . 41. . , , . 4.25. 42. . , , . 40. 43. . . , , . CDateTimeDlg::OnDatetimechangeDatetimepicker Date Time Picker ( ). (, ) . CDateTimeCtrl: :GetTime. CTime. CDateTimeDlg, . , CMonthCaictr: :SetCurSei . CDateTimeDlg: :OnSelectMonthcalendar . CMonthCaictr: :GetCurSel. , . CDateTimeCtrl : : SetTime.

CDateTimeDlg: : OnClickedSelect -

. , , . cwnd: :SetDlgitemText, , , , . cwnd: :ModifyStyle. , , ,

4.

135

, , SetwindowPos. , SetwindowPos. m b s e l e c t , . CDateTimeDlg: : OnClickedDatetime, . . , , cwnd: :SetDlgitemText . CDateTimeCtrl::SetFormat.

5

" ". . Windows DOS. - , , DOS . Windows . , . , , . Windows MFC. , , , .

. . . #define. , , Resource.h, . . Windows WM_, Windows (Windows Message). , . , , ( ).

5.

137

, . , , . . MFC , WM_KEYDOWN, WM_MOUSEMOVE , , . , . Windows (Message Loop), winMain. MFC , . while, GetMessage, . , , , PostThreadMessage. . , . , WMQUIT, . . 1, , . , , TransiateMessage. . GetMessage PeekMessage. , . , , DispatchMessage, , , . ( switch), . , , MFC .

138

II.

(Message Map) MFC . , MFC, . , Visual C++ : . , ccmdTarget, . , , . , , DECLARE_MESSAGE_MAP, . , , BEGIN_MESSAGE_MAP, , , . END_MESSAGE_MAP, . Visual C++ 5.0 6.0. 7.0 . Visual C++ 7.0 , MFC Application Wizard. , Properties (), (public). 5.1 , , 4. ; 5.1. // DialogDlg.h :

#pragma once // CDialogDlg class CDialogDlg : public CDi.alog { //

5. public:

139

CDialogDlg(CWnd* pParent = NULL); // // enum ( IDD = IDD_DIALOGJDIALOG } ; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV // protected: HICON m_hlcon; // virtual BOOL OnlnitDialog () ; afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDraglcon() ; DECLARE_MESSAGE_MAP () public: afx_msg void OnCbnCloseupCombo(); afx_msg void OnCbnEditchangeCombo(); afx_msg void OnDeltaposSpin(NMHDR *pNMHDR, LRESULT *pResult); UINT m_Edit; UINT m_Buddy; CString m_Combo; BOOL m_Save; int m_Switch;

(public) . . 5.2 , 5.1. 5.2. , BEGIN_MESSAGEJ4AP (CDialogDlg, CDialog) ON_WM_SYSCOMMAND () ON WM PAINT()

140

II.

ON_WM_QUERYDRAGICON() //} }AFX__MSG_MAP ON_CBN__CLOSEUP (IDC_COMBO, OnCbnCloseupCombo) ON_CBN_EDITCHANGE(IDC_COMBO, OnCbnEditchangeCombo) ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnDeltaposSpin) END_MESSAGE_MAP () , . , : ONCOMMAND , WM_COMMAND, . , , , ; ON_COMMAND_RANGE ON_COMMAND, , . , , , , . , , , ; ON_UPDATE_COMMAND_UI , . , . , , , ; ON_UPDATE_COMMAND_UI_RANGE ON_UPDATE_COMMAND_UI, , . , ON_COMMAND_RANGE, ; ONCONTROL . . ON_CONTROL. , , , ; ON CONTROL RANGE , , PAINT.

5.

141

, ONCONTROL, , ; ONMESSAGE . WM_USER 0x7 FFF , Windows WMMESSAGE. ONMESSAGE. , , , .

Windows 3.x Windows 3.x , , . . WM_COMMAND, (, B N P A I N T ) , , wParam , , lParam . , . . , BN_CLICKED . Windows 3.x , WM_CTLCOLOR, WM_VSCROLL, WM_HSCROLL, WM_DRAWITEM,

WM_MEASUREITEM, WM_COMPAREITEM, WM_DELETEITEM, WM_CHARTOITEM, WM_VKEYTOITEM . , .

Win32 , Windows 3.1, Win32 API . Win32 , Windows 3.x. . , , WM_*, Win32 API , WMNOTIFY, .

142

II.

NOTIFY , , wparam lParam. NMHDR, , NMHDR. NMHDR , , iparam , NMHDR. NMHDR , . ( ) TTN SHOW TTN POP. NMHDR. NMHDR , , (, SHOW). :typedef s t r u c t{

tagNMHDR

HWND hwndFrom; UINT i d F r o m ; UINT code; } NMHDR;

TTN SHOW code TTN__SHOW.

, NMHDR, , LVNKEYDOWN . , LV_KEYDOWN, : typedef struct tagLV_KEYDOWN { NMHDR hdr; WORD wVKey; UINT flags; } LV_KEYDOWN;

, Windows , Windows. , -

5.

143

NMHDR. : NM_CLICK , ; NM__DBLCLK , ; NM RCLICK , ; NM_ RDBLCLK , ; NM_RETURN , , ; NMSETFOCUS , ; NM_KILLFOCUS , ; NM_ OUTOFMEMORY , .

cwnd: :OnNotify. . . . Visual C++ ON NOTIFY , . ON_NOTIFY , , , LVN_KEYDOWN, , , . : afx_msg void memberFxn(NMHDR ^pNMHDR, LRESULT,*pResult) : memberFxn ; PNMHDR , ; pResult , .

144

II.

, , onDeitaposSpin UDN_DELTAPOS, cspinButtonctri I D C S P I N , : ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnDeitaposSpin) : void CDialogDlg::OnDeitaposSpin(NMHDR *pNMHDR, LRESULT *pResult) { NM_UPDOWN* pNMUpDown = (NMJJPDOWN*) pNMHDR; // TODO: Add your control notification handler code here *pResult = 0; } , . NM_UPDOWN pNMUpDown, P'NMHDR . : void memberFxn(UINT id, NMHDR * pNMHDR, LRESULT *pResult) , , , ON_NOTIFY( ON_NOTIFY_RANGE) ON_NOTIFY_EX ( ON_NOTIFY_EX_RANGE). -

, BOOL, , . FALSE, TO . ON_NOTIFY_EX ON_NOTIFY_EX_RANGE -

, . , , : ON_NOTIFY_EX(nCode, id, memberFxn) ON_NOTIFY_EX_RANGE(wNotifyCode, id, idLast, memberFxn) . : BOOL memberFxn(UINT id, NMHDR * pNotifyStruct, LRESULT * result); id , .

5.

145

TRUE, , FALSE, .

MFC 4.O. , . , WMCTLCOLOR , . Windows MFC , 4.0, , , . , , . , , , . , . MFC 4.0 , . , , , (message reflection), , . WM_CTLCOLOR , - . , , , , MFC, Windows, , , cwnd. MFC , (WM_DRAWITEM ). . , , , MFC.

146

II.

, , . WM_NOTIFY . , , , ON__NOTIFY_REFLECT. ON_NOTIFY_REFLECT_EX, , . , , TRUE, TO , FALSE, TO . WMNOTIFY, . , . , , . , , : REFLECT. , WMNOTIFY ON NOTIFY, ON_NOTIFY_REFLECT. . Visual C + + , .

, , . ,

5.

147

MFC, . , , : , ON_ _REFLECT. , WM__CTLCOLOR ON_WM_CTLCOLOR_REFLECT. , , . : WM_COMMAND ON_CONTROL REFLECT;

NOTIFY ON_NOTIFY_REFLECT;

ONJJPDATECOMMANDJJI ON_UPDATE COMMAND UI_REFLECT.

, on . , c t i c o i o r Oncticolor. , . , . . 5.1 . 5.1. ON_CONTROL REFLECT(wNotifyCode, memberFxn) ON_NOTIFY_REFLECT(wNotifyCode, memberFxn) ON_UPDATE_COMMAND_UI_REFLECT (memberFxn) ON_WM_CTLCOLOR REFLECT() ON_WM_DRAWITEM_REFLECT() ON_WM_MEASUREITEM REFLECT()

afx_msg v o i d memberFxn ();

afx rasg v o i d memberFxn (NMHDR * p N o t i f y S t r u c t , LRESOLT* r e s u l t ) ; afx msg v o i d memberFxn pCmdUI); afx msg HBRUSH C t l C o l o r UINT n C t l C o l o r ) ; (CCmdUI* (CDC* pDC,

afx_msg v o i d Drawltem (LPDRAWITEMSTRUCT l p D r a w I t e m S t r u c t ) ; afx_msg v o i d M e a s u r e l t e m (LPMEASUREITEMSTRUCT lpMeasureltemStruct);

148

II. 5. 1 ()

ON_WM_DELETEITEM_REFLECT{)

afx_msg void Deleteltem (LPDELETEITEMSTRUCT lpDeleteltemStruct); afx_msg int Compareltem (LPCOMPAREITEMSTRUCT lpCompareltemStruct); afx__rasg int CharToItem (UINT nKey, UINT nlndex); afx__msg int VKeyToItem (UINT nKey, UINT nlndex); afx_msg void HScroll (UINT nSBCode, UINT nPos); afx_msg void VScroll (UINT nSBCode, UINT nPos); afx_msg void ParentNotify (UINT message, LPARAM lParam);

ON_WM_COMPAREITEM_REFLECT()

ON_WM_CHARTOITEM_REFLECT() ON_WM_VKEYTOITEM_REFLECT() ON_WM_HSCROLL_REFLECT() ON_WM_VSCROLL_REFLECT() ON WM PARENTNOTIFY REFLECT))

ON_NOTIFY_REFLECT ON_CONTROL_REFLECT

( ). . 5.2. . 5.2. ON_NOTIFY_RE FLECT_EX (wNotifyCode, memberFxn) ON_CONTROL_RE FLECT_EX (wNotifyCode, memberFxn) afx_jnsg BOOL memberFxn (NMHDR * p N o t i f y S t r u c t , LRESULT* r e s u l t ) afx_msg BOOL memberFxn () ;

, , Microsoft . , . , , , , . , -

5.

149

. , , . , Microsoft , , Visual C++ , . 3 . , . Dialog (. 3): 1. File | Open Solution ( | ). Open Solution ( ), . 5.1.

lopen SolutionLookjn:

______ ' 1 Vu l S d Po cs s a r r r et i ua j JJJ jBrushi 1 Rhp cAp i _ll Cno ose l ID SI History _Dt T e La m l ei 1 Set he _J D !D B _T > t ]e c l 11 Do 1 ag il ZlTool ' ZDB jI HS ars V Mco i M Po cs Z dA p y r et j i p j Et Hp ie l ZiLine -U IList Dstp ZJMDI ek o _1 M t ui l 2J Pn rt i _. " 1 Po rs rges F v re _ll R f c aot s i ee t l F nm: j i ae l e F s o t p : |Solution F s e fye l i e l i

tii fU

- o[s-

d zl

! acl Cne

. 5 . 1 . Open Solution

2. Dialog Dialog. Visual C++ Dialog. 3. Class View ( ), Dialog () Add | Add Class ( | ). Add Class - Dialog ( ), . 5.2.

150 Add Class - Dialog; Categories;

II. 2 i D e l t a = -pNMUpDown-> i D e l t a ; *pResult = 0;

12. Class View ( ) CDiaiogDig Events () Properties (). , . 13. I D C S P I N UDN_DELTAPOS. . 14. OnDeltaposSpin. . ( .) 15. Class View ( ) CDiaiogDig Add | Add Variable ( | ). Add Member Variable Wizard - Dialog ( ), . 5.5.

A d M m e Variable Wizard - Dialog d e br Welcome to the Add Member Variable Wizard T i wizard a d a m m e variable to your class, structj or union. hs d s e br

A c s: c es Variable type: Variable n m : a e i ,. .1

C m e t (// notation not required): o mn

Finish

)

Cancel

j

Help

|

. 5.5.

5.

153

16. Control variable ( ) IDC_SPIN.

17. Variable type ( ) MySpinctri, Variable name ( ) m s p i n Finish (). . 18. . . , UDNDELTAPOS. , coiaiogDig. , . : , , . , , , , .

, cwinApp, Run. cwinThread: : Run, , GetMessage, TranslateMessage DispatchMessage. cwnd AfxWndProc, wndProc, . WndProc , , MFC (handle map), . cwnd, . windowProc. , cwnd, , . windowProc, , C++ onWndMessage, , , . -

154

II.

: , . , . , , . C++, , , . MFC , . , File | Open ( | ) MFC S e r i a l i z e . .

. , , . , .

Properties , , Properties (). Properties ( , ), View | Properties Window ( | ), , . , . 5.6, Properties (). Properties (), . 5.7, , . , . 5.7, Categorized ( ), , Properties (), . Alphabetic (), ,

5.

155

Categorized ( ), , .

F E t Vw Poc u uog l os Wdw Hp e i i l d e r et fd eu o l no e i j ili i l % Do D h | J ag I il g- .31 Dialog blobal Functions end Variables Macros and Constants "f CAboutDIg * J CDiaiogApp

ii

i i

r

i

T

I m r i 1 h"

* Go To Definition * bo s Definition r we ^ O u k n Sm o _ cF d y b l i it t

TDialogDlg(CWnd* p P a r e n t = NULL;

Propei tie J j MySpir I aFillRect(rect, SCBrush(RGB(255, 0, 0))); rect.left = rect.right; rect.right += wd; pDC->FillRect(rect, SCBrush(RGB(0, 255, 0) ) ) ; rect.left = rect.right; rect.right += wd; pDC->FillRect(rect, &CBrush(RGB(0, 0, 255))); } was_copied = false;

14. . , . 6.11.

6.

199

Be Edit., w Wdw H p l e no e i i l

Kdy BU . 6 . 1 1 .

15. , . . . 16. . . 6.12. 17. . - , ( ). , OnDraw. , , , cwnd: :GetciientRect, , cwnd, , . -

200

II.

, . m_Rect. , wd, . CDC: : F i i i R e c t , . onDraw , , was_copied FALSE, , , , . UVDDB-DDBI File E i V w W d w H l dt e i no i e pPDDBI

Ra y ed . 6.12.

O n L B u t t o n D b l C l k . CDC C B i t m a p .

memoc, CDC, , , . . CBitmap CBitmap: : C r e a t e C o m p a t i b l e B i t m a p , -

6.

201

, , . , . CDC CDC: :CreateCompatibieDC, , . CBitmap. CBitmap . CDC::SelectObject.

, . CRect: :PtinRect. , , CDC: :BitBit . . . . , . , . CBitmap: :GetBitmapBits, CBitmap , . . , , , , . , . , . was_copied TRUE, , . , CWnd: :GetClientRect : . , , .

202

II.

CBitmap: : SetBitmapBits, , . CDC: :BltBit, . , , , , . , . , , , CDDBView , m_Buffer . Microsoft . Visual C++ 6.0 Add Member Variable ( ) . , Visual C++ 7.0 .

- , - , , , .- , . . - . - . , . - D1B, , . : 1. DI , 1. . 2. Class View ( ) DIB. 3. CDDBView Add | Add Variable ( | ). Add Member Variable Wizard ( ).

6.

203

4. Variable Type ( ) BITMAPINFO*, Variable name ( ) m i n f o Finish (). 5. Class View ( ) CDiBView, Go To Definition ( ). DIBView.cpp, CDiBView. 6. CDiBView 6.9. i

! 6.9. CDiBView // CDiBView CDiBView::CDiBView() { // BITMAPINFO m_Info = (BITMAPINFO*) new char[ sizeof(BITMAPINFOHEADER) + (sizeof(RGBQUAD) 8) ]; // m_Info-> bmiHeader.biSize = sizeof(BITMAPINFOHEADER); m_Info-> bmiHeader.biWidth = 4; m_Info-> bmiHeader.biHeight =0; m_Info-> bmiHeader.biPlanes = 1; m_Info-> bmiHeader.biBitCount = 8; m_Info-> bmiHeader.biCompression = BI_RGB; m_Info-> m_Info-> m_Info-> m_Info-> bmiHeader.biSizelmage = bmiHeader.biXPelsPerMeter bmiHeader.biYPelsPerMeter bmiHeader.biClrUsed 0; = 0; = 0; = 0; = 0;

m_Info-> bmiHeader.biClrlmportant // for(int i=0; i < 256; i++) {

m_Info-> bmiColors[i].rgbBlue = (BYTE) i; m_Info-> bmiColors[i].rgbGreen = (BYTE) i; m_Info-> bmiColors[i].rgbRed = (BYTE) i;

204

II. m_Info-> bmiColors[i].rgbReserved = 0;

} CDIBView::-CDIBView() delete m_Info; } 7. OnDraw 6.10. j 6.10. CDIBView: :OnDraw // CDIBView void CDIBView::OnDraw(CDC* pDC) { // // CDIBDoc* pDoc = GetDocument ; ASSERT_VALID(pDoc); int i, k, q; CRect Draw__Rect; // GetClientRect(Draw_Rect); // BITMAPINFO int Rect_Height = Draw_Rect.Height(); int Rect__Width = Draw_Rect .Width (); HDC hDc = pDC-> GetSafeHdc(); m_Info-> bmiHeader.biHeight = Rect_Height; m_Info-> bmiHeader.biSizelmage = Rect_Height 2; m_Info-> bmiHeader.biXPelsPerMeter = (::GetDeviceCaps(hDc, HORZRES)*1000)/::GetDeviceCaps(hDc, HORZSIZE); m_Info-> bmiHeader.biYPelsPerMeter = (::GetDeviceCaps(hDc, VERTRES)*1000)/::GetDeviceCaps(hDc, VERTSIZE); char Frg[8192]; for(i=0; i < Rect Width; I

6. II q = i & 3; for(k=0; k < Rect__Height; k++) Frg[ (k 2) + q] = (char) (i+k) ; if(q == 3) ::SetDIBitsToDevice(hDc, i - 3, 0, 4, Rect_Height, 0, 0, 0, Rect_Height, Frg, m_Info, DIB_RGB_COLORS);

205

// if(q != 3) : :SetDIBitsToDevice (hDc, i q, 0, q+1, Rect__Height, 0, 0, 0, Rect_Height, Frg, m_Info, DIB RGB COLORS);

. , . 6.13. (, .)

File Edit View window Help1

D ?

i f :

DEEEBSB9I

Hfc .^1 I:

4- '

^ ,'* 1''^

"V

1

K- '

I K **

-

-

'

'

Ra y ed. 6 . 1 3 . - ( High Color)

206

II.

9. 256 . . 6.14.

DIB - oralFile Edit View Window Help

Ray ed. 6 . 1 4 . - ( 256 )

10. . , CDiBView BITMAPINFO, - (DIB) . , . bmiHeader, BITMAPINFOHEADER. , . . bmiHeader bmicoiors,

6.

207

RGBQUAD, , . BITMAFIHFO , CDiBView. CDiBView: :OnDraw. CDIBDOC (, , ) :: ..,.ii-nt:t-L , . BITMAPINFOMEADER. - , . , - , . . . I , . setoiBitsToDevice. , .

7

, . , , , . . /, 2. , , .

2, , , c o b j e c t : : S e r i a l i z e , CArchive. . . , , , , MS-DOS. Text , . Text , , , : 1. File | Open Solution ( | ) Open Solution ( ) Text (). Open Solution ( ) , . 7.1. 2. Text () Open ().

7.

209

. 7 . 1 . Open Solution 3. TextView.cpp OnLButtonDown lpDoc-> a Y . A d d ( p o i n t . ) ; // lpDoc-> SetModifiedFlag();

4. TextDoc.cpp Serialize 7.1.] 7.1. CTextDoc: : S e r i a l i z e // CTextDoc void CTextDoc::Serialize(CArchives ar) int i, n; if (ar.IsStoring()){

i

// n = aX.GetSizef) ; ar n; for(i=0; i < n; i)

210ar ar

II.

else // ; .SetSize(); aY.SetSize(n); for(i=0; i < n; i ar aX[i]; ar aY[i];

Text-Text 1 File Edit Ve Window Help iw Q ^ B < .>\ m t IPJleKtl -. . .!._:

[41.49] [18i.es]

[74.134]

Ready . 7.2. Text

7.

211

5. . Text. 6. . , . 7.2. 7. File | Close ( | ) Close () . Text (), . 7.3. 8. Yes (), , Textl. Save As ( ), .7.4.

]

1 1 U.

t

Cancel

!

. 7 . 3 . Text

JJ.SJ_A Te-t

is a mci]Text.cpp ;h]Text.h ^ Text 4 le..L,tc ^Text e|Text.s!jo PjjjText ci] TextDoc.cpp Ji] TextDoch _ci] TextView.cpp _K] TextView.h

_JC'ebug ^Jres c;] " h i l d F r m . c p p It] G n l d F r m . h c:]MamFrm.cpp ^(lamFrm.h M ] PeadMe h]Resource,h ^stdafx.cpp Jjstdafx.h

]Text

-lie name: Save as type:

[ Filesl".")

Cne acl

. 7.4. Save As 9. Save (). .

212

II.

10. File | Open ( | ) Open () . Open (), . 7.5.

et L o in a T x ok |Debug Zjres *j C id r . p hl Fmc p J ) C id r . V hl Fmh iCt] M i Fmc p a r .p n hlMainFrm.h 1] RaM ed e Ji] R s uc . e o r eh jcijstdafx.cpp [h]stdafx.h S]Text File n m : a ev

'

Text OS Text.re :**Text jalText.suQ lS-Text ^]Textl 2 TextDoc.cpp |K]TextDoc.h *f]TextView.cpp

*3 Text.cpp ji] Text.h

ih] T xVe . e t i wh

F oye lF (. e ft : e " lis pA li s. 7.5. Open

-i

O p e n

11. TextAppl Open (). , , . CDocument: :SetModif iedFlag, , , , . , . 7.3 . c o b j e c t : : S e r i a l i z e . CArchive: : IsStoring , . , , , . CArchiue . : , Open () Save As ( ) ; , . : 1. Resource View ( ). 2. Text.rc, String Table ( ) String Table. . 3. iDR_TextTYPE Caption () . , . 7.6.".. Tent - Microsoft Visual C++ {design] -'-{$9!1 File Edit ew Project Build D_ebug Jpols ffiindom 1 . J _J L=i &% i . ,|. ID IDR MAINFRAME AFX IDS TITLE AFXJDSJDLEMES5AGE ID_INDICATOR_EXT ID_INDICATOR_CAPS ID_INDICATOR_NUM IDJNDICATOR SCRL I0JNDICATOR_OVR IDJNDICATOR_REC ,ID FILE NEW | ID_FILE_OPEN :ID FILE CLOSEi ID_FILE!SAVE

@,

SetModifiedFlaglFALSE); // Invalidate(); CView::OnRButtonDown(nFlags, point);

226 8.

II.

TextDoc.cpp #include "Text.h" #include CTextDoc 7.5. I

9.

I 7.5. CTextDoc // CTextDoc CText Doc::CText Doc : lpClipFile(NULL) , lpOutFile(NULL) { struct _finddata_t file; long hFile; CString File_Name = ":\\ . "; // if((hFile = _findfirst(File_Name, sc_file)) != -1L ) f ::MessageBox(0, " ", "", MBJDK I MB_SYSTEMMODAL); exit(1); } _findclose(hFile); // try { lpClipFile = new CFile(File_Name, CFile::modeCreate CFile::modeReadWrite | CFile::shareDenyNone); SetFileAttributes(File_Name, FILE_ATTRIBUTE_HIDDEN); lpOutFile = NULL; |

// catch ( . ) ..

7. ::MessageBox(0, " ", "", _ I MB^SYSTEMMODAL); exit (1) ;

227

CTextDoc::-CTextDoc() { // CString F_Name = lpClipFile-> GetFilePath() // lpClipFile-> Closed; // if(lpOutFile) lpOutFile-> Close(); // delete lpClipFile; delete lpOutFile; // CFile: -.Remove (F_Name) ;

10. Text. CText:: i n i t i n s t a n c e :// Dispatch commands specified on the command l i n e . Will return F L E if AS // app was /Unregister. if return FALSE; launched with /RegServer, /Register, /Unregserver or

(!ProcessShellCommand(cmdlnfo))

11. . 12. File | Open ( | ) Open () . 13. Open () TextApp I .tpf, , Open ().

228

II.

14. , , TextAppl.tpf. 15. . . 16. . Save As ( ). . , Save As ( ) , , . 7.9.

a- 3

^Sx J JJ on-

Sem a v

Wrn w Rsue o q t eor s H i h c Cgi q a N Rsue t jn e eor t w cVjewina Resources in Resource E

Ray ed

LtL, 9..

9.

257

3. IDRMAIN FRAME. , , . , . 9.3. 4. Cut () , . , , . , Cut (). 5. () Paste (). . 6. . , . 9.4.

. 9.4. Tool - , , .

258

II.

, , , . Tool: 1. File | Open Solution ( | ) Open Solution ( ) Tool, Tool Open (). 2. Resource View ( ), Tool.rc. 3. Toolbar Insert Toolbar ( ). , . 9.5. , T o - Microsoft Visual C + design] ol +1 | Fe | E i Vw Eo c B d dbg lools fiction Mndrw Hp i l d e r e t u eu t i j l i e l ~ _J - 1? S _ Debug -* '/ ' t P - [ T | ' : N L ^ i f 1 ! '." 1! ir u' in. ill* 1 l * i T o.cI R T.A l Toolbar)* | o lr (D _ .. R

D

'2, - _j T or o lc . )A c l r t i c e ao e ) Do ag il I o jc n j Mn eu _J Srn T te ti g af j V ro es n i

Jl S

3

* i

| I.

U .-' , ^ - . ? .

-> -

Uae EiNu0Hsm2la3.i. nd '\ _ 0 se2 etn o W l : t c 'Ulae lEN_0ussie3\n0ld'l Uae E I20Ayt3\ou2d ndd ': I2 C y m7er o d : _ n f i' i iUaeENN0y\ycm2di.lu nddi'w02 sss2mii2d od w_ 000 eV3\cd l d:\2 \ e 3 nd W stm 3. ; n iUae W_0nism2md o d I2 < . 3 r n trait0 0Csee \tl2id 0(x) o h d N a tt3: it re ll e 2 sei w: ;TdorEx8]h\.x:Nvi'.o ee0w ce0(x) h pa :[7 Toxdohcs xd 0 o 00 e r m' 2 oee aeh t t d . ;T g 2 l t a i h h e i i .Ready

'

Ml lUrtelp R s ^ c V w Wir^oiiv e oc e i e bv e o r e d Files Affecteds -R s uc Editing __ R s uc File eo r e Wot'kina with R s uc s eo r e Creatinci a Nw Rescujice ^ R s uc Editors eo r e eo r e eo r e J Viewina R s uc s in a R s uc EdiLL j jffl1 Propestiei Dn m H l | ya i e c p

. 9 . 5 .

9.

259

4. Toolbar ( ), IDR_TOOLBARI Properties (). Properties (). 5. ID ( ) Properties () IDR_TOOLBARI IDRTOOLBAR. 6. Rectangle () Image Editor ( ) . 7. Show Color Window ( ). Colors (), . 9.3 9.6. 8. Colors (). 9. Fill () Image Editor ( ), , . . 10. ID ( ) Properties () ID_SQUARE ( Prompt () ). 11. , Prompt () Properties () "Draw red square\nSquare". , . 9.6. 12. Menu () Resource View ( ) IDR_MAINFRAME.

. 13. View (). 14. " ", . . 15. "& Toolbar" . . 16. My Toolbar ( ), , , Toolbar ( ).

260

II.

,. Tool - Microsoft Visual [design] Toolrt (IDR tQOt8Mtl

F E t V t Eo c BJ Dbg T o Wdw Hp i d e r e t ud eu os no e l e i i i l i l , -' ., ^ ' \ ^ A i ^ ." ., , b . i ' Debug " . EDIT1 .!" C>

3

fi>

^

1 , . - 1!

Tool.rc(IDR_T-ARl -Toolbar)' | < *

S L J

- _] + +

Tool.re :_J Accelerator j Dialoq _ ] Icon _J Menu.

_ J -nng Table j Toolbar alii IDR_MA!NFRAME [English Ul IDR^TOOLBAR + I Version

^

^ _J

("Toolbar Editor ICTBEd _ j

jDebug " Unloaded 'E:\WIN_2n00\system32\ole32.dir : Unloaded 'E:\WIN_20nCl\system32teleaut32.dir 1 i Unloaded 'E:\WlN_2O0O\si'Stem32\mfc70enu.dll : Unloaded 'E:iwiN_Z000\system32\indicdll.dir Unloaded t:\WINJ0OO\system32Vmm32.dll1 l Unloaded 'E:\WIN_2000\systein32\comctl32.dir : The thread 0x280 has exited with code 0 (0x0). | The program '[272] Tool.exe: Native' has exited with code 0 (0x0). 6 : 1 Magnification

ID.SQUARE \ Prompt J

. 9 . 6 . Colors

17. ID ( ) Properties () ID VIEW__MYTOOLBAR File | Save All ( | ) Save All ( ) Standard (). , , . 18. Prompt () Properties () "Show or hide the toolbar\nToggle ToolBar". 19. IDRTOOITYPE Resource View ( ). . 20. , .. 1319, . 21. " ", . .

9.

261

22. "&Draw" . . 23. View () Window (). 24. " ", . . 25. "&Square" . . 26. ID ( ) Properties () ID_ SQUARE ( ) File | Save All ( | ) Save All ( ) Standard (). , , . 27. Prompt () Properties () "Draw red square\nSquare". 28. Class View ( ) CToolView.

29. Properties () Events (). , . 30. ID_SQUARE COMMAND. . 31. . 32. .. 30 31 UPDATE_COMMAND_UI . 33. Class View ( ) CMainFrame. 34. .. 29 32 ID_VIEW_MYTOOLBAR. 35. Properties () Messages (). , . 36. WM_CLOSE . 37. Class View ( ) CMainFrame Add | Add variable ( | ). Add Member Variable Wizard ( ). 38. Variable type ( ) CTooiBar, Variable name ( -

262

II. ) _1 Finish (). , CMainFrame.

39. MainFrm.h. 40. CMainFrame void OnUpdateViewMytoolbar(CCmdOI *pCmdUI); BOOL OnMyToolbarCheck(UINT nID) ; 41. MainFrm.cpp ON_UPDATE_COMMAND_UI (ID_VIEW_MYTOOLBAR, OnUpdateViewMytoolbar)

ON_COMMAND_EX(ID_PROCESS_TOOLBAR, OnMyToolbarCheck) 42. Oncreate 9 1 .. ; 9 1 CMainFrame: :OnCreate ..// int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { // if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; // if (!m_wndToolBar.CreateEx(this, TBSTYLE^FLAT, WS_CHILD I WS_VISIBLE I CBRS_TOP I CBRS_GRIPPER | CBRS_TOPLTIPS CBRS_FLYBY I CBRS_SIZE_DYNAMIC) I I !m_wndToolBar. LoadToolBar (IDRJ4AINFRAME) ) { TRACEO("Failed to create toolbar\n"); return -1; //

j

I

// if ( !m_MyToolBar.CreateEx(this, TBSTYLE^FLAT, WS_CHILD | WS__VISIBLE I CBRS TOP | CBRS GRIPPER | CBRS TOOLTIPS I CBRS FLYBY I

9. CBRS_SIZE_DYNAMIC) | | !m_MyToolBar.LoadToolBar(IDRJTOOLBAR)) { TRACEO("Failed to create toolbar\n"); return -1; //

263

// if (!m_wndStatusBar.Create(this) I I !m_wndStatusBar.Setlndicators(indicators, sizeof(indicators)/sizeof(UINT) ) ) { TRACEO("Failed to create status bar\n"); return -1; //

// SetWindowLong(m_MyToolBar.m_hWnd, GWL_ID, ID_VIEW_MYTOOLBAR) // m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); m_MyToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar) ; DockControlBar(sm_MyToolBar) ; // // LoadBarState("Local AppWizard-Generated Applications"); return 0;

43. OnClose 9.2. I 9.2. CMainFrame: :OnClose // CMainFrame // void CMainFrame::OnClose(void)

264

II.

// SaveBarState("Local AppWizard-Generated Applications"); CMDIFrameWnd::OnClose() ;

44.

OnUpdateMyTooibar 9.3. i

| 9.3. CMainFrame: :OnUpdateViewMytoolbar // void CMainFrame::OnUpdateViewMytoolbar(CCmdUI *pCmdUI) if (&m_MyToolBar != NULL) //

// // pCmdUI->SetCheck((m_MyToolBar.GetStyle() & WSJVISIBLE) != 0) , return; //

// pCmdUI->ContinueRouting() ;

45.

9.4.

! 9.4. CMainFrame: :OnMyToolbarCheck // BOOL CMainFrame::OnMyToolbarCheck(UINT nID) if (&m_MyToolBar != NULL) //

ShowControlBar(&m_MyToolBar, (m_MyToolBar.GetStyle() S WS_VISIBLE) == 0, FALSE); return TRUE; } return FALSE;

9.

265

46. Class View ( ) CTooiview Add | Add Variable ( | ). Add Member Variable Wizard ( ). 47. ) booi, ) ish (). ToolAppView.cpp. Variable type ( Variable name ( bDrawn Fin

48. onSquare 9.5. j 9.5. C T o o l V i e w : :OnSquare // void CToolView::OnSquare(void){

j

CClientDC d c ( t h i s ) ; CBrush recffirush(RGB(255,0,0)); CPen pen(PS_SOLID, 0, R G B ( 0 , 0 , 2 5 5 ) ) ; CPen + oldPen - dc.SeiectObject(&pen); CBrush* oldBrush = dc.SeiectObject(SredBrush); dc.Rectangle(20, 20, 120, 120); dc.SeiectObject(oldBrush); dc. SeiectObject. (oldPen) ; bDrawn = true;

49. onUpdateSquare 9.6. j 9.6. CToolView: :OnUpdateSquare // void CToolView::OnUpdateSquare(CCmdUI pCmdUI) f pCmdUI-> Enable(!bDrawn);+

50. onLButtonDown 9.7.

266

II.

! 9.7. CToolView: : OnLButtonDown // CToolView // void CToolView::OnLButtonDown(UINT nFlags,{ bDrawn = false; Invalidate () ; CView::OnLButtonDown(nFlags, point);

CPoint p o i n t )

51. . , . 9.7.

Fl E i V w Da W d w H l ie dt e i rw n o i e p

. 9 . 7 . Tool .

9.

267

52. Square () . , Square () . 53. . , Square () . 54. Draw | Square ( | ). , Square () . 55. Draw () , Square () . 56. . Square () , Draw () , . 9.8.

. 9.8. Tool

268

II.

57. View () My Toolbar ( ). , . 9.9.

. 9.9. Tool 58. View () My Toolbar ( ). . 59. , . 9.10. 60. . . , , . , Visual C++ , .

9.

269

. 9.10.

^

"Jj

Visual C++ 6.0 Visual C++ 7.0 , . ( ). Visual C++ 7.0, Visual C++ 6.0, , . CTooiBar CMainFrame , , CTooiBar . , . , . C M a i n F r a m e : : O n C r e a t e , . .

.

270

II.

, , , , . . CTooiBar: :CreateEx . Windows ( ) CTooiBar. CTooiBar: :LoadTooiBar, Windows, . TRACEO, , Windows , . 1, . . . . , . . setwindowLong, . , , , 00000800. , , , , . , , , . ccontrolBar: :EnableDocking , . . CFrameWnd: : EnableDocking, . ccontrolBar::EnableDocking.

9.

271

DockControiBar, . OnCreate CFrameWnd: : LoadBarState, , . , cwinApp: :SetRegistryKey, CToolAppApp::Initlnstance. CFrameWnd: : LoadBarState -

, CMainFrame Onciose, WM_CLOSE, , . CFrameWnd: :saveBarstate, , . onUpdateMyTooibar UPDATE_COMMAND_UI, . , , , . , ccmdui: :Setcheck, . , . cwnd: :Getstyle, , W S V I S I B L E . , , . , , OnUpdateMyTooibar CCmdUI: : ContinueRouting,

, , . OnMyTooibarCheck , . , , . , OnUpdateMyTooibar, , . , CFrameWnd::ShowControlBar, -

. , . , , .

272

II.

onMyTooibarCheck TRUE, FALSE.

CTooiAppview: :OnSquare , . , , . onsquare . , , , , . bDrawn, FALSE, TRUE.

onUpdateSquare . ccmdui: : Enable bDrawn . , . , , . onLButtonDown, , bDrawn FALSE i n v a l i d a t e , , onDraw .

, MFC Application Wizard, , , . Microsoft , , . , , . , Microsoft , , , Microsoft , Windows.

9.

273

" ", Microsoft, , Visual C++. . MFC , indicators. . , Microsoft. , Tool: 1. File | Open Solution ( | ) Open Solution ( ) Tool, Tool Open ().

I Resource Symbols Nm ae

xj 136 " 32771 134 100 100 128 132 129 In U e s

.g^^^^ ID_SQUARE ID_VIEW_MYTOOLBAR IDD_ABOUTBOX IDP_OLE_INIT_FAILED IDR_MAINFRAME IDR_TOOLBAR IDR_ToolTYPE

Closejjjew... Delete Change... *> Help I ]

~ Show read-only symbols Used by: -not used-

. 9.11. Resource Symbols

274

II.

2. Resource View ( ), Tool, Tool.rc Resource Symbols ( ). Resource Symbols ( ), . 9.11. 3. New (), New Symbol ( ), . 9.12._? Value: jlOl Cancel | 1

. 9.12. New Symbol 4. Name () ID_INDICATOR_X . . 5. ID_INDICATOR_Y Close () Resource Symbols ( ). 6. Tool.rc, String Table ( ). String Table (group) [English (U.S.)]. . 7. . 8. New String ( ). . 9. . , . 10. ID_INDICATOR_X, . 9.13. 11. Caption () "X". 12. .. 711 ID INDICATOR Y "Y".

9.

275

Fe E i Vw Po c B d Cbg T o ijrdnn Hp i d e r e t u eu os l t i j l i l e l L c l A q WadG n r t d A pe o a p a i r - e ede p l z J J ' t 1. , < P t Cbg eu L viavj,- T or ( ti g T b ( r u )* o le Srn a l go p) . e _ J Tool re J D j y - L | crirn + J Accelerator DE TR PC I _ D_ E A E I I 57641 Replace specific text with different text\nReplace - _ J Dialog DE TSLC_L 57642 Select the entire document\nSelect All I _D_ EE TAL I 3 toD_ABOUTBO>! [English (I DE TU D I _D_ N O I 57643 Undo the last action'inUndo DE 1_E O I _DTRD 57644 Redo the previously undone action\nRedo _ J Icon 1 _E _O BR 59392 5how or hide the toolbar\nToggle ToolBar DVWT OA I I - , j Menu DVW 5AU_A 59393 Show or hide the status bar\nToggle StatusBar I _E TTSBR I Sj IDR_MAINFRAME [English AXD _ CZ F_ SS SE I I 61184 Change the window size Sj IDR.ToolTYPE [English (U.: AXD_C OE F IS M V S 61185 Change the window position - _JStrng Table AXD _C N Z 61186 Reduce the window to an icon F_ S5 M ME I II I be String Table (group) [Engli: AXD_C AME 61187 Enlarge the window to full size F_ SS MX Z I II + _ j Toolbar AXD _ C ET r . 61188 Switchtothenext document window F_ SS NXW I I J AXD _C R V N 61189 Switch to the previous document window F_ S5 P EW , I I. + j Version AXI 55 COE F_ _C L S D 61190 Close the active window and prompts to save the documents AXI SS RSOE 61202 Restore the window to normal size F_ _CET R D AXD _CA kS 61203 Activate Task List F_ S3 T SL T I 'I AXD JD HD 61215 Activate this window FJ S4 C L I I AXD _ R VWC 61445 Close print preview mode\nCancel Preview F_ SP EE _ . I I ' I SUR D QAE 32771 Draw red square\nSquare.11 ID INDICATOR_CAPS ID INDICATOR_EXT IDJNDICATOR_KANA ID INDICATORJJUM ID_INDICATOR_OVR IDJMDICATOR R C E 5tem32\mfc70?nu.dll' ID INDICATOR S R CL ystem32\ir>dicdll.dll' ysteni32\imrri32.dir /stem 32>comctl32. d ' H :ed with code 0(0x0), The program '[1228] Tool.eve: Nahve' has exired wii"h code 0 (). ^ p - [string Editor IStrEd

I I D AO DN I T R C I NX P N D ET A E

. 9 . 1 3 .

13. MainFrm.h cstatusBar m_wndstatusBar,- , . p r o t e c t e d public. 14. MainFrm.cpp i n d i c a t o r s :static UN indicators!] = I T{

ID_SEPARATOR, ID_INDICATOR__X, ID INDICATOR Y,

//

15. Class View ( ) CToolview Messages (). , . 16. WM_MOUSEMOVE .