346 106 5MB
Russian Pages 451 Year 2000
Visual C++ 6
• •
1К 1.
•
4.
C++
5. 6.
•
7.
•
8.
•
9.
•
10.
•
-
11.
•
-
C++
-
C++
12.
3.
13.
•
14.
•
15.
4.
Windows 16.
•
Windows
17.
•
Windows
18.
•
•
,
2
•
•
6 Visual C++
.
•
•
Visual C++,
2.
•
•
Visual C++
19.
MFC MFC -
5. 20.
AppWizard
ClassWizard
1
•
•
•
2
21.
OLE
22. 23.
ActiveX ATL
: MicrosoftVisual C++, C/C++ Windows. ,
32, . .
•
, MicrosoftVisual C++. ,
. Microsoft, , MicrosoftVisual C++.
, , ,
•
, .
•
, . C/C++, Windows,
MFC . ,
,
, . .
1—3
MicrosoftVisual C++.
4—12
C/C++. ,
-
. 13—15
-
C++. ,
,
.
16
17
Windows(95, 98
NT),
,
MicrosoftVisualC++ ,
, , 18
,
.
19
MFC . C++ ,
, 20 ,
.
21
MFC . OLE,
OLE-
.
MFC
22, ActiveX.
, 23 ATL
.
3
1. К
•
Visual C++,
6
•
•
• o o o
•
o o
ClassView
o o o o
MFC
o
•
o
General
o
Debug
o
C/C++
o
Link
o
Resources
o
MIDL
o
Browse Info
o
Custom Build
VisualC++
Windows95, 98
NT
. MicrosoftVisualC++
6
:
,
.
VisualC++ ( ,
) ,
Profiler,
, MFC ,
. , .
4
,
,
,
, .
Win32,
Windows95, 98
NT.
:
•
(
•
IntelHSense);
OLEDB;
•
,
•
(
).
К VisualC++ /
• •
• • •
• •
•
Internet ,
(intranet). ,
,
:
Microsoft Transaction Server; ,
;
SQL Editor; SQL Debugger; MFC
;
ADO Data-Bound Dialog Wizard; Remote Automation; Visual SourceSafe. MicrosoftVisualC++
,
Windows AppleMacintosh. , ,
, ™,
,
, .
,
ClassWizard, MFC .
OLE
И MicrosoftVisualC++ . VisualC++.
,
Microsoft VisualC++.
CodeView Debug. , .
5
,
,
,
Windows, . .
,
—
, . (
,
,
,
,
. .).
,
(
).
,
. RC
. 16-19.
. ,
VisualC++.
, ,
.
,
, .
. —
, .
ActiveX Control Test Container ,
Microsoft, .
. APITextViewer , VisualBasic
Win32 API,
.
AVIEditor ,
AVI-
DataObjectViewer DataObjectViewer ActiveX OLE, (drag-and-drop).
,
DDESpy DDE-
.
DocFileViewer OLE-
6
.
.
ErrorLookup . HeapWalkUtility , (
).
HelpWorkshop . OLE Client/Server, Tools View OLEViewer . .
ActiveX OLE Client
OLE,
OLE Server
OLE-
. TheProcessViewer . ROTViewer ActiveX
OLE,
. Spy++ ,
,
. StressUtility ,
. (
GDI,
.
), Stress
, .
,
, .
MFC Tracer AFX.INI. , .
,
Tracer
.
UUIDGenerator (UUID),
.
WinDiff . Zooming .
7
VisualC++ .
.
VisualBasic . VisualC++ ,
,
,
.
, VisualC++.
ClassView ClassView
Java -
,
C++. MFC
,
ALT,
.
VisualC++ .
•
,
: ;
•
;
•
;
•
, ;
•
;
•
;
•
.
DSW( MDP). (
(DSP)
: ).
DSP ,
.(
DSP-
NMAKE.) Export Makefile
,
, Project.
, Word.
,
VisualStudio.
, VisualC++ _
o_npocmpa cm a.DSW. .
,
VisualC++
, , .
8
, ,
,
. . .
VisualC++ .
,
Microsoft
. "
"
;
,
, . ,
,
, ,
.
, ,
. VisualC++
,
, .
-
. ,
/
.
C++, VisualC++ . .
, ,
; ,
.
MFC Windows
,
. API-
, MicrosoftFoundationClasses— MFC . . Windows. ,
.
Microsoft C++, MFC C++, ,
.
MFC
Windows, .
, ,
,
,
,
.
MFC
WindowsAPI. ,
•
•
,
Windows. MFC
. .
MFC WindowsAPI,
,
, (GraphicsDeviceInterface— , . MFC
•
,
,
, GDI
),
,
,
. MFC WindowsAPI. .
Microsoft
,
. ,
MFC ,
,
, WindowsAPI,
•
. MFC
. Windows-
.
MFC
— MFC
9
. switch/case
•
Windows .
,
-
MFC
. , -
•
. MFC
. .
MFC "outofmemory" (
•
MFC
, ), . MFC
. , . , . ,
•
, .
MFC
, MFC WindowsAPI. MFC
,
"
"
WindowsAPI.
.
,
,
MFC
WindowsAPI. ,
,
•
.
,
. MFC DOS. Windows.
,
MS-
MFC , /
. Windows,
MS-DOS.
MicrosoftVisualC++
.
, .
C++ ,
.
,
, switch, while
for. VisualC++
.
, C/C++ ,
Settings, Optimizations
Project
,
Category.
MicrosoftVisualC++ , ,
,
,
. ,
, ,
Project
. Settings.
General MFC (
General MicrosoftFoundationClasses).
, (
Outputfiles)
10
.
Intermediatefiles)
(
Debug ,
Debug .
,
, Category
AdditionalDLLs, (DLL).
C/C++ C/C++ : General, C++ Language, Code Generation, Customize, Listing Files, Optimizations, Precompiled Headers Preprocessor. ProjectOptions . General (
General ,
Warninglevel), (
(
( Preprocessordefinitions).
Debuginfo),
Optimizations)
C++ Language (
C++ Language Pointer-to-member representation), (Enable exception handling), (EnableRun-timeTypeInformation) (Disableconstructiondisplacements).
CodeGeneration CodeGeneration ( ( Callingconvention), timelibrary) Structmemberalignment).
, Processor), (
Userun(
Customize Customize
•
:
Disablelanguageextensions ( ANSI , Microsoft );
•
Enablefunction-levellinking ( , );
•
Eliminateduplicatestrings( );
•
Enableminimalrebuild( C++ );
•
,
Enableincrementalcompilation( );
•
Suppressstartupbannerandinformationmessages( ).
ListingFiles (
ListingFiles Generatebrowseinfo),
,
SBR-
11
, ,
,
.
,
, Listingfilename).
(
Listingfiletype
Optimizations Optimizations ( Optimizations). (
, Inlinefunctionexpansion).
PrecompiledHeaders ,
PrecompiledHeaders (
). .
,
.
Preprocessor . ( Additional Ignore standard include paths, PATH INCLUDE.
Preprocessor #include directories), , Link
: General, Customize, Debug, Input Output.
Link General General ,
. Object/librarymodules .
Outputfilename . ,
•
•
•
•
•
• •
• •
•
•
12
: );
Generatedebuginfo( Linkincrementally( Customize
; Useprogramdatabase);
,
);
Enableprofiling(
,
Ignorealldefaultlibraries( ); Generatemapfile(
-
).
Customize Customize
:
Linkincrementally(
General);
Useprogramdatabase( ); Outputfilename(
);
Printingprogressmessages( ); Suppressstartupbanner( C/C++).
Customize
Debug ,
Debug
-
,
. Input Input ,
.
Output Output (Entry-pointsymbol), Stackallocations),
(
(Baseaddress), , Versioninformation).
(
Resources (
Resources RES)
,
,
. MIDL MIDL . BrowseInfo ,
,
BrowseInfo ,
.
CustomBuild ,
CustomBuild .
13
• • • • •
•
•
•
•
•
14
2. К
Visual C++ Visual C++
File New Open Close Save Save As Save All Page Setup Print Recent Files Recent Workspaces Exit Edit o Undo o Redo o Cut o Copy o Paste o Delete o Select All o Find o Find in Files o Replace o Go To o Bookmarks o Breakpoints o List Members o Type Info o Parameter Info o Complete Word View o ClassWizard o Resource Symbols Resource Includes o Full Screen o Workspace o Output o Debug Windows o Refresh Properties Insert o New Class o Resource o Resource Copy o File As Text o New ATL Object Project o Set Active Project o Add to Project... o Dependencies o Settings o ExportMakefile o Insert Project Into Workspace Build o Compile o Build o Rebuild All o Batch Build o Clean o Start Debug
o o o o o o o o o o
o o o o o
Debugger Remote Connection. Execute Set Active Configuration Configurations Proffle Tools o Source Browser o Close Source Browser File o Error Lookup o ActiveX Control Test Container o OLE/COM Object Viewer o Spy++ o MFC Tracer o Visual Component Manager o Register Control o Customize o Options o Macro / Record / Play Window o New Window o Split o Docking View o Close o Close All o Next o Previous o Cascade o Tile Horizontally o Tile Vertically
•
•
•
o o o o o o o o
Help Contents / Search / Index Use Extension Help Keyboard Map Tip of the Day Technical Support Microsoft on the Web About Visual C++
К
VisualC++
MicrosoftVisualC++
, ,
, ,
,
,
,
C++. . ,
,
3
VisualC++. Visual C++ VisualC++
.
. 2.1
,
VisualC++
.
, .
, [F1].
15
2.1. , .
C/C++
[F1],
.
, ,
.
,
,
a ,
.
, . ,
.
,
,
File
[Alt+F]. ,
"
"
.
, ,
. New...,
File ,
, Slave "
,
[Ctrl+N].
, ,
— .
File
,
, .
",
,
,
. , . Open.
,
,
Open...
File
, . .
VisualC++
.
.
. .
.
, .
16
•
, :
•
;
•
, . -
•
:
;
•
, . :
•
;
•
,
[Ctrl]
.
File VisualC++
File
Windows (
,
. 2.2).
. 2.2. New... New... (
. . VisualC++ ), 1.
,
,
. xxxl,
—
2
. .
17
, (
,
,
,
. .).
xxx1
6,
xxx1,
New...
(
2), , xxx1.
.
Open... New..., , OpenFile
.
,
Open... Windows.
. Open.... Close .
Close ,
, . .
. ,
, ,
.
Save Save
. ,
-
.
, xxxl. ,
,
SaveAs. Save (
).
Save
,
.
SaveAs... SaveAs... , ,
. , . .
SaveAs
,
. ,
. SaveAll Windows95,98 . ,
C/C++ ,
NT, Save . .
, SaveAll SaveAs,
, .
PageSetup... . PageSetup , .
18
,
,
,
,
,
. 2.1. 2.1.
Page Setup
& &d &f &1 & & &t
Print... , Print....
File
Print, .
, .
,
Print
Selection ).
PrintRange (
, , Recent Files
Setup.
Recent Workspaces .
Print... ,
.
VisualC++,
.
Exit VisualC++. .
Exit -
, .
Edit Edit ( ,
. 2.3) ,
. .
19
. 2.3. Undo Undo
. (
).
Redo Undo, ,
Redo. .
Cut Cut
, .
Cut
Paste .
. Copy Cut, ,
. Paste
.
.
Paste Paste (
). .
20
Delete ,
,
Delete. ,
,
Edit
Undo.
Select All SelectAll ,
.
Find... ,
, C/C++
Find..., . ,
Find
, -
,
. . Find...
. Findwhat
. 2.2
, Find.
2.2
Find , : Data*1
*
: Data1, Dataln1, DataOut1 .
: Data. : Data1l
Data2,
Dataln1
: Ado
^
:
,
"do" ,
+
: +value : i_value, fvalue, lng_value
$
: end;$
[]
, : Data[A...Z] : DataA, : Data[1248] : Data2,
:
,
"end;"
Datal Data3
: 100\$
\
: "100$" (
100$,
"100"
) , \{\}
,
: \{no\}*_answer : answer, no_answer, nono_answer, nonono_answer
Find in Files... Find in Files... .
Find... :"
,
, .
?" ,
C/C++,
,
,
-
. ,
Find in Files...,
,
21
. FindinFiles... .
-
, ,
,
,
FindinFiles...
. Internet,
, ,
,
,
.
Replace... ,
Replace... . ,
. ,
, ,
Find....
,
ReplaceAll, . ,
, Undo.
GoTo... GoTo... .
, ,
.
, .
, Bookmarks... ,
Bookmarks... .
, . ,
,
.
(
),
.
, ,
,
.
,
,
. .
,
.
Breakpoints... . ListMembers -
ListMembers . TypeInfo , . ParameterInfo ( .
)
,
,
, ,
.
CompleteWord CompleteWord , , .
. ,
View View(
. 2.4) .
22
,
. 2.4 ClassWizard... ClassWizard
, ,
MFC .
ClassWizard ,
•
ClassWizard
:
, ClassView WizardBar, MFC , ATL . ClassView ClassView( :
MFC ;
•
;
•
-
,
,
,
•
•
, CLW).
;
•
•
MFC ,
; ;
,
Resource Symbols...
,
;
. Resource Includes... , , , .
ResourceIncludes... ,
•
•
•
•
ResourceSymbols... .
: , ; ; ; ;
23
•
, .
FullScreen , .
FullScreen, .
Workspace Workspace
Workspace(
),
,
.
,
,
,
. Output Output
Output,
,
. , .
Debug Windows Debug Windows Watch, Call Stack, Memory, Variables, Registers
, Disassembly.
Refresh Explorer (
Refresh [F5]
, )
Windows. Properties , ,
,
, ,
.
Insert Insert( ,
. 2.5)
,
,
. .
2.5. NewClass... NewClass, MFC ATL
( )
. .
24
Resource... , ,
,
, ,
,
, HTML-
,
,
.
ResourceCopy... VisualC++
. Language ,
InsertResourceCopy.
Condition
.
Workspace
. File As Text... . . New ATL Object... ATL-
,
C++, IUnknown, IClassFactory, IClassFactory2 , ActiveX
. ATL,
IDispatch, (lEnumXXXX), .
Project Project(
. 2.6)
.
2.6. SetActiveProject , . AddtoProject , .
.
Dependencies , Dependencies. Settings... Settings...
, ,
.
25
ExportMakefile... .
, ExportMakefile...,
,
,
VisualC++.
Insert Project Into Workspace... . ,
, .
, .
, (
).
,
.
Build Build(
. 2.7) ,
, .
2.7. Compile . Biuld ,
C/C++,
. , ,
Build, ,
, . ,
Build, ( ( Build
.
Debug)
Release). Set Active Configuration.... , —
, .
Output. RebuildAll Build RebuildAll
, .
26
,
RebuildAll ,
, Output. BatchBuild...
Build, . Clean Clean .
Build.
StartDebug , :
.
Debugger Remote Connection... , . Execute ,
Execute,
. Set Active Configuration... ,
,
, Build
,
RebuildAll .
.
SetActiveConfiguration..., Configurations...
.
Configurations... , ), ).
Debug( Release(
Profile... VisualC++.
, , Link
General
(
Enable profiling
Project Settings). .
Output
,
, ,
.
Tools Tools(
. 2.8)
, VisualC++.
27
. 2.8. SourceBrowser... .
SBR(OBJ)
,
.
BSC-
SBR-
, SBRGenerate browse info Project Settings. , Exclude local .
, Listing Files
C/C++
,
variables from browse info. Close Source Browser File SBR-
.
ErrorLookup ErrorLookup .
, ErrorMessage
Value, .
ActiveX Control Test Container ActiveX. ,
, .
OLE/COM Object Viewer ActiveX OLE, . .
,
Spy++ Spy++
, . ,
,
.
MFC Tracer ,
MFC ,
MFC Tracer. ,
MFC , ,
-
.
VisualComponentManager .
28
RegisterControl OLE,
OLE-
,
, OLE. ,
RegisterControl. Customize... Customize, , . Options... Options, VisualC++. Macro... / Record... / Play... ,
VBScript. VBScript
.
VisualC++.
, , .
Window Window(
. 2.9),
DockingView, Windows.
2.9. NewWindow . Split Split
.
29
DockingView . Close . ,
.
CloseAll . ,
.
Next Next,
Window,
. Previous Next, . Cascade , . TileHorizontally . . TileVertically .
il Vertically
.
.
,
.
Help Help( . 2.10) Search Index,
30
Windows .
Contents,
2.10 Contents / Search... / Index . UseExtensionHelp , ,
MSDN.
KeyboardMap... VisualC++ . Tip of the Day... ,
TipoftheDay... VisualC++. TechnicalSupport , . Microsoft on the Web WebVisualC++
Internet,
.
About Visual C++ About... —
Windows ,
, .
•
• •
•
31
o o
•
o o o
Find
Replace
o o
•
o
•
o o
QuickWatch
, .
VisualC++ ,
, .
, ,
,
,
, , .
, Internet,
Windows, ,
.
: .
, , C/C++, ,
VisualC++.
,
,
, . New
32
, File Projects( . 3.1).
.
,— New...,
3.1. .
,
. . — Win32 ConsoleApplication.
Location .
, , Platforms
VisualC++ ,
.
32Win32. (
. 3.2).
33
. 3.2.
,
Win32 Console Application , Finish.
An empty project ,
. ,
:
/* : , */ /* */ /* */ #include /* */ #define SIZE 5 /* */ void print_them(int offset, char continue, -int iarray[SIZE]); void main( void ) { intoffset; /* */ int iarray[SIZE]; /* */ charcontinue= 0; /* */ /* */ print_them(offset,continue, iarray); /* */ Printf(\n\nWelcome to a trace demonstration!"); printf("\nWould you like to continue (Y/N)"); scanf("%c",continue); /* */ if (continue== 'Y' ) for (offset=0; offset < SIZE, offset++) { printf ("\nPlease enter an integer: "); scanf("%d",siarray [of f set] ) ; /* , */ print_them{offset, continue, iarray) ; /* , */ void print_them(int offset, char continue, int iarray[SIZE])
34
{ printf("\n\n%d",offset); printf("\n\n%d",continue); for(offset=0; offset < SIZE, offset++) printf("\n%d",iarray[offset]); } ,
.
.
, .
,
,
,
. , ,
,
, . , ,
Save,
File
[Ctrl+S].
Save, ERROR.
Save.
.
. 3.3
. .
3.3.
,
,
Windows 3.x, Windows95/98
. .
Windows, NT ,
, C/C++.
, FileView
. ERRORfiles.
35
,
AddFilestoProject..., . 3.4. InsertFilesintoProject, ,
. (
:
)
,
#include. ERROR.C ,
.
3.4.
,
. 3.5.
Add files to Project ...
ERROR.C
. VisualC++, . 3.6
.
Build
RebuildAll. Build
,
RebuildAll,
,
36
, , . .
RebuildAll ,
.
,
,
, RebuildAll.
. 3.6.
RebuildAll
, RebuildAll
Build
. 3.7.
Output(
Build . 3.7).
VisualC++ .
Windows
,
.
,
,
,
.
. ,
error
warning
,
.
37
error
,
warning ,
. .
, .
,
int( .
,
) ,
, ,
. .
, double(
. ,
). float(
),
,
, double.
,
float
, , ,
. double .
,
. 3.7,
.
, .
, .
,
—
,
continue, Find
C/C++. Replace ,
-
. , Replace...
,
, Edit, ,
. Find ,
38
. 3.8,
continue. , [Enter]. continue,
, . 3.8
. .
. 3.8. . , Replace...
continue . . 3.9).
Edit(
. 3.9. ,
,
continue
, Replacewith continu. "\nWould you like to continue (Y/N)". , ReplaceAll, . ,
, . .
,
, , FindNext.
, ,
. 3.10.
39
. 3.10 , .
, :
warning. C4013: 'Printf undefined;.., [Enter]. , (
,
. 3.11). ,
C/C++
. . .
Printf(). .
40
.
printf() , —
,
. 3.11.
,
, . 3.12
Project .
RebuildAll.
.
41
.3.12. ,
,
(Printf()),
. .
C/C++
,
printf () , . .
: printf(". . ,
42
. 3.13.
. 3.13. :
syntax error: missing ';'before ')' C/C++,
Pascal, ,
.
,
for
. RebuildAll. ? ,
, RebuildAll
ERROR.EXE.
43
, ,
.
,
,
.
.
, Would you like to continue(Y/N) :
Project
Execute. [Y],
[Enter],
-858993460 0 -858993460 -858993460 -858993460 -858993460 -858993460 Welcome to a trace demonstration! Would you like to continue (Y/N) . 3.14
,
.
. 3.14.
, Y (yes—
,
)
.
, .
. 3.14 , . . .
, ,
, .
,
VisualC++
, .
-
,
,
.
-
, . StepInto
StepOver
, )
StepOver(
Debug. StepInto ( ).
,
,
. StepInto
StepOver
,
.
StepInto, .
StepOver ,
.
, , .
44
.
. 3.15,
(
),
,
.
print_them().
. 3.15. StepOver
,
StepInto .
StepOver. printf().
, [F10], scanf().
Would you like to continue(Y/N)
Y
[Enter] (
. 3.16). (
. 3.17). scanf().
,
,
,
.
45
. 3.16.
"Y"
[Enter],
. 3.17.
scanf().
scanf()
.
:
scanf("%C", continu); , (&) ,
, continu. :
.
,
scanf("%C", &continu); RebuildAll.
,
,
, . , ,
. Breakpoint (
)
Build. . Breakpoint
,
,
,
.
Go . . scanf()
46
.
, ,
,
20-
,
scanf().
Breakpoints(
— Breakpoints... , ,
. 3.18), .
Edit. 20.
. 3.18.
, scanf{).
, Go—
,
[F5].
,
,
,
. .
,
,
scanf() .
,
StepOver, [Enter]. (
Y StepOver , scanf(). SCANF.C)
!
. ?
StepIn ,
, continu.
QuickWatch QuickWatch...
QuickWatch(
. 3.19), . ,
, [Shift+F9].
continu.
47
. 3.19. ,
QuickWatch ,
continu ,
. 3.20.
48
, Debug
Go(
. 3.20).
4.
•
C++ o o o o
•
—
!
ANSI
•
C++
•
-
C++
o
-
o
C++
o
•
C++ C/C++
o o
C++
o o
C++
o
C++ C++
.
,
,
,
, ,
"
" C++
. MicrosoftVisualC++.
, .
UNIX, , UNIX
. ,
UNIX. , . . UNIX , -
1969 . BellLaboratories,
DEC PDP-7 .
, , PDP-7
"
", .
UNIX
(KenThompson)
. ,
. Algol 60
: 1960 .
49
CPL
Combined Programming Language —
.
BCPL
BasicCombinedProgrammingLanguage —
1963 . .
(MartinRichards) 1967 . , BellLabs (DennisRitchie), BellLabs
1970 . 1972 . , 1983 ., Standards Institute — ANSI)
(American National , ANSI
.
Algol 60
FORTRAN. , . ,
,
,
. .
, Algol 60
,
. CPL
" . ,
CPL
" Algol 60
, Algol 60,
.
BCPL, .
CPL, UNIX,
CPL.
,
,
, BCPL,
,
. ,
.
. , UNIX PDP-11 ,
, ,
,
.
PDP-7,
24 ,
PDP-11. .
,
512
16
.
.
UNIX
,
.
:
,
PDP-11
.
. ,
,
,
1971 .
, , —
BCPL
,
,
PL. ,
APL),
( , Pascal, Lisp ,
(Ada, PL/I
.
,
Algol 60).
,
,
, ,
. ,
:
,
.
, .
,
, . , . .
,
,
, . . 4.1,
50
,
, .
,
, (Jacquard'sloom) (1805 .) (CharlesBabbage) (1834 .)-, . , , , (
)
(
).
-
. 4.1. , , . . ,
,
,
,
. . ,
FORTRAN,
. , .
,
FORTRAN
. .
Algol -
,
,
. ,
,
-
. , -
.
BCPL
.
: . -
,
"
"
-
. ,
. .
, .
,
APL ,
.
, Pascal ?
,
, ,
. ,
,
. . ,
. .
51
, . 256
.
,
,
.
, . ANSI
,
,
Microsoft
27 . 50.
, ,
, .
,
/
,
(
)
. , ,
. , . —
,
.
,
. ,
,
, .
Pascal,
, .
, . ,
—
ASCII.
32, "
,
" , for, if/else, switch/case, while .
,
.
, . ,
,
.
, .
,
, . ,
. , , .
, . , ,
. ,
.
52
,
. UNIX, .
,
, , .
. , .
, student_records, .
student_record__ptr student_record__ptr + 1
. ,
.
Э . ,
.
. ,
,
.
.
, .
,
,
,
. .
.
,
. , .
,
,
,
, ,
. . . !
,
, ,
. , .
, .
, .
, . . , .
, .
(=) ,
53
,
. , ,
, .
,
, .
, ,
.
, . —
! — /
,
.
,
UNIX
, . ,
, ,
. ,
,
,
, .
ANSI (ANSI) .
, . , . .
"(
-
.
"
PrenticeHall, 1978 .). , . ANSI
, .
,
,
. ANSI
,
, .
,
,
, -
.
-
,
,
•
.
ANSI ".
,
•
,
•
.
.
ANSI (
) , ,
54
"
.
,
, ISO (InternationalStandardOrganization — ). , . . 4.1. ANSI.
,
4.1.
ANSI :
,
/*—
,*/—
31
, — It:
;
; , ,
/
#,
,
(
), ;
(
if
) #elif (
)
, #define ANSI read () write ()
,
;
,
, ,
, , ,
size of()
sizeof ()
size_t
,
,
,
void
,
,
void
;
,
void:
, ; , , \ , (0-9, a-f, A-F); \ !0 (
,
16 0x10)
, ,
;
??
> ! 0) { centimeters = feet * 12 * 2.54; meters = centimeters/100; cout foperand2 =%d", (foperand1 > foperand2)); printf("\n foperand1 < foperand2 =%d", (foperand1 < foperand2)); printf("\n foperand1 => foperand2 =%d", (foperand1 >= foperand2)); printf("\n foperand1 > foperand1 >> foperand2; cout >> . imax_score) imax_score = iscores[irow]; if(iscores[irow] < imin_score) imin_score = iscores[irow]; } cout>>>>>>>> = 0; t--) printf("%d",iyourarray[t]); }
: "); scanf("%d",Sivalue) ; vbinary
.
,
,
—2— .
, .
2, , 0
vbinary() (%)
.
1. while.
(0
1)
, ,
(
iyourarray[]. idata. idata)
, .
: char . clowercase() CTYPE.H,
/* * *
clowercase() ,
char . tolower(), .
charf.c ' .
*/ #include
123
#include char clowercase(char c) ; int main () { char clowchar, chichar; printf(" chichar = getchar(); clowchar = clowercase(chichar); printf("%c\n",clowchar); return(0); char clowercase(char c) { return(tolower(c)); }
. \n");
: bool , is_upper() bool,
is_lower(),
, .
C++.
// // boolf.cpp // C++ // bool. // #include bool is_upper(void) ; bool is_lower(void) ; int main () { char cTestChar = 'T'; bool bIsUppercase, bIsLowercase; bIsUppercase = is__upper (cTestChar) ; bIsLowercase = is_lower(cTestChar); cout UpdateWindow() ; return TRUE; } CTheApp TheApp; . AFXWIN.H AFXWIN.H ,
MFC . WINDOWS. H.
AFXWIN.H .
, . ,
CWinApp CTheApp,
CWinApp:
class CTheApp : public CWinApp { public: virtual BOOL Initlnstance () ; }; Initlnstance()
CWinApp.
, .
CWinApp
Exitlnstance(),Run() . CWinApp,
/////////////// // CWinAppclass CWinApp : public CWinThread { DECLARE_DYNAMIC (CWinApp) public: // CWinApp(LPCTSTR IpszAppName =• NULL);// // // // ( ) HINSTANCE m_hlnstance; HINSTANCE m_hPrev!nstance; LPTSTR m_lpCmdLine; int m_nCmdShow; // ( LPCTSTR m_pszAppName; // LPCTSTR m_pszRegistryKey; // CDocManager* m_pDocManager; public: // LPCTSTRm_pszExeName; // LPCTSTRm_pszHelpFilePath; //
,
AFXWIN.H.
Windows
Initlnstance)
(
)
321
LPCTSTRm_pszProfileName;
//
// Initlnstanceprotected: void LoadStdProfileSettings(UINT nMaxMRU = _AFX_MRU_COUNT); void EnableShellOpen (); void SetDialogBkColor(COLORREF clrCtlBk = RGB(192,192,192), COLORREFclrCtlText= RGB(0, 0, 0)); // void SetRegistryKey(LPCTSTR IpszRegistryKey); void SetRegistryKey(UINT nIDRegistryKey); // // ( BOOLEnable3dControls(); // 3// CTL3D32.DLLtifndef _AFXDLL BOOLEnableSdControlsStatic(); //
,
INI)
// CTL3D.LIB fendif void RegisterShellFileTypes(BOOL bCompat=FALSE); // , // . void RegisterShellFileTypesCompat(); // void UnregisterShellFileTypes(); // Initlnstance public: // HCURSOR LoadCursor(LPCTSTR IpszResourceName) const; HCURSOR LoadCursor(UINT nIDResource) const; HCDRSOR LoadStandardCursor(LPCTSTR IpszCursorName) const; HCURSOR LoadOEMCursor(UINT nIDCursor) const; // HICON Loadlcon(LPCTSTR IpszResourceName) const; HICON Loadlcon(UINT nIDResource) const; HICON LoadStandardlcon(LPCTSTR IpszIconName) const; HICON LoadOEMIcon(UINT nIDIcon) const; // virtual BOOL Initlnstance(); virtualintExitlnstanceO; // virtual int Run(); virtual BOOL OnIdle(LONG ICount); virtual LRESULT ProcessWndProcException(CException* e,const MSG* pMsg); public: virtual CWinApp(); protected: // { {AFX_MSG (CWinApp) afx_msg void OnAppExitO; afx_msg void OnUpdateRecentFileMenu (CCmdUI* pCmdUI) ; af x_msg BOOL OnOpenRecentFile (UINT nID) ; //}}afx_msg declare_message_map ( ) }; CWinApp 5.
, .
322
CFrameWnd , CFrameWnd:
CMainWnd,
class CMainWnd : public CFrameWnd { public: CMainWnd () ( Create (NULL, "Hello MFC World", WS_OVERLAPPEDWINDOW, rectDefault, NULL, NULL); } }; CMainWnd . ,
7
Create(), .
. CFrameWnd,
AFXWIN.H.
//////////// // CFrameWndclass CFrameWnd : public CWnd { DECLARE_DYNCREATE(CFrameWnd) // public: static AFX_DATA const CRect rectDefault; CFrameWnd(); BOOL LoadAccelTable(LPCTSTR IpszResourceName); BOOL Create(LPCTSTR IpszClassName, LPCTSTR IpszWindowName, DWORD dwStyle = WS_OVERLAPPEDWINDOW, const RECT& rect = rectDefault, CWnd* pParentWnd = NULL, // != NULL LPCTSTR IpszMenuName = NULL, DWORD dwExStyle =0, CCreateContext* pContext = NULL); // virtualBOOLLoadFrame(HINTnIDResource, DWORD dwDefaultStyle = WS_OVERLAPPEDWINDOW I FWS_ADDTOTITLE, CWnd* pParentWnd = NULL, CCreateContext* pContext = NULL); // CWnd*. CreateView(CCreateContext* pContext, UINT nID = AFX IDW PANE FIRST); // void EnableDocking(DWORD dwDockStyle); void DockControlBar(CControlBar* pBar, UINT nDockBarlD = 0, LPCRECT IpRect = NULL); void FloatcontrolBar(CControlBar* pBar, CPoint point, DWORD dwStyle = CBRS_ALIGN_TOP); CControlBar* GetControlBar(UINT nID); // public: virtual -CFrameWnd (); intm_nWindow; // — ":n"
323
HMENUm_hMenuDefault; // HACCELm_hAccelTable; // DWORD m_dwPromptContext; BOOLm_bHelpMode;// TRUE, // [Shift+Fl] CFrameWnd* m_pNextFrameWnd; // CRect m_rectBorder; COleFrameHook* m_pNotifyHook; CPtrList m_listControlBars; // , // intm_nShowDelay; // afx_msg int OnCreate(LPCREATESTRUCT IpCreateStruct); afx_msg void.OnDestroy(); afx_msg void OnClose(); afx_msg void OnlnitMenu(CMenu*); afx_msg void OnlnitMenuPopup(CMenu*, UINT, BOOL); afx_msg void OnMenuSelect(OINT nltemlD, UINT nFlags, HMENU hSysMenu); afx_msg LRESULT OnPopMessageString(WPARAM wParam, LPARAM IParam) ; afx_msg LRESULT OnSetMessageString(WPARAM wParam, LPARAM IParam), protected: afx_msg LRESULT OnDDEInitiate(WPARAM wParam, LPARAM IParam); afx_msg LRESULT OnDDEExecute(WPARAM wParam, LPARAM IParam); afx_msg LRESULT OnDDETerminate(WPARAM wParam, LPARAM IParam); afx_msg LRESULT OnRegisteredMouseWheel(WPARAM wParam, LPARAM IParam); DECLARE_MESSAGE_MAP () friend class CWinApp; ); Create() API-
RegisterClass().
null. InitInstance( ) CTheApp
initlnstance()
CWinApp: BOOL CTheApp::Initlnstance() { m_pMainWnd=new CMainWndO; m_j>MainWnd->ShowWindow (m_nCmdShow) ; m_pMainWnd->UpdateWindow(); returnTRUE; } new -
m_pMainWnd(
CMainWnd (), _ . ShowWindow()
m_nCmdShow
. -
) .
CWinApp .
Updatewindow()
.
CWinApp:
CTheAppTheApp;
. (
324
. 18.1).
,
. 18.1.
MFC — C++. MFC -
MFC . ,
.
, .
325
19.
•
MFC MFC -
o
MFC SWP.H
o
MFC SWP.CPP
o
•
o
GDI.CPP
o
•
o
FOURIER.H
o o
FOURIER.CPP
o
•
o
BARCHART.H
o o
BARCHART.CPP
o ,
16 ,
17,
Windows,
,
. MFC
Windows.
,
MFC , 32-
. ,
,
, ,
MFC . ,
,
. , MFC -
.
MFC MFC -
,
. Windows,
. ,
MFC SWP (MFC . ,
SimpleWindowsProgram), ,
.
:
.
, .
, MFC .
Microsoft.
326
MFC SWP.H:
class CMainWnd : public CFrameWnd { public: CMainWndO; afx_rasg void OnPaint ; DECLARE MESSAGE MAP() ; }; class CmfcswpApp : public CWinApp { public: BOOL Initlnstance(); } ; MFC SWP.CPP:
// // mfcswp.cpp // // MFC . // #include #include "mfcswp.h" CmfcswpApp theApp; CMainWnd::CMainWnd() { Create(NULL, "A MFC Windows Application", WS_OVERLAPPEDWINDOW, rectDefault, NULL, NULL); } void CMainWnd: :OnPaint () { CPaintDC dc(this); dc.TextOut(200, 200, "Using the MFC Library", 21); } BEGIN_MESSAGE_MAP(CMainWnd, CFrameWnd) ON_WM_PAINT() END_MESSAGE_MAP () BOOL CmfcswpApp::Initlnstance() { m_pMainWnd = new CMainWndO; m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow() ; return TRUE; MFC SWP.H MFC -
.
,
, MFC .
. , .
R, , CWinApp,
"resource" ( .
). : CMainWnd,
CmfcswpApp,
CFrameWnd.
class CMainWnd : public CFrameWnd public: CMainWnd () ; afx_msg void OnPaint(); DECLARE_MESSAGE_MAP () ; ); class CmfcswpApp : public CWinApp public: BOOL Initlnstance(); }
327
CMainWnd
OnPaint() ,
afx_msg.
, OnPaint(), OnPaint()
. virtual
.
,
CMainWnd
WM_PAINT.
declare_message_map , Microsoft , .
MFC . ,
MFC SWP.CPP 17 SIMPLE.CPP, , .
. ,
OnPaint().
void CMainWnd::OnPaint() { CPaintDC do(this); dc.TextOut(200,200, "Using the MFC Library", 21); } , .
GDI-
OnPaint() CPaintDC.
, :
BEGIN_MESSAGE_MAP(CMainWnd,CFrameWnd) ON_WM_PAINT;() END_MESSAGE_MAP() . . ... begin_message_map , . on_wm_paint() wm_paint end_message_map
: CMainWnd CFrameWnd. , OnPaint{).
. , switch/case.
VisualC++, MFC , .
328
, . 19.1.
. 19.1. , Rectangle (), Ellipse ()
TextOut()
,
, LineTo(). .
. , :
17. GDI.H
GDI.CPP. .
,
, ,
class CMainWnd : public CFrameWnd { public: CMainWnd (); afx_msg void OnPaintO; DECLARE_MESSAGE_MAP() ; ); class CgdiAApp : public CWinApp { public: BOOLInitlnstance(); } :
// // gdi.cpp // mfcswp.cpp, // // #include #include "gdi.h" CgdiAApp theApp; CMainWnd::CMainWnd() { Create(NULL, "Experimenting With GDI Primitives", WSJDVERLAPPEDWINDOW, rectDefault, NULL, NULL); >> void CMainWnd::OnPaint() { static DWORD dwColor[9] = {RGB(0, 0, 0), // RGB(255,0, 0), // RGB (0,255., 0), //
.
329
RGB(0,0, 255), // RGB(255,255, 0), // RGB(255,0, 255), // RGB(0,255,255), // RGB(127,127, 127), // RGB(255,255, 255)};// short xcoord; POINT polylpts[4],polygpts[5] ; CBrush newbrush; CBrush* oldbrush; CPen newpen; CPen*oldpen; CPaintDC dc(this); // newpen.CreatePen(PS_SOLID, 6, dwColor[0]); oldpen = dc.Selectobject(Snewpen); dc.MoveTo(0, 0) ; dc.LineTo(640,430); dc.TextOut(70,20,"", 11); // dc.SelectObjecb(oldpen); newpen.DeleteObject(); // newpen.CreatePen(PS_SOLID, 8, dwColor[2]); oldpen = dc.Selectobject(Snewpen); dc.Chord(550, 20,630,80, 555, 25,625,70); dc.TextOut(485,30,"chord->", 7) ; // dc.Selectobject(oldpen); newpen.DeleteObject() ; // newpen.CreatePen(PS_SOLID, 1, dwColor[1]); oldpen = dc.Selectobject(Snewpen); newbrush.CreateSolidBrush(dwColor[1]); oldbrush = dc.Selectobject(Snewbrush) ; dc.Ellipse(180, 180, 285, 260); dc.TextOut(210,215, "ellipse",7); // dc.SelectObject(oldbrush) ; newbrush.DeleteObject(); // dc.SelectObject(oldpen) ; newpen.DeleteObj ect{); // newpen.CreatePen(PS_SOLID, I, dwColor[3]); oldpen = dc.SelectObject(Snewpen); newbrush.CreatesolidBrush(dwColor[3]) ; oldbrush = dc.SelectObject(Snewbrush); dc.Ellipse(380,180, 570, 370); dc.TextOut(450,265,"circle",6);
330
// dc.SelectObject(oldbrush) ; newbrush.DeleteObject(); // dc.SelectObject(oldpen); newpen.DeleteObject() ; // newpen.CreatePen(PS_SOLID, I, dwColor[0]); oldpen = dc.SelectObject(Snewpen); newbrush.CreatesolidBrush(dwColor[2]); oldbrush = dc.SelectObject(Snewbrush); dc.Pie(300,50,400, 150, 300, 50,300, 100); dc.TextOut(350,80,"ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow() ; return TRUE; } BARCHART.H , ,
CMainWnd: afx_msg void afx_msg void afx_msg int afxjnsg void afx_msg void
348
,
OnPaint(); OnSize(UINT, int, int); OnCreate(LPCREATESTROCT cs); OnAbout(); OnBarData();
.
afx_msg void OnExit(); CBarDataDialog .
CFourierDataDialog
, .
, BARCHARTR.H BARCHRT.RC, BARCHART.RES.
Microsoft
BARCHARTR.H idm_input IDM_EXIT. . . ,
: idm_about, , dm_title, DM_XLABLE dm_ylable, , DM_P1 _ 10, .
BARCHART.RC
. . ,
,
About
.
BARCHART.CPP ,
, . . .
. BarChartData
,
. .
maxnumbar :
#definemaxnumbar
10 ,
,
:
char szTString[80] = "(barchart title area)"; char szXString[80] = "x-axis label"; char szXString[80] - "y-axis label"; int iBarSize[maxnumbar] = (20,10,40,50}; :
int i^i_cxClient, m_cyClient; . dwColor ,
,
. ,
. CFont CDC (
CBrush ). .
,
:
CFont newfont; CFont* oldfont; CBrush newbrush; CBrush* oldbrush;
349
, .
iBarSize. :
iNBars = 0; for(i=0;i < maxnumbar; i++) { if (IBarSizefi] != 0) iNBars++; } , n
().
, .
:
IBarWidth = 400/iNBars; . ,
:
// IBarMax = iBarSize[0]; for(i= 0; i< iNBars; i++) if(iBarMax < iBarSize [i])iBarMax = iBarSize [i]; . __itoa( ) :
// strptr = _itoa (iBarMax, sbuffer, 10); ilenMaxLabel= strlen (sbuffer) ; :
// . // — 270. for(i=0;i < iNBars; i++) iBarSizeScaled[i] = iBarSize[i] *
(270/iBarMax);
, ,
, :
// // dc.SetMapMode(MM_ISOTROPIC) ; dc.SetWindowExt(640,400); dc.SetViewportExt(m_cxClient, m_cyClient); dc.SetViewportOrg(0, 0) ; .
,
.
-
,
CreateFont () CreateFontlndirect () . CreateFont().
, . TimesNewRoman
350
, 12
, TimesNewRoman 14 , 0,376
. Arial . . . 72
12
,
— .
, . (
, ,
,
,
' ').
, ,
(
, ,
. .).
, . .
CreateFont( ) CreateFontO
WINDOWS.H.
GDI-
,
,
. CreateFontO
CreateFont( , _ _ _
. :
,
,
,
, ,
,
, ,
_ ,
,
_
, ,
) CreateFont()
19.1.
. 19.1.
CreateFont()
(int) (int) ( , 900 (90°) —
(int)
)
;0— , 2700
, 1800 (180°) —
(270°) — ( (int) (
(int) (DWORD) (DWORD)
0 1000); , 700 (fw_bold) —
;0— , 1800 — 400 (fw_normal)
, ,
(DWORD) (DWORD) _
) 90° 90°
, 900 — , 2700 —
, ; oem_charset — hebrew_charset— ;
(DWORD) _
: ANSI_CHARSET— , russian_charset—
-
, ,
. .
: out_default_precis — , out_tt_precis— (TrueType), out_device_precis— , : clip_default_precis— , clip_stroke_precis—
(DWORD) _ )
ANSI-
; , clip_character_precis— (
. . ; , draft_quality—
: default_quality— , , PROOF_QUALITY— ,
(DWORD) , — default_pitch — , fixed_pitch— (DWORD) _ _
, : ff_dontcare— ,
; , fixed_pitch— ( ). ; , ff_roman— , FF_SWISS— ,
, ff_modern— FF SCRIPT—
:
,
351
ff_decorative— ,
(LPCTSTR)
CreateFont() . ,
12
Windows
.
, .
, CreateFont()
:
newfont.CreateFont(12,12,900,900,FW_BOLD, FALSE, FALSE, FALSE, OEM_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAOLT_PRECIS, DEFAULT_QDALITY, VARIABLE_PITCH | FF_ROMAN, "Roman"); ,
. ,
90
900.
. :
oldfont = dc.SelectObject(Snewfont); dc.TextOut(50, 200+(strlen(szXString)*10/2), szYString, strlen(szYString));
MoveTo()
LineTo():
// dc.MoveTo(99,49); dc.LineTo(99,350); dc.LineTo(500,350); dc.MoveTo(99,350); . , x1
100,350, y1. .
// xl= 100; yl = 350; 2 = xl + iBarWidth; iBarSizeScaled. Rectangle()
,
,
.
dwColor, .
// for(i= 0; i < iNBars; i++) { newbrush.CreateSolidBrush(dwColor[ i ]) ; oldbrush = dc.SelectObject(Snewbrush); y2 = 350 - iBarSizeScaledfi]; dc.Rectangle(xl,yl,x2,y2); xl = x2; x2 +- iBarWidth; // dc.SelectObject(oldbrush);
352
newbrush.DeleteObject() ; } ,
x1
2
, , for
. ,
.
, 19.11).
,
, ,
. 19.11.
(
.
. 19.12. .
,
353
. 19.12.
354
,
20.
•
AppWizard
ClassWizard
Graph
o o o o
•
o , Windows95, 98
32-
NT
,
,
MFC . ,
, , ,
-
—
.
,
. .
/
,
,
,
, , — Cut, Copy, Paste , ),
. . MDI-
. (MultipleDocumentInterface— ,
OLE.
.
Microsoft AppWizard. .
, MFC File
,
-
New, AppWizard.
MFC , . .
"
"
AppWizard
, ClassWizard. .
ClassWizard
, AppWizard.
View.
ClassWizard
. .
, .
:
, ,
,
,
. Graph AppWizard
ClassWizard.
. .
, ,
Graph.
355
MicrosoftVisualC++ File ( . 20.1), MFC AppWizard ,(exe). .
New. , Graph,
. 20.1. ,
,— , (
356
. 20.2).
,
.20.2. SDI-
1:
Single Document ,
,
, ,
. Document/View architecture support?. . Next.
, , ,
. 20.3,
357
. 20.3.
2:
None , . Next,
358
None. (
. 20.4).
. 20.4.
3: OLE-
,
( ActiveX.
OLE
None (
Next,
. 20.5.
) . 20.5).
4: , ( ).
,
Next,
, (
. 20.6).
359
. 20.6.
5:
, MFC , (
360
. 20.6, . 20.7).
Next,
. 20.7.
6: AppWizard , , CGraphApp, CMainFrame, CGraphDoc CGraphView,
CScrollView, CTreeView CWnd,
CGraphView.
, Baseclass (CEditView, CFormView, CHtmlView, CListView, CRichEditView, CView), . CView, .
.
,
, .
CFormView
, .
CEditView . AppWizard(
. 20.8.
,
Finish . 20.8).
,
AppWizard .
,
.
,
, .
ClassWizard . , wm_paint, WM_MOUSEMOVE View
. . ClassWizard....
,
361
OnPaint(), .
, CGraphView(
ObjectIDs,
. 20.9.
,
wm_paint, Classname
. 20.9).
CGraphView ,
Messages wm_paint,
. Memberfunctions
OnPaint() ( . 20.10). GRAPHVIEW.CPP. —
362
.
. 20.10
OnPaint()
, RebuildAll(
Build
. 20.11.
Build
. . 20.11).
Rebuild All
Output(
. 20.12).
363
. 20.12. , GRAPHDOC.CPP GRAPHVIEW.CPP, 30 ,
— GRAPH.CPP, MAINFRM.CPP, . ,
.
. DEBUG.
,
. .
,
,
,
.
.
, .
,
364
.
. 20.13. A AppWizard GraphView.cpp,
: Graph.cpp MainFrm.cpp GraphDoc.cpp . .
, Graph.cpp :
////////////////////////////////////////// // CGraphApp CGraphApp theApp; ////////////////////////////////////////// // CGraphApp CGraphApp::Initlnstance() // . // // , // . // , // . tRegistryKey(_T("LocalAppWizard-GeneratedApplications")); adStdProfileSettings(); // INI, // // SingleDocTemplate* pDocTemplate; 'OcTemplate = new CSingleDocTemplate ( ////////////////////////////////// // CGraphApp BEGIN_MESSAGE_MAP(CGraphApp, CWinApp) //{{AFX_MSG_MAP(CGraphApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) // : // .
365
// , . //}}AFX_MSG_MAP // ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) END_MESSAGE_MAP() //{{AFX_DATA_INIT(CAboutDlg) //}}AFX DATA INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) f CDialog::DoDataExchange(pDX); //({AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP i BEGIN_MESSAGE_MAP (CAboutDlg, CDialog) // { (AFX_MSG_MAP (CAboutDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP ( ) // , About void CGraphApp : : OnAppAbout ( ) { CAboutDlg aboutDlg; aboutDlg . DoModal ( ) ; } ////////////////////////////////// // CGraphApp ,
, CGraphApp. id_app_about, id_file_new ID_FILE_OPEN OnAppAbout() , CWinApp: :OnFileNew() CWinApp: :OnFileOpen(). CGraphApp, initinstance() OnAppAbout(). CAboutDlg,
About CDialog.
,
DoDataExchange ().
MAINFRM.CPP MAINFRM.CPP CFrameWnd
SDI-
CMainFrame, .
// MainFrm.cpp: CMainFrame// #include "stdafx.h" #include "Graph.h" #include "MainFrm.h" #ifdef _DEBUG #def ine new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[]= _ FILE #endif ////////////////////////////////// 1 1 CMainFrame IMPLEMENT_DYNCREATE (CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP (CMainFrame, CFrameWnd) // { (AFX_MSG_MAP (CMainFrame) // : // . // , . //}}AFX_MSG_MAP END_MESSAGE_MAP ( )
366
////////////////////////////////// 1 1 CMainFrame CMainFrame:: CMainFrame() { // TODO: , } CMainFrame::-CMainFrame() { } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT Ses) { if(ICFrameWnd::PreCreateWindow(cs)) returnFALSE; // TODO: , // cs. return TRUE; } ////////////////////////////////// // CMainFrame #ifdef _DEBUG void CMainFrame: :AssertValid()const { CFrameWnd: :AssertValid() ; void CMainFrame: : Dump (CDumpContext &dc) const { CFrameWnd: : Dump (dc); } #endif //_DEBUG ////////////////////////////////// // CMainFrame , , PreCreateWindow()
, ,
AssertValid(), Dump() .
GRAPHDOC.CPP GRAPHDOC.CPP ,
CGraphDoc, .
// GraphDoc.cpp: CGraphDoc// #include "stdafx.h" #include "Graph. h" #include "GraphDoc. h" tifdef _DEBOG #define new DEBUGJSIEW #undef THIS_FILE static char THIS_FILE [ ] = _ FILE _ ; #endif ////////////////////////////////// // CGraphDoc IMPLEMENT_DYNCREATE (CGraphDoc, CDocument) BEGIN_MESSAGE_MAP (CGraphDoc, CDocument) //( (AFX_MSGJXIAP (CGraphDoc) // : // . // , . //}}AFX_MSG_MAP END_MESSAGE_MAP ( ) ////////////////////////////////// II CGraphDoc CGraphDoc:: CGraphDoc() {
367
// TODO: } CGraphDoc::-CGraphDoc () { } BOOL CGraphDoc::OnNewDocument() if (ICDocument::OnNewDocument{)) return FALSE; : // TODO: // ( SDI). return TRUE; ) ////////////////////////////////// // CGraphDoc void CGraphDoc: : Serialize (CArchive Sar) { if (ar . IsStoring () ) { // TODO: } else{ // TODO: } } ////////////////////////////////// // CGraphDoc fifdef _DEBUG void CGraphDoc::AssertValid() const { CDocument::AssertValid(); } void CGraphDoc: : Dump (CDumpContext Sdc) const f CDocument :: Dump (dc); ) #endif //_DEBUG ////////////////////////////////// // CGraphDoc ,
,
,
. .
Serialized
. /
. GRAPHVBEW.CPP GRAPHVIEW.CPP CView
CGraphview, .
// GraphView.cpp: CGraphView// #include "stdafx.h" #include "Graph. h" #include "GraphDoc.h" #include "GraphView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS__FILE static char THIS_FILE[] = _ FILE _ ; #endif ////////////////////////////////// // CGraphview IMPLEMENT_DYNCREATE (CGraphview, CView) BEGIN_MESSAGE_MAP (CGraphview, CView) // ( {AFX_MSG_MAP (CGraphview) ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP ( )
368
////////////////////////////////// // CGraphview CGraphview: : CGraphview() { // TODO: } CGraphView::~CGraphView() { } BOOL CGraphView::PreCreateWindow(CREATESTRUCT Ses) { // TODO: , // cs. return CView::PreCreateWindow(cs); } ////////////////////////////////// // void CGraphview::OnDraw(CDC* pDC) { CGraphDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: } ////////////////////////////////// // CGraphView #ifdef _DEBUG void CGraphView::AssertValid() const { CView::AssertValid(); } void CGraphview: : Dump (CDumpContext Sdc) const { CView: : Dump (dc); } CGraphDoc* CGraphview: : GetDocument () // ( ASSERT (m_pDocument->IsKindOf (RUNTIME_CLASS (CGraphDoc) ) ) ; return (CGraphDoc*)m_pDocument; } #endif //_DEBUG ////////////////////////////////// // CGraphview void CGraphview: :OnPaint () { CPaintDCdc(this);// // TODO: // CView: :OnPaint () , , on_wm_paint.
,
. OnDraw( ) AssertValid()
WM_PAINT.
pDoc
,
.
Dump()
.
Graph , CGraphview OnPaint() .
// voidCGraphView::OnPaint() { static DWORD dwColor[9]={ RGB(0,0, 0), // RGB(255,0, 0), //
Wizard ClassWizard . GDI.CPP,
CGraphView
369
RGB(0,255,0), // RGB(0,0, 255), // RGB(255, 255, 0), // RGB(255,0, 255), // RGB(0,255, 255), // RGB (127,12V,127), // RGB (255,255, 255)};//. int xcoord; POINT polylpts[4], polygpts[5]; CBrush newbrush; CBrush* oldbrush; CPen newpen; CPen* oldpen; CPaintDCdc(this);// // newpen.CreatePen(PS_SOLID, 1, dwColor[1]); oldpen = dc.SelectObject(Sriewpen); newbrush.CreateSolidBrush(dwColor[1]) ; oldbrush = dc.SelectObject(Snewbrush); dc.Ellipse(275,300, 200, 250); dc.TextOut(220,265,"ellipse",7); dc.SelectObject(oldbrush) ; newbrush.DeleteObject() ; dc.SelectObject(oldpen) ; newpen.DeleteObject(); // newpen.CreatePen(PS_SOLID, 1, dwColor[3]); oldpen = dc.SelectObject(snewpen) ; newbrush.CreateSolidBrush(dwColor[3]) ; oldbrush = dc.SelectObject(Snewbrush); dc.Ellipse(375,75, 525, 225); dc.TextOut(435,190,"circle",6) ; dc.SelectObject(oldbrush) ; newbrush.DeleteObject(); dc.SelectObject(oldpen); newpen. DeleteObj ect (); // for(xcoord = 400; xcoord < 450; xcoord += 5) dc.SetPixel(xcoord, 350, OL); dc.TextOut(460,345, "> RUNTIME_CLASS (CCntView) ) ; pDocTemplate->SetContainer!nfo(IDR_CNTR_INPLACE) ; AddDocTemplate (pDocTemplate) ; // , // DDE. CCommandLinelnfo cmdlnfo; ParseCommandLine (cmdlnf ) ; // , if ( ! ProcessShellCommand (cmdlnfo) ) return FALSE; // m _pMainWnd->ShowWindow (SW_SHOW) ; m_pMainWnd->UpdateWindow() ; return TRUE;
397
} //////////////////////////////////////////////////////////////// // CAboutDlg, About class CAboutDlg : public CDialog { public: CAboutDlg ( ) ; // //{{AFX_DATA (CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // , ClassWizard //{{AFX_VIRTUAL (CAboutDlg) protected: virtual void DoDataExchange (CDataExchange* pDX) ; //})AFX_VIRTUAL // protected: // { { AFX_MSG (CAboutDlg) // //})AFXMSG DECLARE_MESSAGE_MAP() }; CAboutDlg: : CAboutDlg () : CDialog (CAboutDlg: : IDD) { //{fAFX_DATA_INIT (CAboutDlg) //}}AFX DATA INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) / / } } AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // //}}AFX_MSG_MAPEND_MESSAGE_MAP() // , About void CCntApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } //////////////////////////////////////////////////////////////// // CCntApp ,
. (in-placeediting). ,
, OLE. Excel, Excel
,
Cnt Cnt. MFC
OLE.
, : idr_mainfraime idr_cntr_inplace ( ).
IDR_MAINFRAIME. ,
idr_cntr_in-PLACE.
MAINFRM.CPP -
,
MAINFRM.CPP, Editor .
.
398
, .
OLE , ,
// MainFrm.cpp: CMainFrame // #include "stdafx.h" #include "Cnt.h" #include "MainFrm.h" tifdef _DEBUG #define new DEBUG_NEW tundef THIS_FILE Static char THIS_FILE[] = _FILE_; #endif //////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE (CMainFrame, CFrameWnd) i BEGIN_MESSAGE_MAP (CMainFrame, CFrameWnd) //{{AFX_MSG_MAP (CMainFrame) // : // . // , . //}}AFX_MSG_MAPEND_MESSAGE_MAP ( ) static UINT indicators!] = { ID_SEPARATOR, // ID_INDICATOR_^CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; //////////////////////////////////////////////////////////////// II CMainFrame CMainFrame::CMainFrame() { // TODO: . } CMainFrame::-CMainFrame() f int CMainFrame: :OnCreate (LPCREATESTRUCT IpCreateStruct) { if (CFrameWnd: :OnCreate (IpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE I CBRS_TOP | CBRS_GRIPPER I CBRSJTOOLTIPS I CBRS_FLYBY | CBRS_SIZE_DYNAMIC) | !m_wndToolBar.LoadToolBar(IDR_MAINFRAME) ) { TRACEO ("Failed to create toolbar\n") ; return-1; // } if (!m_wndStatusBar.Create(this)|| !m_wndStatusBar.Setlndicators(indicators, sizeof(indicators)/sizeof(UINT))) ( TRACEO("Failedto create status bar\n"); return -1; // } // TODO: , , // . m_wndToolBar . EnableDocking (CBRS_ALIGN_ANY) ; EnableDocking(CBRS_ALIGN_ANY) ; DockControlBar (Sm_wndToolBar) ; return 0; } BOOL CMainFrame: : PreCreateWindow (CREATESTRUCT Ses) { if(ICFrameWnd: : PreCreateWindow (cs)) return FALSE; // TODO: , cs.
399
return TRUE; } //////////////////////////////////////////////////////////////// // CMainFrame #ifdef _DEBUG void CMainFrame: :AssertValid () const { CFrameWnd: :AssertValid() ; } void CMainFrame::Dump(CDumpContext Sdc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG //////////////////////////////////////////////////////////////// // CMainFrame CNTDOC.CPP CNTDOC.CPP .
,
// CntDoc.cpp: CCntDoc// #include "stdafx.h" #include "Cnt.h" # include "CntDoc.h" #include "Cntrltem.h" tifdef _DEBUG #define new DEBUG_NEW lundef THIS_FILE static char THIS_FILE[] = _ FILE _ ; #endif //////////////////////////////////////////////////////////////// // CCntDoc IMPLEMENT_DYNCREATE (CCntDoc, COleDocument) BEGIN_MESSAGE_MAP (CCntDoc, COleDocument) //{{AFX_MSG_MAP (CCntDoc) // : // . // , . //}}AFX_MSG_MAP // OLEON_UPDATE_COMMAHD_UI ( ID_EDIT_PASTE, COleDocument: :OnUpdatePasteMenu) ON_OPDATE_COMMAMD_OI ( ID_EDIT_PASTE_LINK , COleDocument: :OnUpdatePasteLinkMenu) ON_UPDATE_COMMMJD_UI ( ID_OLE_EDIT_CONVERT , COleDocument: :OnUpdateObjectVerbMenu) ON_COMMAND (ID_OLE_EDIT_CONVERT, COleDocument: :OnEditConvert) ON_OPDATE_COMMAHD_OI (ID_OLE_EDIT_LINKS , COleDocument: :OnUpdateEditLinksMenu) ON_COMMAND (ID_OLE_EDIT_LINKS , COleDocument: :OnEditLinks) ON_0PDATE_COMMAND_UI_RftNGE ( ID_OLE_VERB_FIRST , ID_OLE_VERB_IAST, COleDocument: :OnUpdateObjectVerbMenu) END_MESSAGE_MAP () //////////////////////////////////////////////////////////////// // CCntDoc ' CCntDoc: : CCntDoc( ) {
400
* // EnablecompoundFile ( ) ; // TODO: . } CCntDoc::-CCntDoc() { } BOOLCCntDoc: : OnNewDocument( ) { if ( ! COleDocument : : OnNewDocument ( ) ) return FALSE; // TODO: // ( SDI) return TRUE; } //////////////////////////////////////////////////////////////// // CCntDoc void CCntDoc::Serialize(CArchive sar) { if (ar. IsStoringO ) { // TODO: . } else. // TODO: . } // COleDocument // COleClientltem, // . COleDocument : : Serialize (ar ) ; } //////////////////////////////////////////////////////////////// // CCntDoc tifdef _DEBUG void CCntDoc::AssertValid() const { COleDocument::AssertValid(); } void CCntDoc: : Dump (CDumpContext .&dc) const { COleDocument: :Dump(dc) ; } #endif //_DEBUG //////////////////////////////////////////////////////////////// // CCntDoc .
, . EnableCompoundFile() , ,
. .
CNTVIEW.CPP CNTVIEW.CPP Graph.
// CntView.cpp : // #include "stdafx.h" #include "Cnt.h"
CCntView
401
#include "CntDoc.h" #include "Cntrltem.h" #include "CntView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = _FILE_; #endif //////////////////////////////////////////////////////////////// // CCntView IMPLEMENT_DYNCREATE(CCntView, CView) BEGIN_MESSAGE_MAP(CCntView, CView) //{{AFX_MSG_MAP(CCntView) // : // . // , . ON_WM_DESTROY() ON_WM_SETFOCUS() ON_WM_SIZE() ON_COMMAND (ID_OLE_INSERT_NEW, OnlnsertObject) ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr) //}}AFX_MSG_MAP // ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP () //////////////////////////////////////////////////////////////// // CCntView CCntView::CCntView() { m_pSelection = NULL; // TODO: . } CCntView::-CCntView() } BOOL CCntView::PreCreateWindow(CREATESTRUCT Ses) { // TODO: , // . return CView::PreCreateWindow(cs); } //////////////////////////////////////////////////////////////// // void CCntView::OnDraw(CDC* pDC) { CCn.tDoc* pDoc = GetDocument () ; ASSERT_VALID(pDoc); // TODO: . // TODO: OLE, // . // . // , // . // , // CCntCntrltem, // . // TODO: , // . if (m_pSelection == NULL) { POSITION pos = pDoc-X3etStartPosition() ;
402
m_pSelection = (CCntCntrItem*) pDoc-XSetNextClientltern(pos); > if (m_pSelection != NULL) m_pSelection->Draw(pDC, CRect(10, 10,210,210)); } void CCntView::OnInitialUpdate() { CView::OnInitialUpdate(); // TODO: , // . m_pSelection = NULL; // , // } //////////////////////////////////////////////////////////////// // BOOL CCntView: :OnPreparePrinting (CPrintlnf * plnfo) { // return DoPreparePrinting (plnfo) ; } void CCntView::OnBeginPrinting (CDC* /*pDC*/, CPrintlnfo* /*plnfo*/) { // TODO: . } void CCntView::OnEndPrinting(CDC* /*pDC*/, CPrintlnfo* /*plnfo*/) "" { // TODO: . } void CCntView::OnDestroy() { // ; , // . CView::OnDestroy(); COleClientltem* pActiveltem = GetDocument()-> GetlnPlaceActiveltem(this); if (pActiveltem != NULL && pActive!tem-> GetActiveView() == this) { pActive!tem->Deactivate0; ASSERT(GetDocument()-> GetlnPlaceActiveltem(this) == NULL); } } //////////////////////////////////////////////////////////////// // OLEBOOL CCntView::IsSelected(const CObject* pDocItem) const { // , // CCntCntrltem. // . // TODO: , . return pDocItem == m_pSelection; } void CCntView::0nlnsert0bject() ( // InsertObject // CCntCntrltem. COlelnsertDialog dig; if (dlg.DoModaK) != IDOK) return; BeginWaitCursor() ; CCntCntrltem* pltem = NULL; TRY {
403
// , . CCntDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pltem = new CCntCntrltem(pDoc); ASSERT_VALID(pltem); // , // . if (!dig.Createltem(pltem)) AfxThrowMemoryException(); // ASSERT_VALID(pltem); // , // , , if (dlg.GetSelectionType() == COlelnsertDialog::createNew!tem) p!tem->DoVerb(OLEIVERB_SHOW, this); ASSERT_VALID(pltem); // . // TODO: , . m_pSelection = pltem; // // pDoc->UpdateAHViews (NULL) ; CATCH(CException, e) if (pltem != NULL) ASSERT_VALID(pltem) ; p!tem->Delete() ; AfxMessageBox(IDP_FAILED_TO_CREATE); END_CATCH EndWaitCursor(); > // // . // , , voidCCntView::OnCancelEditCntr() // . COleClientltem* pActiveltem= GetDocument()-> GetlnPlaceActiveltem(this); if (pActiveltem != NULL) pActive!tem->Close(); ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL); } // OnSetFocus OnSize // . void CCntView: :OnSetFocus (CWnd* pOldWnd) { COleClientltem* pActiveltem = GetDocument ( ) -> GetlnPlaceActiveltem(this) ; if (pActiveltem != NULL && pActive!tem->GetItemState () == COleClientltem: :activeUIState) { // , // . CWnd* pWnd = pActiveltem- >GetInPlaceWindow( ); if (pWnd != NULL) { pWnd->SetFocus( ) ; // SetFocus return; }} CView::OnSetFocus(pOldWnd); } void CCntView: :OnSize (UINT nType, int ex, int cy)
404
{ • ' CView: :OnSize (nType, ex, cy) ; COleClientltem* pActiveltem = GetDocument ()-> GetlnPlaceActiveltem(this) ; if (pActiveltem != NULL) pActiveItem->SetItemRects () ; } ///////////////////////////////////////////////// // CCntView tifdef _DEBUG void CCntView::AssertValid() const { CView::AssertValid(); } void CCntView::Dump(CDumpContext Sdc) const CView::Dump(dc); } CCntDoc* CCntView::GetDocument() // ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCntDoc))); return (CCntDoc*)m_pDocument; #endlf //_DEBUG //////////////////////////////////////////////// // CCntView , :
OnDraw( ).
if (m_pSelection !=NULL) m_pSeleotion->Draw(pDC, CRectdO, }
10,210,
210)); ,
CRect( ) .
.
OnlnitialUpdate() , IsSelectedO, OnlnsertObject() , OnCancelEditCntr() , OnSetFocusO OnSize(). , OnlnsertObject() COlelnsertDialog,
.
CNTRITEM.CPP CNTRITEM.CPP, CCntCntrltem.
,
// Cntrltem.cpp: CCntCntrltem // #include "stdafx.h" #include "Cnt.h" #include "CntDoc.h" #include "CntView.h" #include "Cntrltem.h" #ifdef _DEBUG #define new DEBUG_NEW tundef THIS_FILE static char THIS_FILE[] = _ FILE _ ; #endif ////////////////////////////////////////////////// // CCntCntrltem IMPLEMENT_SERIAL (CCntCntrltem, COleClientltem, 0) CCntCntrltem: : CCntCntrltem (CCntDoc* pContainer) : COleClientltem (pContainer) { // TODO: . CCntCntrltera::~CCntCntrItem () {
405
// TODO: . } void CCntCntrltem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam) ASSERT_VALID(this); COleClientltem::OnChange(nCode, dwParam); // OnChange, // . // TODO: // UpdateAllViews. GetDocument()->UpdateAllViews(NULL); BOOL CCntCntrltem::OnChangeItemPosition(const CRect SrectPos) ASSERT_VALID(this); // // . // , , // , COleClientltem::SetItemRects // . if (!COleClientltem::OnChangeItemPosition(rectPos)) return FALSE; // TODO: , // . return TRUE; ) void CCntCntrltem::OnGetItemPosition(CRect SrPosition) ASSERT_VALID(this); // // , . // . // TODO: ( ) // rPosition. rPosition.SetRect(10, 10,210, 210); } void CCntCntrltem: :OnActivate() { // . CCntView* pView = GetActiveView ( ) ; ASSERT_VALID(pView) ; COleClientltem* pltem = GetDocument ( ) -> GetlnPlaceActiveltem(pView) ; if (pltem !- NULL ss-pltem != this) p!tem->Close () ; COleClientltem: : OnAct ivate ( ) ; } void CCntCntrltem: :OnDeactivateUI (BOOL bUndoable) { COleClientltem: :OnDeactivateUI (bUndoable) ; // , . DWORDdwMisc = 0; m_lpObject->GetMiscStatus (GetDrawAspect () , SdwMisc) ; if (dwMisc & OLEMISC_INSIDEOUT) DoVerb (OLEIVERB_HIDE, NULL) ; } void CCntCntrltem: : Serialize (CArchive Sar) { ASSERT_VALID(this) ; // , // COleClientltem. // m_j>Document, // CCntCntrltem: :GetDocument, // . COleClientltem: : Serialize (ar);
406
// , if (ar.IsStoringO ) { // TODO: . } else{ // TODO: . } } /////////////////////////////////////////////// // CCntCntrltem #if