You are on page 1of 427

. .

Borland C++

32.973.26 018.2
17
17 . .
Borland C++ . .: . 432 .: . ().
ISBN 5940740944


Borland C++ C++ Builder
++. ,
.
: , , 
, Internet.

: , ,
, , 
. 
, 
.
, 
. .

32.973.26'018.2

.

.
, , . ,
, '
. '
, .
, , . '

.

ISBN 5940740944

. .


.................................................................................. 7

I
Borland, Borland ............................................................... 15
1
...................................................... 16
1.1. ................................................................... 16
1.2. ......................................................... 20

2
........................................................................... 25
2.1. ................................................
2.2. ........................................................
2.3. ..............................................................................
2.4. ....................................................................

26
29
33
34

3
............................... 36
3.1. ................................................................... 36
3.2. ............................................................................. 39

4

....................................................... 41
5
..................................................... 44
6
.................................................................. 51
6.1. ............................................................... 51
6.2. ..................................................................... 54

7
........................................................... 58

Borland C++ 5

8
...................................................... 70
9
............................................................................... 78
10
....................................................................... 84
11
....................................................... 87
11.1. trial ............................................................................ 87
11.2. .............................................................. 95

12
.......................................................................... 101
12.1. ...................... 103
12.2. ................................................... 106

13
................................................................ 118
14
...................................................... 127
14.1. .................... 127
14.2. ............................................................. 128
14.3. ............................................... 132

15
.................................................................... 135
15.1. ........................................................................................ 135
15.2. ................................................................................ 138

16
.................................................................................................. 144
17
.................................................. 156
18
........................................................................ 169
18.1. / ................................................ 169
18.2. ................................................. 170
18.3. ............................................ 175

19
............................................................. 178

19.1. .......................................................................... 178


19.2. .............................................................. 181
19.3. ................................................................... 183

20
........................................................................ 188
21
........................................................................ 192
22
.......................................................................... 196
22.1. ...................................................................... 197
22.2. ....................................................................................... 200

23
................................................................................................. 205
24
..................................................................... 210

II
Borland C++ Builder 5 ........................................................................ 213
25
C++ Builder ......................................................... 214
25.1. ! ....................................................................................
25.2. ......................................................
25.3. .....................................................................
25.4. VCL OWL, Borland ++ .............

214
218
221
222

26
................................................................... 224
26.1. ..................................................................
26.2. ! ..........................................................
26.3. .............................................................
26.4. MessageBox ..................................................................

224
225
229
232

27
C++ Builder ........................................................ 234
27.1. ................................................................ 235
27.2. ............................................................................... 238

Borland C++ 5

27.3. .............................................................................. 240


27.4. ......................................................................... 244

28
............................................................. 249
28.1. ................................................................................
28.2. ....................................................................
28.3. ...............................................................
28.4. ...........................................................................

249
253
259
265

29
....................................................................... 284
29.1. .....................................................................
29.2. ............................................................................
29.3. .................................................................
29.4. trialD .................................................

284
289
296
307

30
........................................................... 322
30.1. .................................................................
30.2. ...............................................................................
30.3. ................................
30.4. .................................................................
30.5. .......................................................................

322
332
338
350
363

31
....................................................................................... 373
31.1. .................................................................
31.2. ........................................
31.3. ................................
31.4. Borland C++ ...........................................................

374
380
388
395

32
..................................................................... 399
32.1. ......................................... 399
32.2. ..................................... 409
32.3. .................................................. 416

33
............................................. 421
........................................................................................ 424
.................................................................... 425

++
,

.
++


++, .
, , (
++) . 
++ .
,
, . 
,
. 
, 
 .
. , ,
, , 
,
.
. , 
++. , , , 
,
,
,
.
, ,
.

, , 
, ++. 
; 
; ,
++. 
. , ,
.

Borland C++ 5

. ,
.  , , ,
, .
++?

. , .

. , . 
, , 
, .
, 
, Borland C++ 5
C++ Builder 5. , ,
, . ,
, Borland C++ ( C++Builder)
.
++  . 
++ 

.
, , 
++.
, 
. , ,
. Borland ++
(++ Builder) , .
Borland ++, ++ Builder,
 
++, 
Borland ++, ++ Builder.
, 
 .
,
( ). 
++ ( , ),
, .
, ,  . ,
.
Borland ++ 5 . .
(Brian W. Kernighan, Dennis M. Ritchie, The C Programming Language). 
Borland ++.
, Borland ++ ++
Builder , ,
. ,
( Borland ++) ( ++ Builder) 
.

, , . 
cborland@mail.ru.
, .
.
. ( 
, ) 
.
( ,
) .
, 2000

Borland, Borland Builder Microsoft


Bor
land,
Microsoft  
API.

. Microsoft, Borland 

(RAD Rapid Application Development) , 
, , Windows.
( ,
, ).
. 
, 
, Internet.
, , 
,
. Borland Microsoft
, . 
Windows 
, .

. ,
.
, , 
++, 
Pascal, Basic, Fortran. , 

.
.


10

Borland C++ 5


?
, ,
. 
Borland, ++. 
,
.
. 

Windows, 
.
, 
, . 
: ,
. 
. , , ,
. , , 
Borland ++ ( 5.02).
,
,
. , ++  .
(, ) ,
.
Linux, , ,
*.

, , ++
.
, , , 
++.
() . 
, 
++, 
Borland Microsoft. , ,
Borland,  Microsoft. ,
, . , 
Borland.
++ 
. , ++ (

* ,
BASIC, , Windows
UNIX, Linux, C. . . .

11

), Borland.
Visual C++ Microsoft,
Microsoft, , .
, Borland.
++. 
Borland C++. ++ Builder, Borland C++ Builder,
Inprise C++ Builder. , Borland Builder .
 
.
, Borland C++
, , . 
, , .
, Borland C++ .
, 
. Borland C++ 486 16
; C++ Builder Pentium90 32 *.
PentiumIII Borland C++ .
,
.  
, , ,
.. , 
.
C++ Builder , 
C++ Builder. 
, , . C++ Builder 5 2000 ,
, Borland C++ 5.
,
. Borland C++ , 
, C++ Builder ,
, . Internet C++ Builder 
.
Borland C++
, , 
. C++ Builder
, C++, ,
.
Internet. 
BC MVC?. , 
, .
*  , , 
: , 
. . . .


12

Borland C++ 5




!

, 
Borland C++ C++ Builder.
.
,
, .
, , 
( ). , 
C++.
 Internet, 
. , 
From () . ,
, .

, . .
, Borland C++. 
, . ,
, , . ++ Delphi.
C++ Builder 4 Internet.
: , , ,
. , , 
. , , 
, .
,  , . 
. , 15. Borland 5.01. , ,
. , .
, . , ,
?

! , , , 
, , .

http://www.rusdoc.ru/ Borland C++.
, .

13

 , ... C, 

!
Vadim S

Borland C++ 5.
, ,
++
. ,
, . Borland C++ 5
, .
Eugeny Mazunin
. , 
. .
hdesk
 , Borland C++5 
.
Wizard
. , 
, .
Titan
!
(, ). ,
++ .
Borland C++ 5.02 . , ()
. , 95%
.
Internet .
!
++

Borland C++ 5 . .
...
.
, !
German
, , ,
Borland C++.
Makhov Denis


14

Borland C++ 5


, 
:
, , ,
;
(, , ..), 
;
, , 
, , .

1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

Borland,
Borland


,
,

.

,
, 
. , 
, , 
, Borland C++.
, 
. ,
,
. Borland C++
.
, ,  .

1.1.
Borland C++. ,
. File () New ()
AppExpert ( ) . . 1.1.
, 
.
, .

1.1.

17

. 1.1

, , 
2000 (. 1.2).
Open (). 
. Dialog Client (
) Document/View (/)
. . 1.3.

. 1.2

Application (),
. Basic Options ( 
) , (. 1.4).
Admin Options ( ) 
(. 1.5). 
.
Main Window ( ) 
, . 1.6. ,
.
Generate (),
. ,
(. 1.7).


18

. 1.3

. 1.4

1.1.

. 1.5

. 1.6

19


20

. 1.7

Yes (), Borland . 


, 2000
(. 1.8).
2000.exe, ,
. ,
.

. 1.8

, Run (
). // (
) (. . 1.9). 
.
, ,
, . 
.

1.2.
.
, .

1.2.

21

, . 1.3.
Window Model ( )
( Dialog Client). 
, .
. 
, ,
, ().

. 1.9

( . 1.3 )
SDI (Single Document Interface)
. ,
, . 1.10.

. 1.10 SDI

, 
. , 
WordPad,  ,
, .


22

, , . 
, Windows
(. . 1.11).

. 1.11 SDI

SDI , .
.
MDI (Multiple Document Interface)
. , SDI, MDI , 
SDI . 
Word, 
.
.
Document/View (. . 1.3) 
SDI MDI, .
,
. 
, . exe.
, 2000 (. . 1.2), , 
, .
, 2000

1.2.

23

. 1.12 Windows

, , My Super Program (. . 1.4).


Target name ( ). , 
(. 1.12).
, Use long file names
( ) . 
my super program.exe ( ,
, ). 
2000 (. . 1.9) My Super Program. 
.
, , . 1.4, 
, . , Dockable ToolBar ( )
, (. . 1.9).
,
, .
. Status line ( )
. , SDI (. . 1.4).
. 
, .
,
.
, , 
.
Help file name ( ). 
, , ,
, ,
. 
( Borland ++).
.
, . 1.6.
, ,
Max box ( ) Thick frame ( 
).


24

. , , Window Styles
( ). Max box , 
. 
, 
.

Thick frame.
, 
. , 
,  . , 
, (. . 1.6). ,
, 
, , ,
.
. , 
. ,
, ,
, . ? 
. 2, 2.4, .

, , ,
Enter!

, .
, .
Project:2000.ide.
(. . 2.1).

. 2.1

. 
. ,
.


26

2.1.
2000app.rc .
. , , DIALOG
IDD_CLIENT (2000) . . 2.2. 
2000, 
. , 
IDD_CLIENT (2000) .

. 2.2

. Dialog Client 

, 
.
IDD_CLIENT (2000). 
Controls ( 
), (. 2.3).

. 2.3 Controls

,
Dialog Client Control Palette (
) . . 2.4.
, Grid (). 
, .
Controls ( ,
) OK. ,

2.1.

27

.  
(. 2.5).
. 
(. 2.6) ,
Properties ().

. 2.4

. 2.5

Caption ()
Button3 ,
(. 2.7).
OK, , ,
(. 2.8).

. 2.6

. 2.7


28


(. 2.9).
, , , 
Run.

. 2.8

. 2.9


, Run , 
, , (. 2.10).

. 2.10

Borland,

.
, Borland C++. 2000.ide
File Open. (. . 2.1),

.
Build () . . 1.7.
, 
. : , .
2000.exe, 
. 
Build Make (. . 1.7).
. Make 2000.exe,
, 
2000.exe (Borland ++ ). 
Build , 
, , , .
Make, 
( , !)
Build: .

2.2.

29

. 2.11

Make (Build)
( Status: Success ) . . 2.11.

. 2.12

2000.exe .
(. 2.12).
, ,
. 
.

2.2.
, ,
. ,
, .


30

Borland C++. 
, . 2.6.
ClassExpert ( ).
, ,
, . (. 2.13).

. 2.13

, , 
IDC_BUTTON1 (. . 2.7).
.
IDC_BUTTON1. ,
(. 2.14).
,
BN_CLICKED ( ) .
(. 2.15).

. 2.14 , . 2.15

Add handler ( ).
, , . 
,
. BNClickedOne (. 2.16).

2.2.

31

. 2.16

BN_CLICKED
. 
,
(. 2.17).

. 2.17

, ,
. 2000dlgc.cpp
. , , 
, . .
, (. 2.18).

. 2.18

,  
: INSERT>> Your code here ( ).


32

.
,
(. 2.19).

. 2.19

, , 
:
void T2000DlgClient::BNClickedOne()
{
// INSERT>> Your code here.
MessageBox(" \n !",
" ", MB_OK | MB_ICONINFORMATION);
}

. 2.20

, . Borland ++ 
,
. 
(. . 2.19).
, . 
, , .
, Options

2.3.

33

(), Enviroment (). 


Editor (), Display (). 
Font () 
Cyr. .
. , 
, MB_OK, MB_ICONINFORMATION MessageBox,
.
, .
Borland ++.
Borland ++
( ).
Mb_ok MB_OK *. !
. 1.7
Compile ().
() ,
Borland C++. 2000dlgc.cpp.
Compile Borland ++ ,
(. 2.20).
, 
. 3 .
Make 
.
Run. 
. . (. . 2.20).

2.3.
,
() MessageBox. 
. \n 
. . (
), . 
, MB_ICONINFORMATION , 
i (. 2.1).
2.1 MessageBox

MB_ICONINFORMATION
MB_ICONWARNING
MB_ICONQUESTION
MB_ICONSTOP

* C C++ 
C C++, Borland ++. . . .


34

MB_OK , 
. , , . 
MB_OK (. 2.2).
2.2 MessageBox


(, )

MB_ABORTRETRYIGNORE

Abort, Retry Ignore

MB_OK ( )

MB_OKCANCEL

OK Cancel

MB_RETRYCANCEL

Retry Cancel

MB_YESNO

Yes No

MB_YESNOCANCEL

Yes, No Cancel

MB_OK  , 
.
.
, 
, . , 
, .

2.4.
. ,
.
, 1.2 
, .
( 2000app.rc
). 2000dlgc.cpp 
, , .
,
. ,
.
. ,
Borland ++ .
, 2000dlgc.cpp .
2000app.cpp ( ) ,
,
. :
frame>Attr.Style |= WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN |
WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE;
frame>Attr.Style &= ~(WS_CHILD | WS_MAXIMIZEBOX | WS_THICKFRAME);

, , . 1.6.
, ,

2.4.

35

(

), 
( ).

.
,
WS_SYSMENU 
, 
. 

WS_MINIMIZEBOX. . 2.21
(. 2.21).
, , , 
.
TWindowAttr::Style.

.
( ) . 

:
frame>Attr.ExStyle |= WS_EX_TOPMOST;

Borland ++, ,
() , 
. , .
 , ..
Attr. , 
, . Attr Style. 
. ,
, . Attr 
ExStyle. (
).
,
TWindowAttr struct.
X, Y, W, H . , , X
Y ( ), 
. 
, :
frame>Attr.X =0;
frame>Attr.Y =0;

,
. , 17.



?
, .
++ .

, . 2.20.
, .
2000dlgc.cpp .

3.1.
, , 
, Borland ++ . , , 
" ".
MessageBox( \n !",

( 
, , ). Borland
++  . 
,  .
.
MessageBox(" \n !"
" ", MB_OK | MB_ICONINFORMATION);

,
. . Compile.
, . 3.1.

3.1.

37

. 3.1

Success (), Failure ().


Errors () 2. 
, , .
Messages (). 
(. . 3.2).

. 3.2

, , 
. 
, .
,
. , , 
48 60 2000dlgc.cpp (60,
48). , .
Borland ++ . ,
, Borland 
. , , 
. ,


38

. , 
. Messages,
. 
MessageBox, , 
 . , , 
,  . 3.2.
:
Error: 2000dlgc.cpp(60,48):Type mismatch in parameter "caption" in call
to "TWindow::MessageBox(const char *,const char *,unsigned int)"

, 
MessageBox. ,
. , 
( ,
), , 
, . .
. ,
caption, ,
 .
, .
,
Borland ++. ,
Error messages ( ).
, . 

Help.
. 
. , :
MessageBox(" \n !",
" ", MB_OK | MB_ICONINFORMATION;

. 
:
Error:

2000dlgc.cpp(60,48):Function call missing )

, , , 
. :
.
, ,
, , 
. Run,
 .
, Borland ++, , 
Build. (. 3.3).
OK.
(. 3.4).

3.2.

39

. 3.3

, , , Borland
++ 
2000.exe , .
: ?
, (Make, Build) .

. 3.4

3.2.
. 3.1 3.3 Warnings () . 
. :
void T2000DlgClient::BNClickedOne()
{
// INSERT>> Your code here.
MessageBox(" \n !",
" ", MB_OK | MB_ICONINFORMATION);
int a;
}

. 3.5.
Errors, 
Success. (1) (Warnings). 
, ,


40

. 3.5

Borland ++ . 
, :
Warn : 2000dlgc.cpp(64,2):'a' is declared but never used

, a ,
. , 
, . 
, , Warnings,
, . , , Borland ++
,  .
,
, .
, ,
, .

Microsoft: 
Windows 98.

.

, 
Return Values ,
.
. , .
:
y = sin(x);

, , , 
. 
. . 
. 
, . 
:
sin(x);

sin 
. .
MessageBox, 2 
, . ,


42

() .
. 

 . :
? , 
. , MessageBox,
, .
, ,
. if ().
2000dlgc.cpp :
void T2000DlgClient::BNClickedOne()
{
// INSERT>> Your code here.
if ( (MessageBox(" \n !",
" ", MB_YESNO | MB_ICONINFORMATION) ) == IDYES)
{
MessageBox(" \n YES/",
" ", MB_OK | MB_ICONWARNING);
}
else
{
MessageBox(" \n NO/",
" ", MB_OK | MB_ICONSTOP);
}
}

, MB_YESNO
MB_, .
,
, MessageBox ( 
); IDYES ..
, MessageBox (
, ) , IDYES.
:
if ( (MessageBox(...) ) == IDYES)

== .
=. , 
, ,
, .
:
if ( )
{
, ,
}
else

4
{
, ,
}

43

, 
:
if ( )
{
, ,
}

,  , 
.
: 
, . 
, , 
MessageBox. ,
(. 4.1).
.
, MessageBox :
IDYES, , IDNO, . 
, (
IDYES). , , 
, ,
MessageBox, .
, (. 4.2).
, ,
else (). 
(. 4.3).

. 4.1

. 4.2

. 4.3



, . 

. ,
:
FORMAT C:!!! ENTER!!!

C .
. ,
 .
: ,
, , 
. , 
++: , , 
, ,
. 
. .
, 2000.ide. , 
2000app.rc, 
IDD_CLIENT (2000).
. Controls 
(. . 5.1).
. , 
, . ,
. 
. .
Properties () ( 
Properties ) Text1.

45

. 5.1

,
. , 
, .
IDC_STATICTEXT
, Add instance variable 
(. 5.2).
, , mytext1, 
(. 5.3).

. 5.2

. 5.3

Controls
Common. , 5.4.
.
(. 5.5).
, , 
.
IDC_PROGRESSBAR1 
. 5.4
bar1. 


46

. 5.5

: , 
. , 
.
, :
2000dlgc.cpp*:
// Construction/Destruction handling.
//
static T2000DlgClientXfer T2000DlgClientData;
T2000DlgClient::T2000DlgClient(TWindow* parent, TResId resId, TModule*
module)
:
TDialog(parent, resId, module)
{
//{{T2000DlgClientXFER_USE}}
mytext1 = new TStatic(this, IDC_STATICTEXT1, 255);
bar1 = new TGauge(this, IDC_PROGRESSBAR1);
SetTransferBuffer(&T2000DlgClientData);
}

2000dlgc.h:
//{{T2000DlgClientXFER_DEF}}
protected:
TGauge* bar1;
TStatic* mytext1;

, , bar1
mytext1 ( 
) . 
.. 
, , :
void T2000DlgClient::BNClickedOne()
* ( Borland ++ ).

5
{

47

// INSERT>> Your code here.


MessageBox(" : ?",
" ", MB_YESNO | MB_ICONQUESTION);
bar1>SetRange(0, 100);
int dwSecs = 20;
::SetCursor(::LoadCursor(NULL, IDC_WAIT));
mytext1>SetText(" \
: ... .");
DWORD dwTimeStart = GetTickCount();
DWORD dwTimeEnd = dwTimeStart + (dwSecs * 1000);
while (GetTickCount() < dwTimeEnd)
{ bar1>SetValue((GetTickCount() dwTimeStart)/(dwSecs *10));}
mytext1>SetText(" . \
.");
}

: 
, , .
(\) , .
:
MessageBox , 
. 5.6.
, ,
.
bar1>SetRange(0, 100);

. 
TGauge. , . , , 
, 
. .
, TGauge , 
.
bar1,

:
bar1> TGauge (...);

. 5.6

, ++ ,
, ..
, .
Borland ++ ( );
; , ,
, .


48

, , TGauge 12 . 
. SetRange
. ,
100. , , 0 1 ..
int dwSecs = 20;

(, ) dwSecs. 
, , int (
integer ), , . 
, . :
// INSERT>> Your code here.
int dwSecs;


:
dwSecs = 20;

dwSecs ( ) (
). , , 
20 , .
, 
. , 
20 .
,
. 
, ,
.
++ 
, , 
, ..
,
::SetCursor(::LoadCursor(NULL, IDC_WAIT));

. 
LoadCursor, ,
Windows IDC_WAIT ().
. (SetCursor) 
:
mytext1>SetText(" \
: ....");

SetText TStatic 
mytext1, .
mytext1 , 
. 
, .

5
DWORD dwTimeStart = GetTickCount();

49

dwTimeStart DWORD
, GetTickCount.
DWORD unsigned long, (
) *.
GetTickCount, ,
, Windows. 
dwTimeStart. ,
. GetTickCount 
, ,
 .
.
, 
, DWORD 0 4,294,967,295.
, 49,7 .
, . 
, **.
DWORD dwTimeEnd = dwTimeStart + (dwSecs * 1000);

dwTimeEnd .
,
1000. ,
dwTimeEnd 
.
while (GetTickCount() < dwTimeEnd)
{bar1>SetValue((GetTickCount()  dwTimeStart)/(dwSecs *10));}

. while ().
:
while ( )
{ }

, while, .
, ,
.
. , ;
, ,
. ,
, , 

.
*

32 Windows (Windows 9x/NT/2000)


(long, long int) (int). . . .
** , Windows NT ,
, 50 . . . .


50

GetTickCount() < dwTimeEnd

, ,
GetTickCount 
. (
) , . 
SetValue TGauge bar1
. , ,
. 
. 20 , 
dwSecs, .
, .
.
mytext1>SetText(" . .");

, .
, mytext1
.

. 5.7

. 5.7 , 
.

, 
.

TGauge .




, , ,
, .

,
, .
 , , 

. .

6.1.
, . 
2006. , 
, , , . 
Add to project ( ) . . 6.1.
*.bmp 
(. 6.2).
, 
, ,
, 
.
, . 
Borland ++ , , 
:
C:/bc5/examples/owl/apps/aclock/face_bmp.bmp


52

. 6.1

, , .
BITMAP, IDB_BITMAP1.
, 
(. 6.3). .

. 6.2

. IDD_CLIENT (2000),
, . 
, . 6.4.

Static Picture ( ). ,

6.1.

53

. 6.3 Borland

,
. (. 6.5).
. ,
Properties Caption IDB_BITMAP1.
Interpret Caption As Number
(. 6.6). ,
.
.
, . 
. . 6.7. ,
( 
) Borland ++.

. 6.4

. 6.5

. 6.6

. 6.7


54

, ,
. , (. 6.8).
. , 
, , .

6.2.
,
 . , Win
dows , ,
. AVI. 
, .

. 6.8

. 6.9

, 
. , , . 


BNClickedPlay. . 2.15 2.16.
Common, 
, . 6.9.

TAnimateCtrl. ,
(. . 6.10).
avione, 
IDC_ANIMATION1.

2006dlgc.cpp. :
void T2001D6gClient::BNClickedPlay()

, AVI
. 
:
c:\bc5\examples\mfc\general\cmnctrls\search.avi

6.2.

55

Borland ++. ,
2006.
, Help , , 
TAnimateCtrl. ,
, :
Open AVI;
Play ;
Seek AVI ;
Stop .

. 6.10 IDC_ANIMATION1

BNClickedPlay :
void T2006D6gClient::BNClickedPlay()
{
// INSERT>> Your code here.
avione>Open("search.avi");
avione>Play(0, 1, 1);
}

. .

, Windows (. . 6.11).
  , Borland ++
AVI ( RLE),
.
TAnimateCtrl.
Open .
, . .
AVI (
). 0,


56

. 6.11

Open(0),
( Close ).
Play , .
, ;
, ;
. Play(0, 1, 1) 
( ) . 
1, , . .
Seek Stop .

:
void T2001DlgClient::BNClickedPlay()
{
// INSERT>> Your code here.
avione>Open("search.avi");
avione>Play(0, 1, 1);
}

1 Play ,
. , 
(. . 6.12). 
BNClickedStop
:
void T2001DlgClient::BNClickedStop()
{
// INSERT>> Your code here.
avione>Stop();
avione>Open(NULL);
Invalidate();
}

6.2.

57

. 6.12


Stop,
Open(NULL), , , Invalidate(),
, .
, Stop.
, , 
AVI.
 , . 
, ; () Open,
Play Stop  
.
, . ,
.
.
.
,
, Open :
avione>Open("c:\\bc5\\examples\\mfc\\general\\cmnctrls\\search.avi");

( Borland ++ 
.) , 
.
(, )
\n. .
, 
.
C++
.

,
.

, 
( 
) ( 
 ).
.
.
, 1.
2007.
.
, 
Controls (. 7.1)
. 7.1
, .

, . 7.2.


, ( 
, , Properties), 
Left, Top, Width
Height (. 7.3).
, . ,
, , () .
.
, 
BNClickedSinus; , 
, BNClickedClean.
, T2007DlgClient (. 7.4).

59

. 7.2

. 7.3

. 7.4

Windows.
Control Notifications, 

, . ,


60


( )? ,
,  .
Windows Messages (
Windows) Basic Messages ( ).
, Windows.
WM_LBUTTONDOWN , 
(. 7.5). 
, BN_CLICKED,
.

. 7.5

WM_LBUTTONDOWN (,
T2007DlgClient), Add handler.
WM_LBUTTONDOWN , , ,
. , 
. 2007dlgc.cpp 
:
void T2007DlgClient::EvLButtonDown(uint modKeys, TPoint& point).

EvLButtonDown Event Left Button Down (


). ,
Borland ++ . ,
, .
MessageBox:
void T2007DlgClient::EvLButtonDown(uint modKeys, TPoint& point)
{
TDialog::EvLButtonDown(modKeys, point);

7
// INSERT>> Your code here.
MessageBox(" \n !",
" ", MB_OK | MB_ICONINFORMATION);

61

. :
( )
.

. () ,
, .
, ,
. .
, 
.
EvLButtonDown, , 
:
void T2007DlgClient::EvLButtonDown(uint modKeys, TPoint& point)
{
TDialog::EvLButtonDown(modKeys, point);
// INSERT>> Your code here.
char s[16];
TClientDC dc(*this);
wsprintf(s, "(%d,%d)", point.x, point.y);
dc.TextOut(point, s, strlen(s));
}

. :
char s[16];

s. ,
char s, ,
, , , 
. s[16],
.
. , 
, . s[16]
16 s[0], s[1], s[2] s[15] (
, ).
TClientDC dc(*this);

.
, , , 
. , Windows 
, .
dc TClientDC ( , ),
this. ,
, , , .. 
, , .


62

wsprintf(s, "(%d,%d)", point.x, point.y);

. point.x, point.y
point,
EvLButtonDown . point
.
wsprintf s.
, . 
s point.x , ,
. ,
. , 
s, , 
.
dc.TextOut(point, s, strlen(s));

. 
TextOut dc :
point ( 
) s 
, strlen(s) 
. ,
s, , .
,
. , , :
dc.TextOut(point, s, 16);

. 
.
, , 
(. 7.6).
, , 
. x=0, y=0

. 7.6

63

( ).
X , Y . ,
,
. ,
.
7.3 7.6 , ,
() , 
, . 
.
.
, ,
, , .
, 
. , 
( ),
, , . , 
, , 
, , .

Windows . 
WM_PAINT Windows ,
. ,
, .
,  , .
,
WM_LBUTTONDOWN WM_PAINT, , Add
handler ( ).
2007dlgc.cpp :
void T2007DlgClient::EvPaint()

, , 
. 
, void
T2007DlgClient::BNClickedSinus().
BNClickedSinus EvPaint? . 
, , bool. 
true false ( ). , 
, false.
. false, 
, true,  . ,
BNClickedSinus true.
. 2007dlgc.h
EvPaint() bool sinus_on:
//{{T2007DlgClientRSP_TBL_BEGIN}}
protected:


64

void
void
void
void
bool

7
BNClickedSinus();
EvLButtonDown(uint modKeys, TPoint& point);
BNClickedClean();
EvPaint();
sinus_on;

sinus_on
, .
2007dlgc.cpp :
// Construction/Destruction handling.
//
T2007DlgClient::T2007DlgClient(TWindow* parent, TResId resId, TModule*
module)
:
TDialog(parent, resId, module)
{
// INSERT>> Your constructor code here.
sinus_on = false;
}

 sinus_on
. 
. BNClickedSinus :
void T2007DlgClient::BNClickedSinus()
{
// INSERT>> Your code here.
sinus_on = true;
Invalidate();
}

sinus_on ,

. Invalidate() , 
, . Invalidate()
WM_PAINT,
EvPaint. sinus_on, , true, 
.
BNClickedClean ( ) 
:
void T2007DlgClient::BNClickedClean()
{
// INSERT>> Your code here.
sinus_on = false;
Invalidate();
}

BNClickedSinus,
sinus_on , .
, EvPaint (
):

7
void T2007DlgClient::EvPaint()
{
TDialog::EvPaint();
// INSERT>> Your code here.
TPen* Pen
= new TPen(0x01f001L, 3);
TDC* sinusDC
= new TClientDC(*this);
int y;
if (sinus_on == true)
{
sinusDC>SelectObject(*Pen);
sinusDC>MoveTo(9,90);
for (int x = 10; x <= 307; x++)
{
y = 90 (sin ( (x158)*6.28/298 ))*81;
sinusDC>LineTo(x, y);
}
}
}

65

, 
. , , ,
.

TPen* Pen = new TPen(0x01f001L, 3);

Pen TPen ( 
). . ,
Pen, .
0x01f001L , . 
0x .
L , long.
, . 
RGB RedGreenBlue (). 
01f001 , ,
(, ).
. , 01
( ), f0 ( ), 01 ( ).
, .
. 10 ()
. , 17,
17 = 1*10 + 7.
16 , ,
a (10 ), b (11), c (12), d (13), e (14), f (15). 
, f0
f0 = (f=15)*16 + 0 = 240.
(RGB) 00 ff 
, 0 255 . 
Pen, , . 
, , 0x0000ffL.


66

Pen 3.
.
, ,
, .. , 
. , 
1. , .
TDC*

sinusDC = new TClientDC(*this);

, 
.
, sinusDC. 
, , , ,  . 
, DC
( dc) , ,
, , . ,
 ,
, .
int y;

y, 
y .
if (sinus_on == true)

, (
) . sinus_on true,
; false, .
, ,
.
, 
, .
sinusDC>SelectObject(*Pen);

Pen, .
sinusDC>MoveTo(9,90);

(9,90) . . 7.6. 
MoveTo , ,
. .
for (int x = 10; x <= 307; x++)
{
}

. x 10 307 (. . 7.6),
. 9 , 
, x = 9.
y = 90 (sin ( (x158)*6.28/298 ))*81;

67

x y.
, . 
, .
sinusDC>LineTo(x, y);

, 
, (x, y).
. , 
(. 7.7).

. 7.7


sin. , 2007dlgc.cpp, ,
#include, :
#include "math.h"

.
2007dlgc.h bool sinus_on bool cosinus_on,
.


BNClickedCosinus.
BNClickedCosinus 2007dlgc.cpp ,
, BNClickedSinus:
void T2007DlgClient::BNClickedCosinus()
{
// INSERT>> Your code here.
cosinus_on = true;
Invalidate();
}

BNClickedClean ( ) , 
cosinus_on false. ,


68

, . 
BNClickedClean :
void T2007DlgClient::BNClickedClean()
{
// INSERT>> Your code here.
sinus_on = false;
cosinus_on = false;
Invalidate();
}

, EvPaint. 
, .
Pen2 , , .
cosinus_on true, 
. EvPaint
:
void T2007DlgClient::EvPaint()
{
TDialog::EvPaint();
// INSERT>> Your code here.
TPen* Pen
= new TPen(0x01f001L, 3);
TPen* Pen2 = new TPen(0x0000ffL, 3);
TDC*
sinusDC
= new TClientDC(*this);
int y;
if (sinus_on == true)
{
sinusDC>SelectObject(*Pen);
sinusDC>MoveTo(9,90);
for (int x = 10; x <= 307; x++)
{
y = 90 (sin ( (x158)*6.28/298 ))*81;
sinusDC>LineTo(x, y);
}
}
if (cosinus_on == true)
{
sinusDC>SelectObject(*Pen2);
sinusDC>MoveTo(9,170);
for (int x = 10; x <= 307; x++)
{
y = 90 (cos ( (x158)*6.28/298 ))*81;
sinusDC>LineTo(x, y);
}
}
}

sinusDC ,
, .
(9,170), 
sin cos. 
, , .

69

, ,
(. . 7.8).
( LineTo 
),
, .

. 7.8

, , 
.
, 
.

Windows 2000 
... 
.


. .
, , 
.
, , 
. ,
.
, 
shareware: 
, 
, . ,

, , , 
. .
, 2007. ,
Disable
(Properties) . . 8.1. , 

.
, , 
,

71

. 8.1 Disabled

ButtonCosinus . . 8.2. 
.
,
 BNClickedPassword. 
, . 8.3.

. 8.2

2007dlgc.cpp BNClickedPassword 
:
void T2007DlgClient::BNClickedPassword()
{
// INSERT>> Your code here.
char inputText[6];
wsprintf(inputText, "");
if ((TInputDialog(this, " ",
" :",


72

. 8.3

inputText,
sizeof(inputText))).Execute() == IDOK)
{
int InputPassword = atoi(inputText);
if ( InputPassword == 4321 )
{
ButtonCosinus>EnableWindow(true);
MessageBox( " ",
" ",
MB_ICONINFORMATION);
}
else
{
MessageBox( ", ",
" ",
MB_ICONSTOP);
}
}
}

, #include, :
#include <owl/inputdia.h>

 ,

.
, , , 
MessageBox, .
char inputText[6];

,
, . ,
, , ,
.

8
wsprintf(inputText,"");

73

, 
. ,
.
, , 
:
if ((TInputDialog(this, " ",
" :",
inputText,
sizeof(inputText))).Execute() == IDOK)

if (
) , .
4.
MessageBox,
, MessageBox. 
.
TInputDialog().Execute()

TInputDialog 
Execute() . 
IDOK, OK
(. . 8.4).
, 
TInputDialog, , 
. this, 
,
.
inputText sizeof(inputText). ,
(), 
. 8.4

.
,
. wsprintf,
, .
OK, 
, .
, ,
, 
. Execute() 
IDOK, if 
.
,  
. Execute() IDOK, if
. 
, ,


74

. , ,
inputText . 
. , ,
, .

atoi().
int InputPassword = atoi(inputText);

InputPassword 
, atoi, 
inputText.
. , ,
 .
, , 
. 4321,
(
InputPassword).
if ( InputPassword == 4321 )

, , 
, 
:
ButtonCosinus>EnableWindow(true);

ButtonCosinus.
, TButton. 
EnableWindow.
. 
TButton EnableWindow.
, 
, ,
.
,
Borland ++. Borland ++ 
TWindow. TWindow TControl,
TButton. TButton ,
, EnableWindow.
, TWindow.
EnableWindow, ,
.
MessageBox,
, .
.
, 
else, , 
.

75

, .
, 
. 
.
. Run
Borland ++, , . 8.5.

. 8.5

, , 
,
, . (  , ,
 , .)

Windows,
 ; Borland ++,
,  .
, , , Borland
(Debug), , , Debug,
Terminate process.
, 
, . 8.6.

. 8.6

, 
, .
, Borland ++ .
. ,  Borland ++.


76

. . ,
, Add
to project (. 8.7).

. 8.7

*.rc inputdia.rc (. 8.8). 


Borland ++ C:\bc5, C:\bc5\
include\owl.

. 8.8 Borland C++

DIALOG,
(. 8.9).
. . .
, . 8.4 . 8.9.
,
, .

, ,
.

77

. 8.9 DIALOG

, ,
EnableWindow, false.
,
, 
. ,
shareware ,

. 
 
(
Windows) .


,
.

:
, .
!

, ,
. ( ) ,
, , , 2007.key,
.
2007.key,
( ),
, , , .
2007.ide, 8.

, 
Password ,
.
2007.key 
, 2007dlgc.cpp, :
T2007DlgClient::T2007DlgClient(TWindow* parent, TResId resId, TModule* module)
:
TDialog(parent, resId, module)
{
// INSERT>> Your constructor code here.
sinus_on = false;
cosinus_on = false;
}

79

cosinus_on = false;
:
checkpassword = false;
if ( (keyfile = fopen("2007.key", "r")) != NULL)
{
checkpassword = true;
fclose(keyfile);
}

2007dlgc.h .
bool cosinus_on:
FILE *keyfile;
bool checkpassword;

, int (
) char (), ( 
) keyfile. 2007dlgc.h,
.

2007dlgc.h, FILE .
#include :
#include <stdio.h>

stdio.h, 
FILE. ,
Call to undefined function ( ), ,
, (
, , , ++ 
).
, , ( 
) :
keyfile = fopen("2007.key", "r")

keyfile 2007.key ( ,
, ).
fopen (mode) . r
, . fopen 
(
), 
NULL. 
if :
if ( (keyfile = fopen("2007.key", "r")) != NULL)

, NULL (
!= ), , 
:
checkpassword = true;


80

checkpassword 
, , . 
keyfile:
fclose(keyfile);

, 
. ,
.
, , 
EnableWindow, , .

, ? 
fclose(keyfile); :
ButtonCosinus>EnableWindow(true);
Password>EnableWindow(false);

, . ,
2007.key, .
. . , 
, 2007dlgc.cpp,
,
(Disabled).
EnableWindow .
checkpassword ,

true, . ,
. . 
, EvPaint,
. :
if ( checkpassword == true)
{
ButtonCosinus>EnableWindow(true);
Password>EnableWindow(false);
}

. , , 
.
SetupWindow.
, ( )
, , .. ( . 14).
. 
2007.key, , 
(. 9.1). 
, (. 9.2).

81

. 9.1

. 9.2

: , 
7. , 
( ),
, 2007.key . 
:
if ( InputPassword == 4321 )
{
ButtonCosinus>EnableWindow(true);
MessageBox( " ",
" ",
MB_ICONINFORMATION);
}


:
checkpassword = true;
keyfile = fopen("2007.key", "wt");
struct date d;


82

getdate(&d);
char regdate[15];
wsprintf(regdate, "%d\n%d\n%d\n", d.da_year, d.da_mon, d.da_day);
fputs(regdate, keyfile);
fclose(keyfile);
Invalidate();

.
checkpassword = true;

, , checkpassword
true. EvPaint,
/ .
keyfile = fopen("2007.key", "wt");

2007.key, 
wt. r, 

( 
, ).
, fopen NULL 
. wt : 
, ,
. ;
t , ( 
/, b). , 
fopen, , 
/ . , w r,
a ( ), 
+, , .
Borland C++.
struct date d;

. 
, ( 
). , ,
. date 
d. ,
date, <dos.h> ( getdate).
struct date {
int da_year;
char da_day;
char da_mon;
};

/* current year */
/* day of the month */
/* month (1 = Jan) */

, . ,
da_day da_mon char, int, :

83

char , . 
.
, :
getdate(&d);

getdate d ,
. 
d , .
char regdate[15];

,
. , 
, ( ;
).
wsprintf(regdate, "%d\n%d\n%d\n", d.da_year, d.da_mon, d.da_day);

, .
: , .
wsprintf 7.
(
). 
,
, , \n,
. 
regdate
. 9.3 ,
. 9.3 ,
.
fputs(regdate, keyfile);

() regdate
keyfile. .
, . 9.3.
, :
fclose(keyfile);
Invalidate();


, , .
. .
, , ,
; ..
, , 
trial, , 
.

10

:
.
: ++.

, 
++.
, 
 . ,
password, password, 
, .
,
. :
int ;
char ;
bool .

. int. 
( , 
++), ,
32 (4 ) 2,147,483,648
2,147,483,647.
short int unsigned int.
(short int) , 
, int. 
: 32,768 32,767.

10

85

,
short int.
(unsigned int) ,
32 . 0 4294967295.
char , .. 
, , , 
. , char ,
int. , char ( 
) 128 +127, . ,
,
char int.
date. , ,
, 1 12,
da_mon, , char;
. char int , 
() .
bool
0 1, false true ( ). 
, *.
float double
. , 
, ,
int .

:
int x;

, , 
. , , 
. ,
,
.
, 
. : 
; , Borland ++, ,
int; Borland ++
32 ( , ).
. , , 
, x1 X1 , ,
.
, , 
. : +, , *, /. (
* , bool (8 ), 
. ,
. . . .


86

10

%, .)
a = x + y ++ , , :
a = x. (
) : a = a x.
, i++,
: i = i + 1.
. if
for >, >=,
<, <=, ==. : =,
.
, , .


11

, 
, 
: 
, ,
, .



. ,
, ,
.
.
, 
29 3000 .
,
. .

11.1. trial
, , . 
2011.key, 
. 
, , Windows.
,
, ,
; ,
30 , .


88

11

(trial) . 
, , , 
, .
2007,
, 1, 2011.
, 
.
2011dlgc.cpp
, :
#include "stdio.h"

, 
:
// INSERT>> Your constructor code here.


. :
struct date curdate;
char filepath[80], regdate[12], regyear[5], stringrestdays[80];
int ryear, rmonth, rday, month1, month2, day1, day2, restdays;
FILE *keyfile;
GetWindowsDirectory(filepath, 80 );
strncat(filepath, "\\", 1);
strncat(filepath, "2011.key", 8 );
getdate(&curdate);
if((keyfile = fopen(filepath, "r")) == NULL)
{
keyfile = fopen(filepath, "wt");
wsprintf(regdate, "%d.%d.%d", curdate.da_year,
curdate.da_mon, curdate.da_day);
fputs(regdate, keyfile);
fclose(keyfile);
}
else
{
fgets(regyear, 5, keyfile);
fseek(keyfile, 1, 1);
ryear = atoi(regyear);
month1 = fgetc(keyfile);
if(( month2 = fgetc(keyfile) ) == 46)
{rmonth = month1 48;}
else
{
rmonth = (month1 48)*10 + (month2 48);
fseek(keyfile, 1, 1);
}
day1 = fgetc(keyfile);
if ( ( day2 = fgetc(keyfile) ) == EOF)
{
rday = day1 48; }
else
{
rday = (day1 48)*10 + (day2 48) ;}

11.1. trial
restdays = 30 (365*(curdate.da_year ryear)
+ 30.5*(curdate.da_mon rmonth)
+ (curdate.da_day rday));
if(restdays < 0)
{
MessageBox(", ",
"", MB_ICONSTOP);
exit(0);
}
else
{
wsprintf(stringrestdays,
" %d ", restdays);
MessageBox( stringrestdays, "",
MB_ICONINFORMATION);
}

89

, ,

. ( ) . 
: 
.
struct date curdate;

9, date curdate 
.
char filepath[80], regdate[12], regyear[5], stringrestdays[80];
int ryear, rmonth, rday, month1, month2, day1, day2, restdays;
FILE *keyfile;

, ,
. :
,  , 
, , , 
, . 
,
, .
GetWindowsDirectory(filepath, 80 );


, ( 
) Windows. ,
, , .
, Windows. Borland C++ 
Help Windows API (. 11.1), Windows
Windows Developers Guide.
, filepath ,
Windows. . Windows


90

11

. 11.1
Windows

 , , C:\windows, 
filepath ,
(\) . 
Windows 
, filepath 
C:\, .
, 
, .
, , . 
? , 
:

strncat(filepath, "\\", 1);


strncat(filepath, "2011.key", 8 );

strncat 
.
\
Windows. , (\\) 
,
. , \n ,
. , , \\.

2011.key, () filepath :
C:\windows\2011.key. .
getdate(&curdate);

getdate
curdate , 
, 
.
if((keyfile = fopen(filepath, "r")) == NULL)

,
. , fopen ( r) 
, 0 (NULL).
if. , 
.
, , 
( ,
, ). , 
,
.
keyfile = fopen(filepath, "wt");

.
. .

11.1. trial
wsprintf(regdate, "%d.%d.%d", curdate.da_year, curdate.da_mon,
curdate.da_day);

91

. ,
,
.
, . 11.6. , 
.
fputs(regdate, keyfile);
fclose(keyfile);


. 
, .
,
. fopen if 
NULL ,
else:
fgets(regyear, 5, keyfile);
ryear = atoi(regyear);

fgets 5 
. , 4 , 
. , () regyear 
. (
), ,
4 *.
atoi regyear 
ryear. . . 
,
. , 12 (
10 9),
(6 ), (12 ). 
, (). 
.
fseek(keyfile, 1, 1);

. 
, .
. , 
. 
fseek , .
* , fgets :
( ), 
. fgets ,
, , , 
. . . .


92

11

. 
.
fseek , (
). ,
(
).
month1 = fgetc(keyfile);

month1. 
fgetc 
. 
: (,
, month1), 
( ).
if ( ( month2 = fgetc(keyfile) ) == 46)

fgetc ,
month2 ( , ).
46. .
, 
 HEXviewer 
( ). . 11.2 , 
.

. 11.2

, ANSI Text, 
: , , .
Bytes . ,
, 2.
( ) :
216 + = 216 + 14 = 46

fgetc, , 
46.
, , 
. , 46, 
:
1. month1.
: , , 5,

11.1. trial

93

month1 5, 53 5 (. . 11.2). 5 
35,
316 + 5 = 53

,
48. , .
2. , 
. .
, if ,
rmonth , 
month1 :
rmonth = month1 48;

, , .
month1
(, 1, 20),
month2 .
, ,
:
rmonth = (month1 48)*10 + (month2 48);

:
fseek(keyfile, 1, 1);

, 
, .
, :
rmonth,
( ).
( ) , 
. .
,
EOF (End Of File) 
. , ,
EOF . , 
EOF, .
, rday 
.
restdays = 30 (365*(curdate.da_year ryear)
+ 30.5*(curdate.da_mon rmonth)
+ (curdate.da_day rday));

, curdate,
,
ryear, rmonth rday (, ), 
30 ,


94

11

. 
30 ,
, ,
. ,
. 
.
if (restdays < 0)

, ,
, . , ,
. :
MessageBox( ", ",
"", MB_ICONSTOP);
exit(0);

exit(0) .

. , exit
. ,
MessageBox, exit(0) 
. .
restdays , :
wsprintf(stringrestdays,
" %d ", restdays);
MessageBox( stringrestdays, "", MB_ICONINFORMATION);

wsprintf stringrestdays ,
. .
: , 
 , 
( %d, ),
( restdays).
,
,
. , 
.
, stringrestdays, 
, MessageBox. 
, MessageBox ,
() .

.
, .
.

11.2.

95

, Windows 2011.key.
, . 
. ,
, 30
. ( , ),
. ,
.
, .
, , 
, . , 
, ,
, . 
, . 
.

11.2.

. ,
 . , ,
, , 
. , 
, , , .
, 2011.exe.
2011crack.exe, 2011.key
.
.
EasyWin , MS DOS (, 
, ).
, Borland ++,
, . 11.3.

. 11.3

,
. 11.4.


96

11

. 11.4

,
2011crack.cpp :
#include <dir.h>
#include <stdio.h>
#include <windows.h>
void main()
{
char filepath[80];
GetWindowsDirectory(filepath, 80 );
chdir( filepath );
struct ffblk fileone;
FILE *keyfile;
if((findfirst("2011.key",&fileone,0)) != 0)
{
printf(" 2011.key ,\n , \
");
}
else
{
keyfile = fopen(fileone.ff_name, "r+t");
fseek(keyfile, 1, 0);
fputc('3', keyfile);
fclose(keyfile);

11.2.
printf(" , 2300 \n");

97

}
}

, , !
. #include 
, . (
), .
void main()

main() . 
.
WinMain 
. 
. , 
. 
, 2011crack.cpp
main.
char filepath[80];
GetWindowsDirectory(filepath, 80);

filepath, 
Windows filepath
, .
chdir( filepath );

. , 
, .
,
( ,
), , 
. .
chdir Windows. 
:
findfirst("2011.key",&fileone,0)

, 
. (
2011.key) , , *.bmp,

bmp.
ffblk. fileone:
struct ffblk fileone;

, 
. , 



98

11

. , findfirst
findnext.
findfirst 2011.key.
, 0, , 1. 
:
printf(" 2011.key ,\n , \
");

(, wsprintf). 

EasyWin.
,
else:
keyfile = fopen(fileone.ff_name, "r+t");

keyfile:
FILE *keyfile;

.
fileone, findfirst. 
r+t ,
(r)  (+).
fseek(keyfile, 1, 0);

fseek . ( )
, keyfile.
0, 1, 0 fseek 
.
fputc('3', keyfile);

fputc .
'3',
. .
, "" . ,
"3", , . 
, , fputc
, .
, 
3. , , 2000.5.13,
2300.5.13. 2011.exe,
, 2300 .
fclose(keyfile);
printf(" , 2300 \n");

11.2.

99

, 
. , 
, ,
. 11.5.

. 11.5 D


EasyWin,
Windows . ,
, 
(EOF).
, 
() .

, . 11.6.
2011.exe 
, . 11.7.

. 11.6

. 11.7

, ,
. 11.8.
. 
, 
. :
printf(" , 2300 \n");

, ...
, .


100

11

. 11.8

, , (,
) . . 11.9.
, (, )
. , ,
Windows 98, Microsoft.

. 11.9 ,


12

,
!

, . debugger ().
. , 8,
, Borland C++,
,
.
,
( ) 
, .
. 3.
, 
 . 
Borland ++ .
,
, .
8 Borland ++?
, .
, , .
,
, . , ,
, , .
 
. , ,
, 
.


102

12

, , ,
. , , 
2+2 5. , 
. ,  
. .
. , 
, , .
, 
. 
, . ,
,
 . :
, ( ) 
,
.
,
.
2011.exe, 
11. ,
. , , 
(, ,
). . , , 
,
. .
:
else
{
fgets(regyear, 5, keyfile);
ryear = atoi(regyear);
fseek(keyfile, 1, 1);
month1 = fgetc(keyfile);
if ( ( month2 = fgetc(keyfile) ) == 46)

,
fseek(keyfile, 1, 1);

:
fseek(keyfile, 1, 0);

, , 
fseek.
. , , Borland
++ , ,
( 0
fseek), (
1).

12.1.

103

, Windows 2011.key (
11), . 
. .
, . 12.1.

. 12.1


, . .

12.1.


Borland ++. Borland ++ ,
, . 
. , 
.
, .
. Windows, ,
2011.key .
, else 
.
30 , 
(. . 12.1).
, 
, :
if (restdays < 0)
{
MessageBox( ", ",
"", MB_ICONSTOP);
exit(0);
}

, , restdays < 0,
restdays 30. ,
?
. if :


104

12

char s[100];
sprintf(s, "restdays = %d", restdays);
MessageBox(s, "");

s, ,
restdays MessageBox. ,
, ,
restdays. , ,
. 12.2.
,  ,
2011.key, .
, 
. (, 8 
2000 ) . . 12.3.
,  . 
, . 
:
char s[100];
sprintf(s, "ryear = %d\nrmonth = %d\nrday = %d", ryear, rmonth, rday);
MessageBox(s, "");

: MessageBox

.

. . 12.4.

. 12.2

. 12.3

. 12.4
!

, 19 0  . 
, , .
rmonth
month1 month2. , 
rmonth. :
month1 = fgetc(keyfile);
if ( ( month2 = fgetc(keyfile) ) == 46)
{
rmonth = month1 48;
}

12.1.
else
{
rmonth = (month1 48)*10 + (month2 48);
fseek(keyfile, 1, 1);

105

,
if. MessageBox, 
:
month1 = fgetc(keyfile);
if ( ( month2 = fgetc(keyfile) ) == 46)
{
rmonth = month1 48;
MessageBox("if", "");
}
else
{
rmonth = (month1 48)*10 + (month2 48);
fseek(keyfile, 1, 1);
MessageBox("else", "");
}

, , ,
. .
, . ,
. 12.5.
, 
, , . 
. , 
month1.
, MessageBox,
. , MessageBox,
. 12.5
, , :
char s[100];
sprintf(s, "month1 = %d", month1);
MessageBox(s, "");

, 
. 12.6.
48 0 ( 
11). (. 12.3),
, 7.
0? .
, ?  . 12.6
, , 
month1 .
fgets(regyear, 5, keyfile);
ryear = atoi(regyear);


106

12

fseek(keyfile, 1, 0);
month1 = fgetc(keyfile);

, , .
. ,
month1.
, :
fgets(regyear, 5, keyfile);
fseek(keyfile, 1, 0);
ryear = atoi(regyear);
fpos_t pos;
fgetpos(keyfile, &pos);
char s[100];
sprintf(s, "current position = %d", pos);
MessageBox(s, "");
month1 = fgetc(keyfile);

fgetpos
keyfile pos fpos_t.
MessageBox. 
, , . 12.7.
,  , . 
5 , 7 ( 
2 
).
1.
, . 
. 12.7
. ,

, 
. , 
, .
,
MessageBox . 
, 
, 
pos keyfile.
, MessageBox , 
.

12.2.
, MessageBox
, .
, MessageBox 
, .

.

12.2.

107

, ( ) ,
. ,
, 
, MessageBox,
.
,
. , 211dlgcl.cpp.
,
. , 
else MessageBox, 
, . , 
restdays 0.
, . ,
, . , 
.
,
, breakpoint. , 
2011dlgc.cpp, ,
, . 12.8. ,
, .

. 12.8

. ,
. 12.9 ( , 
) , .

. 12.9


108

12

, , 
.
, 
, . 
,
. Run . . 1.7.
Debug Run ( ) . . 12.10.

. 12.10

: 
, 
. , . 12.11.
, , 
, ,
. 
Bor
land ++ . . 12.11.

. 12.11

, 
. , ,
, . ,
restdays .
.
, , ,
.
: 
( ).
. ,
,

12.2.

109

. 
restdays 302 (. 12.12).
, 
ryear, rmonth, rday. 4, 3 2 
. 
. . 12.13 12.14.

. 12.12

. 12.13 ryear

. 12.14

. 12.14 : , 
( , , ),
rmonth ,
. 
. , ,
rmonth, ryear. 
, ,
.
. ,
. 12.15.
, .
. , . 
(. . 12.16). ,
, .
. Run
Debug Run. , . 12.17.


110

12

. 12.15

. 12.16

(
), Borland ++ , 
. ( ), .
. :
. , 
(. 12.18).

. 12.17 Borland ++

. 12.18

. , . 12.19.
. 
. :
. ,
. 12.20.
. . , 
. , ryear,

. 12.19

12.2.

111

. 12.20

rmonth, rday.
(. 12.21).
, 
.
, 
MessageBox?
(). , 
.

. 12.21 rmonth

View Watch (),


. 12.22.
Watches. 
. 
. . 
, Watches ,
. (. 12.23).
, Add Watch (
). .
. . 12.24.

. 12.22

. 12.23
Watches

. 12.24


112

12

Expression () ryear
O. , . 12.25.
Watches 
( , ).
Watches. 
,  .

. 12.25
Watches

. 12.26 rmonth

2011dlgc.cpp,
rmonth ( ) . . 12.26.

Watch (. 12.27).
Watches , 
. Window, 
. 12.28.
, , Watches
( , ).
Window Watches. , ryear
rmonth (. 12.29).
rday Watches
, , 
. 12.30.

. 12.29

. 12.27

. 12.28 ,

. 12.30

12.2.

113

month1. 
(. 12.31).

. 12.31

, . 
(. 12.15).
, .
, . 12.32.
. 
, (. 12.33).

. 12.32

. 12.33

Watches, Window.
. 12.34.
,  ,
ryear, .

. 12.34

.
, .
, . 12.35,
Watches ,
.
(. 12.36).
:
fgets(regyear, 5, keyfile);


114

12

. 12.35

. 12.36

.
, . Watches
, 
. 
(. 12.36) , Watches 
(. 12.37).

. 12.37

. 
(. . 12.37) :
ryear = atoi(regyear);

ryear 2000.

12.2.

115

. 
month1, . 12.38.
, . ?

. 12.38 month1 48

, 
(. . 12.24), Expression ().
,

,  . ,
,
. , Expression
ryear+rmonth, .
, . ,
, 
.
, 
fgetpos . 
, ftell.
.
, . 12.15.
Watches, , Add
Watch Expression :
ftell(keyfile)

,
, 
. , , Watches 
 ..


116

12

, Expression
ftell(keyfile), Borland ++ Call to undefined function
ftell ( ftell), , 
Watches, ( )
Edit Watch ( ). , Thread
ID 0.
. , 
(. 12.39).

. 12.39

, . 
(. . 12.36). , 
4
(. 12.40). .

. 12.40

12.2.

117

.
, . 12.41.
, , ,
. ftell:
fseek(keyfile, 1, 0);

5 1. 
.

. 12.41

, (
) , , 
Borland ++. , 
, .
.


13

?
!

, 
. ,

. TInputDialog,
. 
, . ,
( ) .
,
, .
, , .
, , ,
,
, .
. 13.1
1

2013. 

. Controls 
(. 13.1).
, 
. (. 13.2).
Properties. 
Edit1 Caption ( ) 
Number ( , 
, ) . . 13.3. ,

13

119

. 13.2

Number ,
( ), 
, , , 3,62.

. 13.3

.
Ctrl;
; , , 
(. 13.4); ; Ctrl.


120

13

. 13.4


. , , , 
. , , .
.
Properties
Readonly ( ), . 13.5.
,
.
,
(. 13.6).

. 13.5

. 13.6

13

121

.
(,
ClassExpert).
IDC_EDIT1, IDC_EDIT2 IDC_EDIT3. ,
x, y result 
(. 13.7).

. 13.7 x

 BNClickedSumma.
, 2013dlgc.cpp. 
BNClickedSumma :
char strx[100], stry[100], strresult[100];
int numx, numy, numresult;
x>GetText(strx, 100);
y>GetText(stry, 100);
numx = atof(strx);
numy = atof(stry);
numresult = numx + numy;
sprintf(strresult, "%d", numresult);
result>SetText(strresult);

(
):
#include <stdio.h>

, .

.
GetText,
x y, strx stry.
, .
TEdit. TEdit GetText, 
TEdit TStatic. 
100.

atof. , 
numresult.


122

13

. 13.8

, sprintf,
numresult strresult, SetText
strresult result.
, , , .
1 2, . 
3 (. 13.8).
. 
,
: . 
(. 13.9).

. 13.9

? , .
, . 13.10.
. , 
. .
. . 
,
(. . 12.36) 
. ,

13

. 13.10

123

. 13.11 stry

strx stry . 
, . 13.11.
, , , 
stry, , \0,
.
, 100 .

. numx (. 13.12).
, , int 
2,147,483,647, 2 . 
10. 999 . , 
TEdit .
int double. ,

int numx, numy, numresult;

( ):
double numx, numy, numresult;

. 13.12
int

. 13.13
double

, .
numx, (. 13.13).
. 13.13 . , ,
numresult (. 13.14).
numresult
strresult , ,
. . 13.15.


124

13

. 13.14

. 13.15

, 
int double . 
 %d, , 
. %d %.0f, f ,
( double), 
( )
.
strresult (. 13.16).

. 13.16

, . , , 
, (. 13.17).

. 13.17

. 13.18

13

125

. , 
: . 
(. 13.18).
. , 
: 2 2 , , 4.
2 3, , 
. (. 13.19).

. 13.19 3 + 2 = 4

. 13.20

, ,
. .
, , . 13.20.
Classes T2013DlgClient, Events 
Control Notification, IDC_EDIT1.
TEdit .
EN_CHANGE (. change ). 
. , (
EN_CHANGE) Add handler (. 13.21).
ENChangeX (. 13.22).

. 13.21 ,

, 
, ENChangeY. 2013dlgc.cpp.

. , . 13.23.


126

13

. 13.22

. 13.23

.
. , 
, .
,
.

, ... ? , 

, .

, (
 ). BNClickedSumma,
. 
. ,
. 
. , ,
, . 13.24.

. 13.24

, , ,
ENChangeX, , , 
BNClickedSumma,
. , 
, , .


14


, 
!
?!!
!
!..

,  .
, 3040 ,
Borland ++ 810 .
? , 50
, . 
, .

14.1.

,
, 2013.ide ( )
9,5 . , . 14.1.
Target. (. 14.2).
2014. (Target Type) 
(Application [AppExpert]). , 
. Generate.
Project ... (. 14.3).


128

14

, 
( ). 
Borland ++
,
.
, 
. 14.1
. 
2014.exe ( . 14.3) 
Run. 2014 ,
. ,
, . 12,5 .
, .
, 9 .
, 12 , 18.

. 14.2

. 14.3

, ( ) , 
. , :
 , (,
, , ),

. Borland ++ 
, ..

14.2.

14.2.

129

,
. 2013.exe,
. ?
2013.exe 2014.exe (node) 2013.ide.
, 2013dlgc.cpp ,
, . 13.23,
, 
.
, Windows
+ + 
. + 
. , . 
.
,
. : 
, TEdit. , 
+ , .
( ,
): , ,
Classes T2013DlgClient Events
Windows Messages, Basic Messages (. 14.4).

. 14.4

(. 7, . 7.5). 
, Windows,  
. . 
, Windows WM_CHAR (.
char , ) , ( , 
).


130

14

WM_CHAR , 
(, ). 
TEdit.
, Add handler (. . 14.4) 
, . 
WM_CHAR ,

.
TEdit , ,
, , +. ()
, 
TEdit, TButton ( , ).
.
: ,
0,1 +, ,
BNClickedSumma. , 
Borland C++.
2013dlgc.h
( , ):
protected:
void BNClickedSumma();
void ENChangeX();
void ENChangeY();


, 
. :
void EvTimer(uint timerId);
void SetupWindow();

. 
, . 
, 
.
2013dlgc.h :
void T2013DlgClient::SetupWindow()
{
TDialog::SetupWindow();
SetTimer(NULL,100);
};


.
. 2013dlgc.cpp, 
( ):
DEFINE_RESPONSE_TABLE1(T2013DlgClient, TDialog)

14.2.

131

. , 
Windows . :
EV_EN_CHANGE(IDC_EDIT2, ENChangeY),
EV_WM_TIMER,
//{{T2013DlgClientRSP_TBL_END}}

, .
(
, , ,
,
):
void T2013DlgClient::EvTimer( uint )
{
if (GetKeyState(107) < 0) BNClickedSumma();
}

, 
. , 
. . 
+ ().
.
, :
void SetupWindow();

TDialog, ,
, . , 2013dlgc.h,
,
( T2013DlgClient), 
TDialog.
.

++. ,
. , 2013dlgc.h
TDialog :
class T2013DlgClient : public TDialog { ... };

TDialog  ,
T2013DlgClient.
, 
. , , , 
:
void BNClickedSumma();

TDialog,
T2013DlgClient. , 
, .


132

14

, 
. SetupWindow().
. 
, :
void T2013DlgClient::SetupWindow()
{
TDialog::SetupWindow();
SetTimer(NULL,100);
};

T2013DlgClient::SetupWindow(), 
, TDialog::SetupWindow()
( ), 
:
SetTimer(NULL,100);

,
SetupWindow() . 
,
9. , 
.
SetTimer
Borland ++. , 100 ( ). 
100 (0,1 ) 
WM_TIMER .
, , , 
EV_WM_TIMER. , 
:
void EvTimer(uint timerId);

SetupWindow(), 
, :
if (GetKeyState(107) < 0) BNClickedSumma();

GetKeyState 
107. 107 . 
, GetKeyState .
EvTimer BNClickedSumma(),
.

 , 
, , , ,
.
, , , 
, .
7.

14.3.

14.3.

133

TEdit, 
.
,
TEdit,
(. 14.5). char1.
2013dlgc.cpp EvTimer
:
void T2013DlgClient::EvTimer( uint )
{
if (GetKeyState(107) < 0) BNClickedSumma();
int i; char itext[100];
for ( i = 0; i < 255; i++ )
{
if (GetKeyState(i) < 0)
{
sprintf(itext, "%d", i);
char1>SetText(itext);
break;
}
}
}

, 107, 
+ .
, , 0 255.
255? 0 255.
,  , :
GetKeyState(i) < 0

i itext
sprintf, 
 char1. break, .

. 14.5 16


134

14

,
(, 42 53), 
42, 42 ,
53.
, 
(. 14.5).
. ,
,
, (
. 14.5).
, ,
.
, , , ,
1 2. ,
Windows .
.


15


, 
.

15.1.

, , 
TCheckBox. , , 
, ,
. TCheckBox TButton,
. ,
.
, :
. 
( ), 
. , 
.

.
, .
GetCheck , :
BF_CHECKED ;
BF_UNCHECKED ;
BF_GRAYED .


136

15

SetCheck 
.
, 
.
, ,
.
. 
2013.exe. , 
, 
(. 15.1).
.
, (. 15.2).

. 15.1

. 15.2

Properties .
Caption, , Checkbox
Type Auto.
. 
, , ,
. ,
, . ,
,
.
,
. , (
) BNClickedSumma(),
.
, 
. , 
,
. , 
,
IDC_CHECKBOX1. BN_CLICKED, ,

15.1.

137

Add handler (. 15.3)


BNClickedMinus.
, 
. .
IDC_CHECKBOX1 (. . 15.4), . 
checkminus.

. 15.3

. 15.4


2013dlgc.cp. , , BNClickedSumma()

numresult = numx + numy;

,
:
if ( checkminus>GetCheck() == BF_CHECKED )
numresult = numx numy;
else
numresult = numx + numy;

checkminus,
BF_CHECKED, ; .


138

15

BNClickedMinus
:
BNClickedSumma();

, . 
, ( 
), SetupWindow():
checkminus>SetCheck(BF_CHECKED);

.
. ,
. 
. . 

.

button1 . . 15.5.

. 15.5

BNClickedMinus :
if ( checkminus>GetCheck() == BF_CHECKED )
button1>SetWindowText("");
else
button1>SetWindowText("");

, 
.
. 
.

15.2.
(, )
.
. ;

15.2.

139

, 
.
, 
.. , . ,
TRadioButton () TCheckBox
(), , , TButton (
).
. 
. ,
2013.ide, 2013.exe, ,
, .
(. 15.6), ,
. 15.7. 
, , . 15.7.

. 15.6

. 15.7

. , 
, . 
: ,
; , ,
, ,
.
. ,
, . 15.7 (
RadioButton1, RadioButton2, 3 4),
, RadioButton1
RadioButton3, RadioButton2 RadioButton4.
, 
.
( , 
). , ( Properties) 
, Group Flag


140

15

RadioButton1 RadioButton2 , RadioButton3 RadioButton4


( . . 15.8).
, . 15.9,
Set Creation Order.

. 15.8 RadioButton1

. 15.9

, . 15.10.
.
, 
, , .
,

. 15.10

15.2.

141

. ,
.
, (Creation Order) 
. , , ,
. , , 
,
. 
,
(. 15.11). , 
, .

. 15.11

. 15.12 ,

,
, , 
End Mode (. 15.12). Cancel Mode
.
.
.
, , 
.
, 
: RadioButton1 RadioButton3,
: RadioButton2 RadioButton4 (. 15.11).
Group Flag, 
, RadioButton1 RadioButton2.
,
.


.


142

15

,
.
Caption (. 15.13).

. 15.13

, ,
, minusyes
minusno . ,
BNClickedMinusYes BNClickedMinusNo.
, . 15.14.

. 15.14 !

. 
(,
minusyes) , SetupWindow :
minusyes>SetCheck(BF_CHECKED);

, SetCheck 
. , ,

15.2.

143

. 
.
, ,
. 
GetCheck , 
BNClickedMinusYes BNClickedMinusNo :
if ( minusyes>GetCheck() == BF_CHECKED )
checkminus>Show(SW_SHOW);
if ( minusno>GetCheck() == BF_CHECKED )
checkminus>Show(SW_HIDE);

, 
minusyes minusno (Show(SW_SHOW))
(Show(SW_HIDE)) checkminus. 
, ( 
), (. 15.15).

. 15.15

Show 
. , 8 9
, .
, 
, BNClickedMinusYes
:
checkminus>Show(SW_SHOW);

BNClickedMinusNo :
checkminus>Show(SW_HIDE);

, .
, .

(. . 2.3).


16


, 
,
.

Controls
(. . 2.3) , . 16.1.
TListBox. 
, , TListBox, TButton,
TControl.
. 
, 
.
( )
. .
, .
.
2013.ide
2014.exe. ,
2013.exe, 2014.exe . ,
2014app.rc. IDD_CLIENT 
Controls , 
, . 16.2.
, 
. ,
.

16

. 16.1

145

. 16.2

2014.exe, 
: ClassExpert
(. 16.3).

Borland C++, . , .
2014.exe, 
Special Rescan ( (
)) . . 16.4.

. 16.3
ClassExpert

. 16.4 ClassExpert

, ClassExpert . 
(, ) 
IDC_LISTBOX1.
list1 (. 16.5).


146

16

. 16.5

, . ,
SetupWindow. ,
.
void SetupWindow();

2014dlgc.h ( TListBox* list1;), 2014dlgc.cpp


:
void T2014DlgClient::SetupWindow()
{
TDialog::SetupWindow();
list1>AddString("");
list1>AddString("");
list1>AddString("");
list1>AddString("");
list1>AddString("");
list1>AddString("");
}

. 16.6

. 16.7

16

147

2013dlgc.h. 
, , 2014dlgc.h,
2014dlgc.cpp.
SetupWindow , 
AddString.
, , . 16.6.
. , 
, .
, IDC_LISTBOX1
(. 16.7).
Sort , 
.
, 
, ,
.
. 16.6, .
, . , 
. SetupWindow
AddString
list1>SetSelIndex(0);


. , 
, . 
, , 
Sort
, . ,
.
,
( TEdit).
(. . 16.9). 
choice. IDC_LISTBOX1 (.
16.8),
(LBN_SELCHANGE). LBNSelchangeList1.
, 2014dlgc.cpp,
LBNSelchangeList1 :
void T2014DlgClient::LBNSelchangeList1()
{
// INSERT>> Your code here.
list1>GetSelString(str, 256);
choice>SetText(str);
}


148

16

. 16.8

2014dlgc.h protected str:


char str[256];

. (. 16.9). 
, 
, . , 
SetupWindow:
list1>GetSelString(str, 256);
choice>SetText(str);

. , .
. ,
, .. 
, 
. , 
.
. , 
.
( ,
). telephone.txt,
2014.exe (. 16.10).
: ,
; .
, . 
, 
.
, . ,
,
list1.
2014dlgc.h ,
#include:
#include <stdio.h>

16

. 16.9

149

. 16.10

protected:
FILE* base;

SetupWindow 2014dlgc.cpp
( ):
void T2014DlgClient::SetupWindow()
{
TDialog::SetupWindow();
if ( (base = fopen("telephone.txt", "r")) != NULL)
{
char strone[100]; int istr;
while ( fgets(strone, 100, base) != NULL)
{
istr = 0;
while ( strone[istr] != 32 ) istr++;
strone[istr] = "\0";
list1>AddString(strone);
}
fclose(base);
list1>SetSelIndex(0);
list1>GetSelString(str, 256);
choice>SetText(str);
}
else
{
MessageBox(" !", "", MB_ICONSTOP);
}
}

, ,
. ,
. 2014dlgc.h
base:
FILE* base;


150

16

,
. SetupWindow
:
if ( (base = fopen("telephone.txt", "r")) != NULL)

telephone.txt (r), 
, .
fopen NULL, 
,
SetupWindow:
else
{
MessageBox(" !", "", MB_ICONSTOP);
}


. , ,
.
, 
if:
char strone[100]; int istr;

, 
.
while ( fgets(strone, 100, base) != NULL)


15 while. fgets
base strone.
100 , , 100
.  ,
, .
fgets, ( )
base .
, fgets ,
NULL. (while) NULL
(!= NULL), strone ,
, .
NULL, .
, ,
strone. strone ,
. , 
, strone:
istr = 0;
while ( strone[istr] != 32 ) istr++;

16

151

strone,
. (while) istr 
(32 ), istr
(istr++) . , (
) ,
if, while for , 
.
, ,
:
while ( strone[istr] != ) istr++;

32 (
).
, ,
. istr 
strone.
strone[istr] = \0;

, . strone 
\0.
strone .
AddString,
strone.
list1>AddString(strone);

AddString strone
list1.
while , 
. , , 
. :
fclose(base);
list1>SetSelIndex(0);
list1>GetSelString(str, 256);
choice>SetText(str);

base, ,
( ).

. , 
, .
SetupWindow,
LBNSelchangeList1(). :
void T2014DlgClient::LBNSelchangeList1()
{
// INSERT>> Your code here.


152

16

if ( (base = fopen("telephone.txt", "r")) != NULL)


{
list1>GetSelString(str, 256);
char strone[100], *strnumber;
while ( fgets(strone, 100, base) != NULL)
{
if ( strstr(strone, str) != NULL)
{
strnumber = strchr(strone, );
strnumber++;
choice>SetText(strnumber);
}
}
fclose(base);
}
else
{
MessageBox(" !", "", MB_ICONSTOP);
}

, telephone.txt.
, . :
1. SetupWindow 
, LBNSelchangeList1,
, .
2. SetupWindow , 
, , ,
LBNSelchangeList1 . .
? , , 
, SetupWindow 
. telephone.txt ,
. ? , .
, .
, MessageBox,
.
list1>GetSelString(str, 256);

, list1 
str.
char strone[100], *strnumber;

. 
. , , 
(), , 
.
, 
. .

16

153

, 
goto . 
, , : ( ,
) goto . .
, 
. 
, .
, , .
, ,
. ,  
, , ,
( 
). ,
( ).
, 
, . , 
:
FILE* base;

base .
base, , ,
.
strnumber 
. ,
. , ,
: , 
. , Borland ++ 
:
Possible use of "identifier" before definition

, , , :
char *strone

, :
char strone[100]

strone ,
.
fgets(strone, 100, base)

,
base .
, ,
, fgets. , 
, .


154

16

strone . 
, 
strnumber.
while ( fgets(strone, 100, base) != NULL)


base strone .
, , :
( NULL) ,
:
while ( fgets(strone, 100, base) )

. ,
, , C++ ,
( NULL) .
!=NULL:
if ( strstr(strone, str) != NULL)

strstr(strone, str) strone, 


(, 5550403), str, ,
(, ). ,
, strstr NULL. 
while . strone
5559634, strstr
NULL, str strone. 
, , 
. strone.
NULL,
:
strnumber = strchr(strone, );

. ,
strchr , .
strone . ,
. strnumber

" 5559634".

.
, . 
. , strnumber
.
, ( ) .
, ,
, strnumber :
strnumber++;

16

strnumber :

155

"5559634"

.
choice:
choice>SetText(strnumber);

, !
:
fclose(base);

, (. 16.11).

. 16.11

. , 
. , SetupWindow
, .
, . , 
 . , 
. , !


17


, .

c Intel 486

,
. 

, .  
, : 
,

.
,
.
, , . 
, TInputDialog (. . 8.4).
. . 
, , , ,
.
.

 ( )
 ( TInputDialog).
.
,
, , . ,

17

157


, . , 
. ( 
) ,
.
:
2013.ide, 2014.exe, . , 
. ,
New Resource (. 17.1).
Dialog (. 17.2).

. 17.1

. 17.2

(. 17.3).
(
Properties) (. 17.4).
, System Menu (
)
(. 17.5).

. 17.3


158

17

. 17.4

. 17.5

Help, Cancel,
Caption ,
TStatic ( ) TEdit ( ).
, . 17.6.
! .
Properties, General, Edit1 ID (
) IDC_EDIT2, Edit2 IDC_EDIT1. 
, , , IDC_EDIT1
, .
, Borland ++
. 
 . 

: ID IDC_EDIT2
IDC_EDIT3.
, . ,


. 17.6

(. 17.7).

17

159

. 17.7 IDD_DIALOG1

. 
IDD_CLIENT, 

BNClickedAddAbonent.
2014dlgc.cpp
( , ):
TDialog(this, IDD_DIALOG1).Execute();

.

, . ,
,
,  .

. 
, , 
.
.
. 2014dlgc.h
#include (
TTelephoneBuffer):
struct TTelephoneBuffer
{
char name[255];
char number[255];
};

, 
, , . 

. ,
,
FILE* base;


160

17

( base):
TTelephoneBuffer buffer1;

,
buffer1 TTelephoneBuffer.

TDialog. , ,
TDialog:
TDialog(this, IDD_DIALOG1).Execute();

, ( , ,
, ), 
.
14. ,
.
. 2014dlgc.h 
, T2014DlgClient
TDialog. TInputTelephone (
, )
TDialog.
2014dlgc.h :
class TInputTelephone : public TDialog
{
public : TInputTelephone(
TWindow* parent,
TTelephoneBuffer* buffer,
TModule* module = 0);
};

, 
TTelephoneBuffer.
, .
. 
2014dlgc.cpp :
TInputTelephone::TInputTelephone( TWindow* parent,
TTelephoneBuffer * buffer,
TModule* module)
:
TDialog(parent, IDD_DIALOG1, module)
{
new TEdit(this, IDC_EDIT2, 255);
new TEdit(this, IDC_EDIT3, 255);
SetTransferBuffer(buffer);
}

: , ,
IDD_DIALOG1.

17

161

, TEdit, , 
T2014DlgClient:
choice = new TEdit(this, IDC_EDIT1, 255);

TEdit
choice, , 
. ,
, 
(. . 17.7),
, ,
. , (255)
TTelephoneBuffer, 
255.
, . 
, , IDC_EDIT2, ,
IDC_EDIT1,
:
TInputTelephone::TInputTelephone( TWindow* parent,
TTelephoneBuffer * buffer,
TModule* module)
:
TDialog(parent, IDD_DIALOG1, module)
{
new TEdit(this, IDC_EDIT2, 255);
new TEdit(this, IDC_EDIT1, 255);
SetTransferBuffer(buffer);
}

, , , 
, Borland C++, ,
.
. , , .
, () buffer 
.
,
( ,
SetTransferBuffer ..), Borland C++ 

.
BNClickedAddAbonent,
,
.
, (, 
, ):


162

17

void T2014DlgClient::BNClickedAddAbonent()
{
// INSERT>> Your code here.
if (TInputTelephone(this, &buffer1).Execute() == IDOK)
{
if ( ( list1>FindExactString(buffer1.name, 0)) >= 0)
{
MessageBox(" !", "", MB_ICONSTOP);
}
else
{
if ( !strcmp(buffer1.name,"") || !strcmp(buffer1.number,"") )
{
MessageBox(" ",
"", MB_ICONSTOP);
}
else
{
if(strchr(buffer1.name, ) || strchr(buffer1.number, ))
{MessageBox(" ",
"", MB_ICONSTOP);
}
else
{
strcpy(str, buffer1.name);
strncat(str, " ", 2);
strncat(str, buffer1.number, 256);
baseopen:
if ( base = fopen( "telephone.txt", "r+") )
{
fseek(base, 0, 2);
if ( ftell(base) ) fputc(\n, base);
fputs(str, base);
fclose(base);
list1>AddString(buffer1.name);
}
else
{
if (MessageBox(" telephone.txt \n\
?", "",
MB_YESNO | MB_ICONWARNING) == IDYES )
{
base = fopen("telephone.txt", "w");
fclose(base);
goto baseopen;
}
}
}
}
}
}
}

17

163

, 
. .
, ,
, ,
, .
( 
):
if (TInputTelephone(this, &buffer1).Execute() == IDOK)

, , 
TInputTelephone. , 
( &) buffer1. ,
.
Execute(). 
. ,
. , 
IDOK, , ,
if. 
, IDOK, .
IDOK ,
:
if ( ( list1>FindExactString(buffer1.name, 0)) >= 0)

,
buffer1
. name buffer1
, number .
. ; , ,
11. , buffer1.name, buffer1.number.
, 
, list1? 
? ,
Borland C++ ,
. FindExactString list1 , 
( buffer1.name), 
(, ). 
,  .
, 
:
MessageBox(" !", "", MB_ICONSTOP);

.
, else :
if ( !strcmp(buffer1.name, "") || !strcmp(buffer1.number,"") )

! .
strcmp
( "", ,


164

17

). , 
. , , buffer1.name 
, strcmp(buffer1.name, "")
0 ( ), !, 
, . 
.
|| .
!strcmp(buffer1.number, ""), if
, :
MessageBox(" ", "", MB_ICONSTOP);

, else, 
if, :
if ( strchr(buffer1.name, ) || strchr(buffer1.number, ) )

strchr . , strchr(buffer1.name, )
buffer1.name .
, , 
. (|| ) strchr 
, , NULL, ( 
true ),
if :
MessageBox( " ",
"", MB_ICONSTOP);

, ,  .
,
:
strcpy(str, buffer1.name);
strncat(str, " ", 2);
strncat(str, buffer1.number, 256);

str buffer1.name.
str " ",
.
buffer1.number.
, . 
:
if ( base = fopen( "telephone.txt", "r+") )

baseopen: , ,
, .
telephone.txt (r+).
NULL, if , 
else, if. if:

17
if (MessageBox( " telephone.txt \n\
?", "", MB_YESNO | MB_ICONWARNING) == IDYES )

165

, telephone.txt
, . , , 
, . , ,
, , .
, MessageBox IDYES,
.
,
( w), 
goto , baseopen, .
base = fopen("telephone.txt", "w");
fclose(base);
goto baseopen;

, .
, :
fseek(base, 0, 2);

( fseek
).
if ( ftell(base) )

fputc(\n, base);

,
, ,
\n. ,
, , .
ftell(base) ,
, ,
.
, , 
.
( ) , 
:
fputs(str, base);
fclose(base);

.
, :
list1>AddString(buffer1.name);

. 
? .
. , ,
, . 
Enter, 
. 
( ), . 17.8.


166

17

. 17.8 !

\n, .
, , 
.
. SetupWindow
, , 
( \n) :
istr = 0;
while ( strone[istr] != 32 ) istr++;
strone[istr] = \0;
list1>AddString(strone);

:
if ( strcmp(strone, "\n") )
{
istr = 0;
while ( strone[istr] != 32 ) istr++;
strone[istr] = \0;
list1>AddString(strone);
}

strcmp , , 
.
.
, , .
LBNSelchangeList1
strnumber = strchr(strone, );

,
:
if ( strnumber = strchr(strone, \n)) strcpy(strnumber, "");

strone, , 
\n \0.
,
, , ,

17

167

.
, 
. .
LBNSelchangeList1
list1>GetSelString(str, 256);

,
:
strncat(str, " ", 2);

,
: , .
? , SetupWindow
, ,
list1>GetSelString(str, 256);
choice>SetText(str);

( , ):
LBNSelchangeList1();

: ,
. ,
2.4, , 
. 

(. . 17.4 17.5),
Window
Center Dialog (. 17.9).
, 

.

,
Center Dialog , 
. , 

, .

TDecoratedFrame, 
( 
),
.
, 
 ,
, . 17.9


168

17

, 
, . ? , ,
: 2014app.cpp
frame>Attr.Style &= ~(WS_CHILD | WS_MAXIMIZEBOX | WS_THICKFRAME);

:
RECT desktop;
GetWindowRect(GetDesktopWindow(), &desktop);
frame>Attr.X = ( desktop.right 300 ) / 2;
frame>Attr.Y = ( desktop.bottom 160 ) / 2;

desktop RECT (
).
GetDesktopWindow()
Windows*, GetWindowRect
desktop. , 
, 
( desktop.right desktop.bottom)
(300 160).
,
.

* , Windows. 
, Windows , 
. . . .


18

:
...
...

7 , 
.
( 7),
, .
avi
bmp ,
.
. , 
,  
bmp. 
,
, (. . 18.5).

18.1. /
, , 6.
,
2006.exe .
2006.ide, 
: . 
, .
: IDC_CHECKBOX1


170

18

showbmp (. 18.1), ( BN_CLICKED)


BNClickedShowBmp(), IDC_STATICBITMAP1,
, staticbmp1.

. 18.1

BNClickedShowBmp() :
if ( showbmp>GetCheck() ) staticbmp1>Show(SW_HIDE);
else staticbmp1>Show(SW_SHOW);

BNClickedShowBmp() . 
if
GetCheck(). , ,
Show(SW_HIDE). 
, else 
Show(SW_SHOW) .
, . 18.2 18.3.
,
( )
 
. , 
.
, ( ,
), .

18.2.
, 
, . 
( ) :

18.2.

171

. 18.2 ...

. 18.3 ...

, ,
.bmp (,
.bmp);
90120 ;
,
( telephone.txt);
bmp 256 .

, .


172

18

2013.ide, 2014.exe. ,
7, ().
, , Classes 
T2014DlgClient, Windows
Messages, Basic Messages. WM_PAINT ,
, Add handler (. 18.4).

. 18.4 ,

2014dlgc.cpp
EvPaint() ( 7). WM_PAINT,
. 
, 
 .
EvPaint(),
LBNSelchangeList1, 
. ,
bmp EvPaint().
fclose(base);

( , )
:

18.2.
strnumber = strchr(str, " ");
strcpy(strnumber, ".bmp");
Invalidate();

173

. , str
, 
LBNSelchangeList1 , str
" " ( ).
. 
, , 
. , ,
strnumber.
, ,
".bmp", str .bmp.
Invalidate(), , , 
EvPaint().
EvPaint() 
:
void T2014DlgClient::EvPaint()
{
TDialog::EvPaint();
// INSERT>> Your code here.
TDC* dc = new TClientDC(*this);
TMemoryDC memDC(*dc);
TBitmap* fotobmp;
TDib fotodib = TDib(1, 1, 256);
if ( fotodib.LoadFile(str) )
{
fotobmp = new TBitmap(fotodib);
memDC.SelectObject(*fotobmp);
dc>BitBlt(200, 0, 90, 120, memDC, 0, 0, SRCCOPY);
}
else
{
dc>TextOut( 200, 50, " ");
}
}

, dc,
(this):
TDC*

dc = new TClientDC(*this);

7 .

memDC:
TMemoryDC memDC(*dc);


, , , 
.


174

18

, , 
. 7. ,

. 
? .
, .
, .
fotobmp TBitmap,
fotodib TDib:
TBitmap* fotobmp;
TDib fotodib = TDib(1, 1, 256);

, 
, ,
bmp . TDib. 1 1
, 256 .
.
if ( fotodib.LoadFile(str) )

LoadFile
fotodib , str. 
, LoadFile true
.
:
fotobmp = new TBitmap(fotodib);

fotobmp.
memDC.SelectObject(*fotobmp);

,
:
dc>BitBlt(200, 0, 90, 120, memDC, 0, 0, SRCCOPY);

BitBlt memDC
dc. , 
: 200, 0 
, 90, 120 , .
, .
. LoadFile 
fotodib , else.
:
dc>TextOut( 200, 50, " ");

TextOut : 200, 50 
, .
. 18.5 18.6 , .

18.3.

175

. 18.5

. 18.6

,
.

18.3.
,
 . 
, .
, 
. 
BNClickedDeleteAbonent(), . 
:
void T2014DlgClient::BNClickedDeleteAbonent()
{
// INSERT>> Your code here.
if ( !rename( "telephone.txt", "telephone.old") )
{
FILE* basetemp = fopen( "telephone.old", "r");
base = fopen( "telephone.txt", "w");
list1>GetSelString(str, 256);


176

18
strncat(str, " ", 2);
char strone[100];
while ( fgets(strone, 100, basetemp) )
{
if ( !strstr(strone, str) ) fputs(strone, base);
}
fclose(base);
fclose(basetemp);
remove("telephone.old");
list1>DeleteString( list1>GetSelIndex() );

}
else
{
MessageBox(" ",
"", MB_ICONSTOP);
}
}

, , , .
: 
, 
, .
.
if ( !rename( "telephone.txt", "telephone.old") )

telephone.txt telephone.old.
, ,
:
telephone.txt  , 
, telephone.old .
else 
.
,
:
FILE* basetemp = fopen( "telephone.old", "r");

, basetemp. 
,
, , 
. , ,
.
base = fopen( "telephone.txt", "w");

base.
, 
.
list1>GetSelString(str, 256);
strncat(str, " ", 2);

18.3.

177

str
( 
).
char strone[100];
while ( fgets(strone, 100, basetemp) )

strone
basetemp.
if ( !strstr(strone, str) ) fputs(strone, base);

strone
, base. 
, , :
fclose(base);
fclose(basetemp);
remove("telephone.old");

, , Windows.
list1>DeleteString( list1>GetSelIndex() );

. GetSelIndex
,
DeleteString.
, . 18.7. 

.

. 18.7

? , 
. About,
, ..
. , ,
. ? ! .


19


:
,
, .

, 
, ,  .
, , ,
6. 
.

19.1.
. 
,
, . 
. ,
,
telephone.txt. ,
, .
,
, 
, .
,
BNClickedOpenBase.

19.1.

179

, 
Windows. 
, Borland ++ TOpenSaveDialog,

. TOpenSaveDialog 
.
.
SetupWindow 15 , 
. 
. , BNClickedOpenBase
? , 
, 
. , , 
.

. 2014dlgc.h
void BNClickedOpenBase();

:
void LoadBase(char* filename);

, , 
. , .
. . 
2014dlgc.cpp :
void T2014DlgClient::LoadBase( char* filename )
{
if ( (base = fopen(filename, "r")) != NULL)
{
list1>ClearList();
char strone[100]; int istr;
( fgets(strone, 100, base) != NULL)
{
if ( strcmp(strone, "\n") )
{
istr = 0;
while ( strone[istr] != " " ) istr++;
strone[istr] = "\0";
list1>AddString(strone);
}
}
fclose(base);
list1>SetSelIndex(0);
LBNSelchangeList1();
}
else
{
MessageBox(" !", "", MB_ICONSTOP);
}
}


180

19

:
SetupWindow. , 
telphone.txt filename. 
, , 
.
.
list1>ClearList();

, 
. SetupWindow :
void T2014DlgClient::SetupWindow()
{
TDialog::SetupWindow();
LoadBase("telephone.txt");
}

,
. LoadBase telephone.txt.
, ,
.
BNClickedOpenBase. 
:
void T2014DlgClient::BNClickedOpenBase()
{
// INSERT>> Your code here.
TFileOpenDialog::TData FilenameData;
FilenameData.SetFilter(" telephone.txt|telephone.txt");
if (TFileOpenDialog(this, FilenameData).Execute() == IDOK)
{
LoadBase(FilenameData.FileName);
}
}

FilenameData.
.
,
, ,
.
FilenameData
, :
FilenameData.SetFilter(" telephone.txt|telephone.txt");

, , , 
.
telephone.txt. :
, , , 
txt, :
FilenameData.SetFilter(" (*.txt)|*.txt");

19.2.

181

,
, (*.txt).
, .
, (
), :
" telephone.txt|telephone.txt| (*.txt)|*.txt"

.
:
if (TFileOpenDialog(this, FilenameData).Execute() == IDOK)

17.
.
,
FilenameData . 
, FileName , 
, FilenameData.FileName (
) LoadBase:
LoadBase(FilenameData.FileName);

:
. 
. , 

base = fopen( "telephone.txt", "r+"),

, .
fotodib.LoadFile(str) 
.

19.2.
? ( 
, ).
. , 
. 2014app.cpp
:
T2014App::T2014App() : TApplication("2014")

2014. , 
, :
T2014App::T2014App() : TApplication(" ")

. 19.2. ,
.


182

19

Borland C++ . .
(
).
. , 
(. . 6.1) ,
6, Add to project. 
ico (. . 6.2). . 
face01.ico Borland. :
C:\BC5\EXAMPLES\MFC\ADVANCED\SPEAKN\RES

() ,
ICON (. 19.1).

. 19.1


. IDI_ICON1 2014app.cpp,
. , Icon.
:
frame>SetIcon(this, IDI_SDIAPPLICATION);
frame>SetIconSm(this, IDI_SDIAPPLICATION);

.
IDI_SDIAPPLICATION (. . 19.1).
:
:
frame>SetIcon(this, IDI_ICON1);
frame>SetIconSm(this, IDI_ICON1);

. , . 19.2.
, , 
Windows (. 19.3).
( ) 
(. 19.4).
, . , , 
, , , ,

19.3.

. 19.2

183

. 19.3 !

. 19.4

. , 
. Borland C++ .

19.3.
, , , 
, . 
, .

(. . 6.1), New Resource. , 
(. 19.5).
ICON, .
Options, (. 19.6).
, ,
. 19.6. ,
Borland ++ .
Source ;
, Browse
, . , .
. Colors ,
. 
(colors = 2) , 16 256?
256; , 16.
Size .


184

19

. 19.5

. 19.6

3232 (. . 19.3). 6464? , 


, 3232.
Options New Resourse. 
Borland C++. 
, . 
256 . 
.
,
( , 
)
Show (. 19.7).
.
. 19.7

. 

,
, , , 
.
,
.

19.3.

185

,
, . 19.8.

. 19.8

, ,
(. 19.9).
, 2014app.cpp.
:
frame>SetIcon(this, IDI_ICON2);
frame>SetIconSm(this, IDI_ICON2);

. , ,
, , .

. 19.9


186

19

, ..,
. ,  
, ,

Cut (. 19.10).

. 19.10

. ,
,
2014.exe. , 
.
Make, Run Build
2014.exe. . (),

. 19.11

19.3.

187

. Edit
node attributes (. 19.11).
, Name .
 , , . 19.12.

. 19.12

. .

, , .
(),
,
. 19.13.

. 19.13

Borland C++ Rescan,


. , 
, 2014.apx
telephone.apx .
(. . 19.12) ,
.


20

. 
.

, Borland
C++. .  ,
( ) .
. 
, , 
.
.
: ,
. 
, 
.
Borland C++.
, , New Resource.
, . 19.5. Bitmap ,
, Options. 
(. 20.1).
. ,
, . 20.4. 1818.
. 
, .
Bitmap, . ,
, , 
(. 20.2).
, .

20

189

. 20.1

, (. 20.3).
, 
IDB_BITMAP1.
. , ,
, .
IDD_CLIENT, 
, , . 
, 6 
Caption Interpret
Caption As Number (. . 6.4). 
. , ?
, . 6.4.
. 
PushButton Button Image ( ) ,
. Text Bitmap. Bitmap. 
.
 , . 
: Caption
, , Button Image Text.


190

20

. 20.2

. 20.3

addabonent. 
:
TButton* addabonent; 2014dlgc.h,
addabonent = new TButton(this, IDC_BUTTON1); 2014dlgc.cpp.

.
, , TButton,
. TGlyphButton
TButton. 
, . 
TButton ,
.
, TButton TGlyphButton:
TGlyphButton* addabonent;
2014dlgc.h,
addabonent = new TGlyphButton(this, IDC_BUTTON1); 2014dlgc.cpp.

, 2014dlgc.h
#include , :
#include <owl/glyphbtn.h>

, , , ,
, . , .

addabonent = new TGlyphButton(this, IDC_BUTTON1);

2014dlgc.cpp , :
addabonent>SetGlyph(new TBtnBitmap(*GetApplication(),
IDB_BITMAP1));

20

191

. 20.4

IDB_BITMAP1 TBtnBitmap (
),
SetGlyph addabonent.
, , . 
! ,
IDB_BITMAP2, delabonent,
, :
2014dlgc.h:
TGlyphButton* delabonent;

2014dlgc.cpp:
delabonent = new TGlyphButton(this, IDC_BUTTON2);
delabonent>SetGlyph(new TBtnBitmap(*GetApplication(), IDB_BITMAP2));

(. 20.4).

: ,
. ( Caption
) , .
, 
. , , 
, .


21

:
DEL *.* .

.
 
. , , , , 
, ,
?
, ( 
Ctrl+Alt+Del),
,  (process). 

(Notepad Windows), , 
, . ,
,
.
, , , . ,
2021.ide.
( ), 
BNClickedKillNotepad. :
void T2021DlgClient::BNClickedKillNotepad()
{
// INSERT>> Your code here.
HANDLE SnapsProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 ProcessList;

21
ProcessList.dwSize = sizeof( PROCESSENTRY32 );
Process32First( SnapsProcess, &ProcessList );
next:
CharUpper( ProcessList.szExeFile );
if( strstr( ProcessList.szExeFile, "NOTEPAD" ) )
{
HANDLE opPr = OpenProcess( PROCESS_ALL_ACCESS, FALSE,
ProcessList.th32ProcessID );
TerminateProcess( opPr, 0 );
CloseHandle( opPr );
}
if ( Process32Next( SnapsProcess, &ProcessList ) ) goto next;
CloseHandle( SnapsProcess );

193

, , :
#include <tlhelp32.h>

. . 
. .
, , , 
. 
, . , 
Borland C++
, . , Windows ,
, Borland C++,
. ,
:
C:\BC5\HELP\95guide.hlp

, , Borland C++ 
. Borland C++,
, . , , 
, .
HANDLE SnapsProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

.
, , . HANDLE .
, ,
HANDLE void*, .
,
, (, CreateToolhelp32Snapshot) 
HANDLE, , 
.  (,
Process32First) ,
.
, CreateToolhelp32Snapshot (snapshot) 
. screenshot.


194

21

,
. . 
TH32CS_SNAPPROCESS ,
. 
. , , 
() SnapsProcess.
PROCESSENTRY32 ProcessList;
ProcessList.dwSize = sizeof( PROCESSENTRY32 );

ProcessList PROCESSENTRY32.
 
. 
dwSize sizeof,
.
Process32First(SnapsProcess, &ProcessList);

Process32First Process32Next 
, SnapsProcess
(first) Process32First (next) Process32Next 
ProcessList. 
Process32First, Process32Next.
CharUpper( ProcessList.szExeFile );

. ,
, .
, szExeFile
ProcessList,
CharUpper. 
.
if( strstr( ProcessList.szExeFile, "NOTEPAD" ) )

strstr 
, exe "NOTEPAD".
, 100 , . 
,  , ,
, C:\ \notepads\super.exe.
, super.exe 

.
, ,
:
HANDLE opPr = OpenProcess( PROCESS_ALL_ACCESS, FALSE,
ProcessList.th32ProcessID );

21

195

, 
opPr. 
PROCESS_ALL_ACCESS. , :
TerminateProcess(

opPr, 0 );

, 
. , 
, . 
CloseHandle( opPr );

:
if ( Process32Next( SnapsProcess, &ProcessList ) ) goto next;

. , 
ProcessList, 
next, .
, .
, , .
,
,
, . , , 
, .
, , 
.
, .


22

,
!

Controls Standard
, ,
TComboBox. . 22.1.
TListBox,
, 
. ? .
, Standard . 

; Group Box,
,
; 
Static Rectangle (
)  
. 22.1
. 22.2

Common.

 . , ,
avi. , 
Progress Bar. Track Bar (. 22.2) 
. 
TSlider. Track Bar ,

22.1.

197

. Borland C++
, TComboBox, .

22.1.
2007.ide. , 
. , 
. . 
(. . 22.2)
. 
, 
. 

,
Orientation
Horizontal () Vertical
() . . 22.3.
Location
. . 22.3 Both.
, Top Height
Apply
(. 22.4), , 
,
(. 22.5).

vbar.
.
, ,

. 22.3
.
? ,
: SetupWindow. 
,  
. ,
, ,
, , 
. ,
, 
SetupWindow, 14 . 
.
, 14, SetupWindow, 
2007dlgc.h:


198

22

void SetupWindow();

2007dlgc.cpp. SetupWindow()
:
void T2007DlgClient::SetupWindow()
{
TDialog::SetupWindow();
vbar>SetRange(0, 200);
vbar>SetRuler(5, false);
vbar>SetPosition(100);
}

.
,
.

. 22.4

. 22.5

. SetRange 
: 0, 
200. ,
SetRange(0, 1) 
.
, , SetRange(100, 100). SetRange(200, 0)
, .
SetRuler . 
, , , false true
, .
SetPosition . 
.
, 0,2 
, , 
.
, .

22.1.

199

prevpos curpos. 
. ,
14.
, 2007dlgc.h ( ) 
:
int prevpos, curpos;
void EvTimer(uint timerId);

2007dlgc.cpp :
(. 14):
EV_WM_TIMER,

SetupWindow():
prevpos = 100;
curpos = 100;
SetTimer(NULL, 200);

, :
void T2007DlgClient::EvTimer( uint )
{
curpos = vbar>GetPosition();
if ( curpos != prevpos ) Invalidate();
prevpos = curpos;
}

EvTimer.
curpos = vbar>GetPosition();

GetPosition() 
, curpos.
if ( curpos != prevpos ) Invalidate();

(curpos)
(prevpos), , 
Invalidate().
prevpos = curpos;


0,2 .
, 
EvPaint, 
. , ,
. ,

y = 90 (sin ( (x158)*6.28/298 ))*81;


200

22

y = 90 (sin ( (x158)*6.28/298 ))*0.81*(100curpos);

. 
(. 22.6).
.

. 22.6

, ,
EvTimer,
if ( curpos != prevpos ) Invalidate();

:
if ( (curpos prevpos) && sinus_on ) Invalidate();

, 
, , .
:
void T2007DlgClient::EvTimer( uint )
{
curpos = vbar>GetPosition();
if ( (curpos prevpos) && sinus_on && (GetKeyState(1)>=0) )
{
Invalidate();
prevpos = curpos;
}
}

, . 
.

22.2.
, , Controls
Common. 2007.exe.

22.2.

. 22.7

TUpDown

201

. 22.8

, Up
Down, (. 22.7).

,  ,
.
, .
.
, .
( ,
, IDC_UPDOWN1) updown, 
UDN_DELTAPOS 
UDNDeltaposUpdown.
TUpDown  TSlider. 
, SetRange SetPosition 
SetPos. SetupWindow,
:
updown>SetRange(0, 200);
updown>SetPos(100);

updown ,

. ,
updown:
bool T2007DlgClient::UDNDeltaposUpdown(TNmUpDown& udn)
{
// INSERT>> Your code here.
int pos = udn.iPos + udn.iDelta;
vbar>SetPosition(200pos);
}

udn,
UDNDeltaposUpdown updown,


202

22

.
pos. 
, pos. 
, :
vbar>SetPosition(pos);

, , (200pos).
EvTimer 
.
, .
, TEdit, 
. TEdit,
updown.
, 
, 
TEdit.
, (. 22.9).

. 22.9

Readonly TEdit.
IDC_EDIT1. updown
() , . 22.10.
Right Set Buddy Int.
2007dlgc.cpp.
SetupWindow
updown>SetRange(0, 200);

:
updown>SetBuddy(GetDlgItem(IDC_EDIT1));

22.2.

203

. 22.10

. Buddy .
, updown , IDC_EDIT1 
. . . 22.11 ,
.

. 22.11

, , 
. SetBuddy 
,


204

22

. Right ,
(. . 22.10).
Set Buddy Int. , 
.
, 
. .


23

,
.
! .
! ! !.. .
! .
Echo is ON, .


, . 
, , 
, . 
, .
2006.exe, 
AVI. ,
, ,
AVI. Cancel .
, 
Controls Common , 
. 23.1. 
, ,
. 23.1
. 23.2. 
, Set Creation Order (.

. 15.7), . TTabControl

6 . avione,
showbmp staticbmp1 (. 23.3).


206

23

. 23.2

. 23.3

IDC_TABCONTROL1
TCN_SELCHANGE ( ). 
 ( Add handler)
TCNSelchangeMytabcontrol.
.
TTabControl TListBox,
. , , 
, (, 
).
.
,
SetupWindow. . 2006dlgc.h :
void SetupWindow();

2006dlgc.cpp ,
SetupWindow:
void T2006DlgClient::SetupWindow()
{
TDialog::SetupWindow();
mytabcontrol>Add("");
mytabcontrol>Add("AVI");
mytabcontrol>SetSel(0);

23
TNotify tcn;
TCNSelchangeMytabcontrol(tcn);

207

, . Add
AddString.
. , .
SetSel , 
. ,
, . 
0, AVI 1.
TCNSelchangeMytabcontrol,
.
,
SetSel  TCNSelchangeMytabcontrol
, .
tcn , 
, .
TCNSelchangeMytabcontrol. ,
, . 2006.exe
, 
, .
, :
void T2006DlgClient::TCNSelchangeMytabcontrol(TNotify& tcn)
{
// INSERT>> Your code here.
switch (mytabcontrol>GetSel())
{
case 0:
showbmp>Show(SW_SHOW);
staticbmp1>Show(SW_SHOW);
avione>Show(SW_HIDE);
buttonplay>Show(SW_HIDE);
buttonstop>Show(SW_HIDE);
break;
case 1:
showbmp>Show(SW_HIDE);
staticbmp1>Show(SW_HIDE);
avione>Show(SW_SHOW);
buttonplay>Show(SW_SHOW);
buttonstop>Show(SW_SHOW);
break;
}
}

switch. switch
GetSel .
.


208

23

. 23.4

0, case 0: 
break. 1, case 1: 
break. : Show(SW_SHOW)
, Show(SW_HIDE) .
. . 23.4.
, .
, .
, , .
, Show(SW_SHOW)
TCNSelchangeMytabcontrol . 

staticbmp1>Show(SW_SHOW);

:
BNClickedShowBmp();

, .
, .
? , 
(. 23.5).
,
. , .
, , . 23.6.

Multi Line .

23

. 23.5

209

. 23.6

, .
, , 
, bmp 
.


24

,
, .
:
.
,
.
:

. , , 
, 
.
( ):
, , ,
?

 ,
telephone.exe. 4050 .
, 
, . 
, ... ,
. .
2013.ide, telephone.exe, 
TargetExpert (. 24.1).
Dynamic Static.
Dynamic , 
,

24

211

. 24.1

. ,
, . 
, ,
.
. , 
, , Borland C++
InstallShield Express 
. ,
.

, . exe 
. .
. 24.1. Static , 
exe. , , 
( 320 ), .
? , , , 
.
, , ,
Static. Borland C++
. ,
telephone.exe. 
, , Edit node attributes. 
, . 24.2.
Style Sheet. 
,
.


212

24

. 24.2 telephone.exe

, , ,
.
, 
. ,
. , ,
, Internet, , 

, .
, , 
, 
.

II

Borland C++ Builder 5

25 C++ Builder
26
27 C++ Builder
28
29
30
31
32
33


25


C++ Builder



, 
.

, Borland C++ 5.
, ++ Builder. 
, ,
Borland ++,
, ++ Builder, Borland ++.
++ Builder, 
. , , , C++ Builder 5. 
, Professional Enterprise
. ++ Builder 
( Full ), .
, Borland C++ C++ Builder 
. ,
cpp, .

25.1. !
Builder. ( 
), , . 25.1.
, .
, Form1 !

25.1. !

215

. 25.1 C++ Builder

? .
, .
, , ++ Builder .
, . 
Project 1 (1) .
(. 25.2).
C++ Builder , 
(. 25.3).
( ),
.
. 25.3 Create New Folder ( . 25.2
). C++ Buider 

Projects () , 
Projects. ,
, 1, ( )
. , (. 25.4).
, . 
Unit1.cpp,
Project1.bpr. , ++
Builder . ,
.
. 
1 ,
. , , exe .


216

25 C++ Builder

. 25.3

. 25.4

: , 
. 25.5.
Run (). C++ Builder 
, , . 25.6.
. 
. 25.6 Compiling.

( obj), 
.
. . 25.6 , 
Linking, Compiling.

25.1. !

. 25.5

217

. 25.6


, .
, , , , 
. , .
: , , ,
. 
,
. , ++ Builder
Form1 ( . 25.1 
), . 
(. 25.7).
, Borland ++ ,
, ++ Builder ,
,

. 25.7

 , Builder
, . 
, , 
, .
Builder ,
(. 25.8).
Form1 
. ? :
, 
; , 
; , 
. , , Windows,
, .


218

25 C++ Builder

. 25.8

, .
, Project1.exe. 
, ++ Builder Running (
) . . 25.8. , Run 
++ Builder ++ Builder
, , 
. exe ,
, .
, ++ Builder .

25.2.
. , 
.
. ++ Builder (. . 25.1).
++ Builder 
Object Inspector ( ). , ,
++ , 
.
.
, 
. (, , , 
, .) Form1,

25.2.

219

, 
. .
, 
Form1 (. 25.9).
.
Properties () . . 25.9.
, .
Caption () . . 25.10.
++ Builder ,
.
Caption,
. ,
Form1
(. 25.11).
. 25.11 ,
1.
Caption, , . 
, Run.
 ( ),
, .
:
.
, . 
BorderStyle ( )
Caption . . 25.11. .
bsSizeable,
. bsSizeable 
. ,
BorderStyle (. 25.12).

. 25.9
Form1

. 25.10

. 25.11


220

25 C++ Builder

bsDialog, , .
Run .
, ,
. , ,
. .
bsDialog,
bsSingle (. . 25.12). Run. , 
, .
.
Properties
BorderIcons ( ).
() . . 25.13.

. 25.12
BorderStyle

. 25.13

. 25.14

, (
) 
. bsMaximize, ,
true. true
false. true , false . 
true, , false
. , , .
false, . , Form1
++ Builder
, .
, : 
, ,
++ Builder. ,
.
, , , 
.
? Run , 
Form1 Builder. ,
. Form1
( , ) Position (
). (. 25.14).

25.3.

221

poDesigned. ,
( Form1) , 
. poScreenCenter, 
.

25.3.
. 
Windows , 
. , 
,
.
, .
, , ,
 , 
.
, ++
Builder. . 
++ Builder,
. ++ Builder .
, . ++ Builder, ,
.
, . ,
++ Builder, , .
(. 25.15)
. , ++ Builder
( bpr),
. 
bpr. .
,  . 25.15

, 
. ,

C++ Builder Project ( ++ Builder), bpr.


File Open Project (
). ,
Ctrl+F11.
, ++ Builder 
. ,
++ Builder . ++
Builder .
Tools Environment Options ( ). 
,  (. 25.16).


222

25 C++ Builder

. 25.16 ++ Builder

Project Desktop ( 
) Autosave options ( ) . . 25.16.
, C++ Builder, 
, .
, .
. , Beep on com
pletion ( ). , 
, . ++
Builder .
. 25.16. Borland
++. , Borland ++ .

25.4. VCL OWL,


Borland ++
, , ,
: Borland ++ TForm? .
.

25.4. VCL OWL, Borland ++

223

, ,
. , .
++ Builder .
, , .. ,
++ Builder (Borland ++) .
,
, , Form1, , .
Borland ++ ++ Builder ,
Borland ++ ++ Builder ,
. Borland ++
OWL Object Windows Library ( Windows),
++ Builder VCL Visual Components Library (
). (),
Windows. , 
, ,
.
. 
,
. , VCL
TForm; Form1.
. , TForm 
Caption ( ), Form1
1. TForm ,
TForm ; 
.
,
.
.
TForm Borland ++ , .
, OWL,
. , ++ Microsoft
MFC, VCL OWL.
VCL OWL TButton, 
( Microsoft CButton). 
.
Borland ++. , ,
, Borland ++ 
, . 
, (ClassExpert). 
.
Compile, Make Build ,
.
.


26


.
.

26.1.
 ? , ,
. ,
?
C . Project1. 
(. 26.1). 
Component Palette ( ).
, View Toolbars ( 
) Component Palette.
VCL (. 
25.4). , Standard () 
Servers (). , 
++ Builder,
Enterprise.
, 
. Standard , 
, Form1.
* Form1

* ,
. C++ Builder , 
. . . .

26.1.

225

. 26.1

Button1.
, (. 26.2).
Button1
TButton. .
,
Caption. Caption
. Run. 
, (. 26.3). ,
( 25.2).

. 26.2

. 26.3

. , ,
. .
,  .

26.2. !
++ Builder ,
. 26.2. . 
, (. 26.4).
,
.
++ Builder ,
. 
, 
. Button1Click Button1 
, , Click (, ).


226

26

. 26.4

, , .
. 26.4 .
, , ,
 . ,
Beep. , :
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Beep();
}

. ,
++ . ,
, . 
, . 
, , .
, , 
, ,
/ ( )
(. . 26.5).

. 26.5

Code Insight ( ), 
. C++, VCL
. ,
C++ Builder .
, 
.

26.2. !

227

,
No parameters expected (. 26.5). ,
. ,
 , , 
.
, , ,
.
Run, 
, .
Windows, , , 
. Beep.
++ Buider. Button1Click
Beep :
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Beep();
MessageBox(NULL, "!", "", MB_OK);
}

. 
, 
. , ++ Builder MB_OK,
. 
, (. 26.6).

. 26.6

, . 
Run. ,
, , 
.

(. 26.7).
MessageBox. 
, , , MessageBox, Beep
,  , .
, 
. , 
.


228

26

, MessageBox ,
(. 26.6). .
, 
, !.
, ,
MessageBox(NULL, " !", "", MB_OK);

(. 26.8).

, .. 2.2 2.3 
,
MessageBox ( Borland ++ ).
++ Builder, , 
. ( 
), :
MessageBox(NULL, " !", "", MB_TOPMOST | MB_ICONSTOP );

MB_TOPMOST (
, ),
MB_ICONSTOP MessageBox (. 26.9).

. 26.7

. 26.8

. 26.9

, MessageBox.
handle (, 
).  , , 
.
, , ,

. 
, . ,
. , Windows 95 16384 .
, 
, .

26.3.

229

, 
. 
, , NULL. 
MessageBox,
. ,
(owner) MessageBox. NULL ,
. 
. Windows handle (). 
Windows. ,
.
MessageBox , 
. . 
:
MessageBox(Form1>Handle, " !", "",
MB_TOPMOST | MB_ICONSTOP );

C++ Builder ,
.
Form1>Handle ()
Form1. . 
, , , , .

26.3.
? ,
.
, , .
, 
C++ Builder. , , Beep beep. 
Run. ,
C++ Builder ,
. (. 26.10).

. 26.10


230

26

? , ,
C++ Error ( C++),
. . , 
, (Unit1.cpp) (20) . 
, Call to undefined function
beep ( beep). , 
, beep.
.
, , . 
. , beep,
, .
C++ Builder
. , .
Beep.
Run. C++ Builder , 
(. 26.11).

. 26.11

, C++ Builder .
. (21). ,
, 21, , ,
. ,
C++ Builder. , 
, .
21 :
Beep()
;MessageBox(Form1>Handle, " !", "", MB_TOPMOST |
MB_ICONSTOP );

, .
Run !
C++ Builder. .
. 
Run .

26.3.

231

, .
.
.
B MessageBox b.
, . 26.12.

. 26.12

! C++ Builder , 
.
, C++ Builder.
. , :
MessageBox (. 26.13).

. 26.13

: Too few parameters (


). , , ,
, .
4,
. , , 
. 
MessageBox ( ). 
. ,
:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if ( (MessageBox(Form1>Handle, " \n !",


232

26
" ", MB_YESNO | MB_ICONINFORMATION) ) == IDYES)

{
MessageBox(Form1>Handle, " \n YES/",
" ", MB_ | MB_ICONWARNING);
}
else
{
MessageBox(Form1>Handle, " \n NO/",
" ", MB_ | MB_ICONSTOP);
}
}

, 4. ,
, .

26.4. MessageBox
, ,
, , Borland C++ , , 
MessageBox . 
, C++ Builder MessageBox. 
Button1Click
:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Application>MessageBox(" !", "",
MB_TOPMOST | MB_ICONSTOP);
}

. , 
MessageBox.
. , , MessageBox
() .
MessageBox Windows API. 
API Application Programming Interface, 
. , 
VCL OWL Borland ,
Windows. Windows
, 
, C++ Builder (Borland C++).
C++ Builder MessageBox ( ), C++
Builder MessageBox
Windows API. Application>MessageBox, C++
Builder MessageBox,
TApplication. , ,
MessageBox

26.4. MessageBox

233

 ( )
MessageBox Windows API.
C++ Builder
Windows API. . 26.14 ,
. 26.15 .
.

. 26.14 MessageBox VCL

. 26.15 MessageBox Windows API

Borland C++. MessageBox 


OWL, . 

VCL.


27


C++ Builder

.

.
, I

, 
Internet, 5 ,
C++ Builder.
 , , ,  
. 
, , , , 
, , , ,
, ,
.. , , 
.
: 
(, , 
). 
tmp.

. , , 
. , , ,
. 
shareware,

, . ;
,  ,
.

27.1.

235

, . 
, . 25.13,
Builder .
. File New Application ( 
). ,
.
, , , 
. ( ),
Form1. 
2, 25.1. 
.
Caption Form1
, 25.
. , , ,
( ) ClientHeight
ClientWidth (. 27.1).

( , 
25). . , 
, .

27.1.
Additional (
). , 
Image () . . 27.2.
, .
, 
Image1. 

(. 27.3).
Form1 Image1,
. 
. .
.
Properties Image1 Picture (), 
. , 
, Picture, ,
(. 27.4).
:
Picture Editor ( ) .
. 27.5. , Borland
.
, . ,


236

27 C++ Builder

. 27.3

. 27.4 Picture
. 27.1

. 27.2

, , 
, .
, .
Load (), .
, .
, ++ Builder , 
. 
++ Builder. , , :
E:\builder5\Borland Shared\Images\Splash\16Color\technlgy.bmp.

, .
, . 27.6.
, 240180.
,
. . 27.6 
, , .
,

, , .
, , .
, .

27.1.

237

. 27.5

. 27.6

, .
, .
OK, Load.
.
, ,
(. 27.7).
. 
; .
, .


238

27 C++ Builder

true AutoSize (
) Image1. . ,
, , .
AutoSize false.
. Image1
Stretch () true.
, .
,
AutoSize, .
. , 
. 240180, 
8060,
. Image1 
Height () 60, Width () 80.
. 
; 8060. ,
. 
, 
. . 27.8 
,
.  
, .

. 27.7

. 27.8

. ,
project2.exe, ,
. , 
. ,
, .

27.2.
, .
, . , 
.

27.2.

239

Standard
A, Label (
). ,
. Label1, TLabel.
,
. , Microsoft ,
. . 
, .
AutoSize Label1. ,
true; 
. :
, ,
. Caption. , 
(. 27.9).

. 27.9


. AutoSize false.
. 27.10.
Label1 WordWrap ( ) true.
, ,
. , ;
++ Builder , ,
.
, . ,
, . 
Alignment (). taCenter. 
. 27.10.

. 27.10

,
. ,


240

27 C++ Builder

, 
.

27.3.
rich,
TRichEdit.
.
Win32 , (. 27.11).

. 27.11 Win32

: RichEdit.
,
RichEdit1 (. . 28.2).
,
, .
 , 
.
. , 
( ). 
, ( )
txt. license.txt CBuilder5.
 . license.txt 
; 
.
RichEdit1?
. . 
, ++ Builder .
. 
. ,
. .
Unit1.cpp 
. . 
, .
TForm1 *Form1;

Form1, TForm1. 
TForm1. ,
TForm1.

27.3.

241

, 
RichEdit1 license.txt.
,
. (, ),
 , .
:
RichEdit1

, . 
, , . :
RichEdit1>

(property)
(function) . ,
Lines ().
. , . 27.12, , 
Enter Lines .

. 27.12

, File Open:
RichEdit1>Lines

: RichEdit1, 
Lines. . 
,
. , . 27.13.
LoadFromFile ( ).
Enter. :
RichEdit1>Lines>LoadFromFile

. (
)
:
RichEdit1>Lines>LoadFromFile("license.txt");


242

27 C++ Builder

. 27.13

.
. Run. 
, . 
, license.txt .
RichEdit1. , , ,
:
license.txt.
, license.txt 
Run, 
project2.exe .
,
(. 27.14).
,
.
:
, 
RichEdit1
. , 
. 27.14
Lines

RichEdit1.
.

, .
, . 
LoadFromFile 
.  , 
trycatch.
. 
.
try
{
RichEdit1>Lines>LoadFromFile("license.txt");
}
catch(...)
{

27.3.

243

RichEdit1>Lines>SetText(" license.txt.
.\n...");
}

trycatch, 
. ( 
), ++ Builder
. , ,
. , ++ Builder.
, Enter , , 
. ++ Builder,
, , :
RichEdit1>Lines>SetText(" license.txt. \
.\n...");

\n. , 
, .
, .
trycatch. . 
, try,
, try. , try 
. , catch 
, .
try  , 
( ),
, (. . 27.14), 
.
catch. catch , .
(), try.
, .
. 
catch . , catch 
, try.
try LoadFromFile,
,
.
catch SetText RichEdit1
. ,
license.txt .
, 
, project2.exe.
Run, 
license.txt ++ Builder , 
. 27.15.
++ Builder ,
. ,


244

27 C++ Builder

. 27.15

 : .
, OK,
Run. .
. , , 
RichEdit1, ,
. , . , 
, 
. , ,
( , ).
RichEdit1 . 
ReadOnly ( ) true. 
ParentColor ( ) true 
++ Builder. ScrollBars ( )
ssVertical ( ).
.
, , 
. , .

27.4.
, .
Run, , . ,
, , , 
.
. , 
, ++. ,
.
exe , ,
. ,
. , 
.
, .
Run ,
. ? Borland ++ 
Run Compile (),
(. . 1.8).
++ Builder , .

27.4.

245

, Compile. 
Project Compile Unit ( 
) . . 27.16.

. 27.16

, ,
, .
, 
(. . 25.6). 
. ?
, 
. ,
, .
. 
Beep on completion ( ) . . 25.15. 
Background compilation ( 
), .
, 
. , OK
Project Compile Unit . 
(. . 25.6), (
Beep on completion) 
(. 27.17).
, ,
. :
Compile Unit ( ). 
, . 27.18.


246

27 C++ Builder

. 27.17

. 27.18

There are errors ( ),


Errors:1. OK
. , ,
.
++ Builder.
, , Word, 
. ( 
). Customize ().
, . 27.19.
Commands (), Categories
() Project,
Compile Unit. , 
. 27.19. .
,
. Run.
, . 
. 27.20.
, , , 
. , ,

27.4.

. 27.19

. 27.20

. 27.21

247


248

Borland C++

, : . ,
Customize (
).
, ,
.
. 
, ,
View Forms ( ), 
(. 27.21).


28

, 
.

, ,
. 
,
. 
, ,
TLabel,
.
TRichEdit . 
, license.txt.
, 
.
 ,
. 
.

28.1.
Standard . 
(. 28.1).
, . 28.2, 
.
. 
.


250

28

. 28.1

: , 
( , ).
( ) ,
( , 
).
. 
, . 

. 
, (. 28.3).

. 28.2

. 28.3

,
. RadioButton1 RadioButton2.
++ Builder , .
, ,
? RadioButton2 ,
. 
, .
,
. 
, RadioButton1.
Name RadioButton1 AgreeYes. , ,
. 
(yes) (agreement),
.

28.1.

251

. , . 
, AgreementYes, , . AY
. ,
. ++
Builder ,
SoglasDa.
Caption 
AgreeYes. (. 28.4). 
AgreeNo. , . 28.4.

. 28.4

, . . 
Run, ,
license.txt , 
Run . ,
. ,
, .
, 
license.txt . ,
( )
.
. . , 
, . , 
, . , (. 28.6). 
, . ,
.
, . 
,
license.txt. catch, ,
:
catch(...)
{


252

28

RichEdit1>Lines>SetText(
" license.txt. \
.\n...");
AgreeYes>Visible = false;
AgreeNo>Visible = false;
}

, . AgreeYes>Visible
Visible () AgreeYes.
, ,
. AgreeYes
Visible bool () . . 28.5.

. 28.5 Visible

( , ,
) . ,
, , 
. 
true false. ,
. ,
Visible . Visible
true, , ( ) ; false,
.
, . ,
. 
, , . 
. , , ,
. ,
( ),
, , 
++. 
( 
:=).
,
license.txt. , 
.
, .
Visible
Enabled (). catch :
catch(...)
{
RichEdit1>Lines>SetText(
" license.txt. \
.\n...");

28.1.
AgreeYes>Enabled = false;
AgreeNo>Enabled = false;

253

,
license.txt , 
. 28.6. .

. 28.6 ,

, 
. , 
, .
, , 
. , 
.
AgreeYes, Checked () true.
, ,
Checked false
, . !

28.2.
 , 
. ,
. 
, . 
AgreeCont (Agreement Continue),
.
. Out .
. 
, ,
.


254

28

. , , 
. 
,
File Exit ( ). 
.
. 
.
, . OutClick,
Out Click ().
, . :
void __fastcall TForm1::OutClick(TObject *Sender)
{
exit(0);
}

() exit ,
. .
. ,
, 
. 
, , ,
, .
, AgreeCont
Enabled () false. , ,
, .
. ,
, ,
. 
? , . ,
, MessageBox, 
26. , :
void __fastcall TForm1::OutClick(TObject *Sender)
{
if ( Application>MessageBox(" \
?",
" ", MB_YESNO | MB_ICONQUESTION) == IDYES)
Application>Terminate();
}

,
.
MessageBox, . Application
, Application
( ). ,
MessageBox
, IDYES,
. (if) (==) ,

28.2.

255

Terminate (). 
, 
, . , 
, , . 28.7.

. 28.7

. 
. ,
. , 
, 
, . ,
, : 
++ Builder.
. ++ Builder 
, .
, , .
Unit1.cpp . 
:
void __fastcall TForm1::AgreeYesClick(TObject *Sender)
{
AgreeCont>Enabled = true;
}
void __fastcall TForm1::AgreeNoClick(TObject *Sender)
{
AgreeCont>Enabled = true;
}

. ,
Enabled , 
, .
.
. , 
, .
. , 
. , ,
. , 
:
if ( "")
{ , }


256

28

if ( " ")
{ , }

:
if ( "")
{ , }
else
{ , }

,
.
. . 
( ):
if ( AgreeYes>Checked == true )
{ }
else
{ }

, Checked AgreeYes (
) true. , ,
, (
). , 
else.
. , , .
 , 
, . :
if ( AgreeYes>Checked )
{ }
else
{ }

, , ,
++. , 
true .
. 
, 
, .
, 
, .
, ,
.. . 
, ? , , , 
 . , . 
. ++ Builder
.  , 
, ++ Builder. ,
 ( ) OutClick.
:
void __fastcall TForm1::OutClick(TObject *Sender)

28.2.

257

, 
. , .
. , 
:
if ( AgreeYes>Checked )
{ }
else
{
OutClick(AgreeCont);
}

.

, AgreeContClick ( 
),
else. OutClick.
, OutClick
. , .
,
OutClick AgreeCont. , 
, , 
TObject. ++ Builder ,
. , .
, .
, OutClick ( 
):
void __fastcall TForm1::OutClick(TObject *Sender)
{
char* messout;
if ( Sender == Out)
messout = " ?";
if ( Sender == AgreeCont)
messout = " , \
.\n ?";
if ( Application>MessageBox(messout,
" ", MB_YESNO | MB_ICONQUESTION) == IDYES)
Application>Terminate();
}

. 
, (. . 28.7). 
,
, . 28.8.
. 
messout ( message out), 
. , 
OutClick.


258

28

. 28.8 , ?

Sender*. , OutClick
, Out (
), Sender Out.
OutClick,
AgreeCont, Sender
AgreeCont.
if , 
, Sender.
Out, messout
. Sender AgreeCont,
.
MessageBox, ,
messout.
, ,
. 
, 
.
, . TRichEdit, 
. 
, Visible 
false. .
 , .
, , ,
, .
( ),
, . 
. :
if ( AgreeYes>Checked )
{
delete RichEdit1;
delete AgreeYes;
delete AgreeNo;
delete AgreeCont;
}

delete () .
delete ,
* , , , .

28.2.

259

. . 
. 28.9.
, .
, . 
.

. 28.9

28.3.
, . , Win32
.
, TabControl ( ()),
PageControl ( ).  
, . ,
. .
, ++ Builder
, .
. ,
,
(), . 
TPageControl.
( ), ,
TLabel, ,
TTabControl. .
TTabControl,
: TPageControl.
Component Palette, Win32 , 
TTabControl (. 28.10). 
, . 28.11.
TabControl1, 
TTabControl. .


260

28

. 28.10

TTabControl

. 28.11

, ,
, TabOrder. 
. , 
, 
TabOrder.
. 
TabOrder ( 
, ), .. 
.
TabControl1. ,
, ++ Builder ,

. 28.12

28.3.

261

. .
TabControl1 Tabs,
.
String List editor ( ), 
(. 28.12).
,
. C++ Builder
. , 
, . ,
. .
TLabel, TabControl1
(. 28.13).

. 28.13

Label2, .
. . 
,
. , 
Label2. , .
, ,
, : ++ Builder,
TabControl1 .
? , .
. ,
( , 
). ++ Builder ,
, .
? .
TabControl1.
TabControl1Change,


262

28

.
, . :
void __fastcall TForm1::TabControl1Change(TObject *Sender)
{
switch (TabControl1>TabIndex)
{
case 0:
Label2>Caption = " 1";
break;
case 1:
Label2>Caption = " 2";
}
}

switch
, . 
.
, . 
, , . 
0, 1 .. 
0 1
1 2. , TabControl1 
TabIndex,
switch.
, .
case 0: break; ,
(case), switch 0 ( 
0).
" 1". switch,
1. .
break, , .
, . 
, . 
, , ,
Label2 Label2. , 
Label2 ? ,
.
. , , 
, try...catch. try...catch
TabControl1Change. :
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TabControl1Change(Form1);
try

28.3.
{

263

RichEdit1>Lines>LoadFromFile("license.txt");
}
catch(...)
{
RichEdit1>Lines>SetText
(" license.txt. \
.\n...");
AgreeYes>Enabled = false;
AgreeNo>Enabled = false;
}
}


Label2 .
, ,
, . , 
. , false Visible. 
, Label2
. , ++ Builder .
.
, , ( 
),
TabControl1. ,
, 
:
void __fastcall TForm1::AgreeContClick(TObject *Sender)
{
if ( AgreeYes>Checked )
{
delete RichEdit1;
delete AgreeYes;
delete AgreeNo;
delete AgreeCont;
TabControl1>Visible = true;
}
else
{
OutClick(AgreeCont);
}
}

Visible TabControl1 
true, . Label2 
! , . ...
,
, , .
( ) 
, . 
.
, TPageControl.


264

28

, TabControl1.
Del . TabControl1
Label2. 
, , ++ Builder , 
, . , , , 
TabControl1Change,
, C++ Builder . 
, , , .
, Win32
, TPageControl
. 28.14
(. 28.14).

.
28.11.

. 
TPageControl
TabControl1,
Visible PageControl1 false. 
PageControl1 . 
, AgreeContClick
:
void __fastcall TForm1::AgreeContClick(TObject *Sender)
{
if ( AgreeYes>Checked )
{
delete RichEdit1;
delete AgreeYes;
delete AgreeNo;
delete AgreeCont;
PageControl1>Visible = true;
}
else
{
OutClick(AgreeCont);
}
}

PageControl1 . 
PageControl1 Tabs,
TabControl1. 
PageControl1
(. 28.15).
New Page ( ).
, , (tab).

. .
TTabSheet TabSheet1, 
. 
Caption. .

28.3.

265

.
, 
, . 28.15, Delete
Page ( ) . 
.
.
(. . 28.15) New Page.
TabSheet2.
,
++ Builder ,
. ,
, 
Borland ++, 
.
Caption
. ( 
) . ,
. , 
. 28.15


, ++

Builder. ,
, , (
),
, PageControl1:
...
PageControl1>Visible = true;
PageControl1>ActivePage = TabSheet3;
...

ActivePage PageControl1
, . 
, : 
, . 
.

28.4.

.
TLabel. .
. 
ComboBox TComboBox.
Standard, , 
(. 28.16).

. 28.16


266

28

, .
, , , 
. .

, ++
Builder . , 
. 28.17. 
.
( ), 
.

. 28.17

,
. , , 
, . , 
,
. , 
, .
, , ComboBox1
. , ,
, .
, ?
:
 , ++ Builder (, 
, ..), .
, ++ Builder, 
, , Borland ++. .
Borland ++ TComboBox:
Windows API GetLogicalDriveStrings 
.

28.4.

267

, . 
 
.
, , 
, , , , 
, Windows API.
26.4, , Windows
Microsoft. , ++ Builder
Help Windows SDK.
GetLogicalDriveStrings , . ++
Builder , ComboBox1.
, .
, , ,
, .
. ,
:
PageControl1>ActivePage = TabSheet3;
char drivestrings[200];
GetLogicalDriveStrings(200, drivestrings);
int i = 0;
char newitem[4];
while ( drivestrings[i] != \0 )
{
sprintf ( newitem, "%c", UpCase( drivestrings[i] ) );
ComboBox1>Items>Add(newitem);
i = i + 4;
}
ComboBox1>ItemIndex = 0;

, 
. GetLogicalDriveStrings,
, 
.
drivestrings, char () 200 ( 
200 , ). 
, GetLogicalDriveStrings
drivestrings:
c:\<null>d:\<null><null>

, drivestrings
( ), ,
( <null>).
. ,
,
.
, drivestrings, 
newitem (),


268

28

. ComboBox1. 
,
.
, ,
. ,

( ). , 
.
, , :
char drivestrings[200], newitem[4];

sprintf.
i drivestrings
UpCase newitem. %c
, newitem .
.
Borland ++, 
, ++ Builder. ComboBox1
Items, . 
Add .
, , .
drivestrings
. , 
(, , , Unicode,
), 
( ), , ..,
. 
i, 0 (int i = 0;).
drivestrings,
, (.
drivestrings). 
while. , ,
(!= ) \0, 
, while.
, i 
4, i.
i = i + 4 ,
, .
:
i 4, 8.
, while
, . i
, (), 
. ,
, . ,

28.4.

269


.
, ,
ComboBox1. ,
, (index).
0, 1 .. , 
, ItemIndex.
ComboBox1>ItemIndex = 0; 0, 
, 0
ComboBox1.
: , 
sprintf. ,
Unit1.cpp, , :
#include <stdio.h>


(. 28.18).

. 28.18

. 
, .
, Windows API. 
? , ++ Builder
drive ().
TDriveComboBox, TComboBox.
, :
.
Win 3.1 (. 28.19).
.
(. 28.20).


270

28

. 28.19

. 28.20 D

... , , , , 
. , , , ,
, .
. 
( , CDROM)
. , , , 
.
Win 3.1, 
, .
, . Windows API? , 
, 
, , , 
.
, Win 3.1 
TDriveComboBox, ,
:
TFilterComboBox;
TDirectoryListBox;
TFileListBox.
. TFilterComboBox
, . ,
, *.tmp, * ; , 
tmp, .
TDirectoryListBox ,
,  
, .
, 
Windows.

28.4.

271

TFileListBox , 
.

,
. , 
,
. 
.
, :

TDriveComboBox, 
;
TFilterListBox,
;
TDirectoryListBox,
( , 
).
, .
, 
,
. :

.
Win 3.1 
DriveComboBox1 TDriveComboBox
. , . 28.21,
FilterComboBox1 TFilterComboBox. 
, . 28.22.

. 28.21


TFilterComboBox

. 28.22


272

28

,
All files ( ). , 
.
FilteromboBox1,
Filter (). , 
,  
. , Filter
Editor ( ).
. 
, 
. ,
. All files 
. 28.23.
, , 
, ,  
. , ,
, ,
.
. 
,
, Filter
ComboBox1. 
TLabel (. 28.26).
, ( Caption)
.
,
Save All ( ) C++ Builder
(. . 25.2). 
, .
,  
.

. 28.23

. 28.24


DirectoryListBox

28.4.

273

Win 3.1 
, . 28.24.

(. . 28.19). 
, .
Visible DirectoryListBox1
false. . C++
Builder .
.
, 
. ,
( Caption) , ( Name)
DelButton. 
.
TLable, ,
. Additional ,
. 28.25. 
.
Builder StaticText1,
TStaticText. , .
ResText1 ( Result Text). , 
TLabel,  . 
BorderStyle ( ).
sbsNone (
), sbsSunken ().
Caption, .
,
. ,
AutoSize false . 
, .
(. 28.26).

. 28.25

. 28.26


274

28

, . , 
. 
, ,
,
. , ,
, C++ Builder. 
Unit1.cpp DelButtonClick, 
.
, ,
, ,
, , .
, , ,
. DelButtonClick :
void __fastcall TForm1::DelButtonClick(TObject *Sender)
{
ResText1>Caption = " ...";
DirectoryListBox1>Drive = DriveComboBox1>Drive;
DirectoryListBox1>Directory = DirectoryListBox1>GetItemPath(0);
int dirnumber = 0;
int filenumber = 0;
AnsiString slesh;
TSearchRec sfile;
while ( !DirectoryListBox1>GetItemPath(dirnumber).IsEmpty() )
{
if ( dirnumber == 0 ) slesh = "";
else slesh = "//";
if ( FindFirst(DirectoryListBox1>GetItemPath(dirnumber) + slesh +
FilterComboBox1>Mask, faAnyFile, sfile) == 0)
{
do
{
filenumber++;
} while (FindNext(sfile) == 0);
FindClose(sfile);
}
dirnumber++;
}
ResText1>Caption = " " + IntToStr(filenumber) + " ";
}

? , , , 
, . .
Caption ResText1 
... ,
, . 
, ( 
), ... 
.
 ,

28.4.

275

. , , 
. .
. 
, ,
.
DirectoryListBox1>Drive = DriveComboBox1>Drive;

DirectoryListBox1 DriveComboBox1 Drive.


. , 
( =) . 
. DriveComboBox1 
, Drive
. , 
. DirectoryListBox1, 
, .
. Drive , 
DriveComboBox1.
DirectoryListBox1 . 
(, ),
, . ,
, .
, , ,
DriveComboBox1 ,
, DirectoryListBox1 
, .
, 2
, . 28.27. ,
,
, . 28.28.

. 28.27
DirectoryListBox1

. 28.28
...

,
, ,
. , ,
, . 28.27 (
2), , E, 
, , . 28.28. 
, .


276

28

(
). DirectoryListBox1 DriveComboBox1,
, .
(item). , 
, ,
(index). . ,
. 28.27, , :\,
2 4. 
Directory . (
) GetItemPath(), 
, .
:
DirectoryListBox1>Directory = DirectoryListBox1>GetItemPath(0);

, ,
GetItemPath(0) ( ) 
0, Directory, 
.
, , , .
. . 28.28 ,
( ) 
GetItemPath(), 
0, 1, 2 .. 
.
, , . 
:
int dirnumber = 0;
int filenumber = 0;
AnsiString slesh;
TSearchRec sfile;

.
(dirnumber) ( ), 
. , 
, 
1, 0. (filenumber)
, 
0.
slesh sfile. ,
; 
. :
while ( !DirectoryListBox1>GetItemPath(dirnumber).IsEmpty() )

while, , ,
. , (
true), , .

28.4.

277

, , 
. :
GetItemPath()
( 16), , ;
. GetItemPath()
, ,
.
, 
IsEmpty , 
, Is the string empty?
true (), . ,
,
, , IsEmpty false (). 
, , , 
while, ? 
.
.
, ,
while.
: FindFirst, FindNext FindClose.
file management routines ( ).
, .
. FindFirst
(First) ,  .
FindNext (Next)
. FindClose (Close
) , .
, 
, .
if ( FindFirst(DirectoryListBox1>GetItemPath(dirnumber) + slesh +
FilterComboBox1>Mask, faAnyFile, sfile) == 0)


, .
,  ?
FindNext? * . 
, , :
E:\builder5\*.tmp

FindFirst tmp
E:\builder5, FindNext , , 
, . , , 
. GetItemPath()
( , dirnumber), 
, E:\builder5. .


278

28

GetItemPath() 
, E:\,
();
E:\builder5, , . ,
, , .
+. 
. .
slesh. 
:
if ( dirnumber == 0 ) slesh = "";
else slesh = "\\";

. ( 
dirnumber 0), slesh .
.
E:\ , . , 
. , ,
. ,
, E:\builder5, slesh (
), E:\builder5\. .
, ,
. *.tmp. 
FilterComboBox1. ,
, . 
Mask FilterComboBox1. ,
.
FindFirst .
faAnyFile ( ). 
.
sfile. .
( , TSearchRec), sfile (structure).
,
. , , .
, , . FindFirst 
sfile, . 
: , sfile.Name,
, sfile.
FindFirst . , 
, sfile
0. 0 ( ), 
, .
, , , (, 
) ,  if.
(if) ,

28.4.

279

FindNext 
. :
do
{
filenumber++;
} while (FindNext(sfile) == 0);
FindClose(sfile);

while. 
:
while ( <> ) { <> }

, , ,
. 
:
do { <> } while ( <> );

,
. 
do...while, , 
while. while
FindFirst FindNext. ,
, 
FindFirst , . 
.
filenumber++;

, . .
:
filenumber = filenumber + 1;

filenumber ,
filenumber. ,
filenumber . , 
, .
.
, , FindFirst ,
. , , .
, , 47 , 48.

while. FindNext, 
sfile, FindFirst.
,
( FindFirst). 
, 0, . 
0,


280

28

,
FindNext, , . 
, .
FindClose(sfile), 
, .
, 
if, , FindFirst.
, 
.

dirnumber++;

.
, while,
. , , 
, , , .
, , 
:
ResText1>Caption = " " + IntToStr(filenumber) + " ";

filenumber 
. ResText1,
Caption. ( )
. .
, , 48 48,
IntToStr.
. 
. , . 28.29.

. 28.29

28.4.

281

? 
.
2 . 
, ,
filenumber 
. :
ResText1>Caption = " : " + IntToStr(filenumber);

.
. 
, . 
Windows, ,
.
, , 
. ,
do
{
filenumber++;
} while (FindNext(sfile) == 0);

(
DeleteFile):
do
{
DeleteFile(DirectoryListBox1>GetItemPath(dirnumber) + slesh +
sfile.Name);
filenumber++;
} while (FindNext(sfile) == 0);

DeleteFile .
, .
, FindFirst.

( FindFirst FindNext) , 
Name sfile.
:
:. . ,
. , .
, ?
, , 
. , , 
? :
. , ,
.


282

28

,
DeleteFile.
,
. , 
, 
. , ,
.
, . 
filenumber
delfiles:
int delfiles = 0;

.
DeleteFile ( ,
 ):
do
{
if (DeleteFile(DirectoryListBox1>GetItemPath(dirnumber) + slesh +
sfile.Name)) delfiles++;
filenumber++;
} while (FindNext(sfile) == 0);

, DeleteFile
. false, , 
true. (if) 
, delfiles, , 
delfiles++ .

:

. 28.30 ,

28.4.

ResText1>Caption = " : " + IntToStr(filenumber) +


"\n : " + IntToStr(delfiles);

283

\n,
. 
, , 
. ResText1, , 
. 28.30.
, . ,
Snap to grid ( ),
Grid size ( ) 8 (. . 25.16).
,
.  
, . 
, ,
(. . 25.16), , ,
,
Height, Width, Top Left .


29

,
.


. , 
. ,
5. , C++ Builder 
 , 
. , , 
.

29.1.
,
 . ,
.
(TLabel)
. C++ Builder
.
TLabel Label4. AutoSize false
( ), WordWrap
true ( ). Caption
, . 29.4.
, Format ( Name), 
( Caption).

29.1.

285

, 
 . avi.
C++ Builder ,
, avi.
Win 32 , 
29.1.
. , 
, 
. 29.1
, , . 

AviFind1. CommonAVI (
avi).
C++ Builder. ,
. aviFindFile AviFind1
. , ,
,
Active true. . 
.
aviFindFolder, 
, aviFindFile.
aviDeleteFile
.
.
, AutoSize true. 
. Active 
false. , 
,
. , false
Visible.
,
. C++ Builder FormatClick ,
Format .

. :
void __fastcall TForm1::FormatClick(TObject *Sender)
{
AviFind1>Visible = true;
AviFind1>Play(1, 23, 4);
Application>MessageBox(" \
. ?",
" ", MB_YESNO | MB_ICONQUESTION);
}

Visible AviFind1 true, 


. Play () .
: 1 .


286

29

, , avi (), 
, .
23 , 23 .
, , .
StopFrame AviFind1. 
? Windows API
1,
.  , 
, , 10000.
, 4 . 
, . 
.
MessageBox . ,
, , 
,
. , .
. ,
, . 
,
. , avi.
, .
, . ,
 . , 
. , , ;
, C++ Builder,
 . 
, .
.
, ,
AviFind1, , , ( ). 
, 
AviFind1.
, AviFind1,

Properties
(), Events
() . . 29.2.
, , 
, Stop . 
, ,
. 29.2
AviFind1
. , 
; ? , 
, , . 
 , ,
(, C++ Builder) .

29.1.

287

: Play
, 
. , , OnStop.
, . 29.2, ,
. !
 (. . 29.3),
Unit1.cpp, , AviFind1Stop
.
FormatClick
MessageBox. , FormatClick
, AviFind1Stop,
. AviFind1Stop
:
void __fastcall TForm1::AviFind1Stop(TObject *Sender)
{
Application>MessageBox(" \
. ?",
" ", MB_YESNO | MB_ICONQUESTION);
}

: 
(. 29.4),
(. 29.5).

. 29.3 D
AviFind1Stop OnStop

. 29.4 ,

. 29.5 , ,


288

29

, , , 
. ,
AviFind1Stop ( ) :
AviFind1>Visible = false;

, . ,
, , .
,
, . ,
. , ,
Label4 .
AviFind1Stop :
void __fastcall TForm1::AviFind1Stop(TObject *Sender)
{
AviFind1>Visible = false;
if ( Application>MessageBox(
" \
. ?",
" ", MB_YESNO | MB_ICONQUESTION) == IDYES)
Label4>Caption = ". :. \
...";
else
Label4>Caption = " , . \
\ :. ...";
}

. 
, Width (). ,
. , , 
, , , (

WinZip, ).
. ,
, , (
\n) , Label4.
:
void __fastcall TForm1::AviFind1Stop(TObject *Sender)
{
AviFind1>Visible = false;
if ( Application>MessageBox(" \
. ?",
" ", MB_YESNO | MB_ICONQUESTION) == IDYES)
Label4>Caption = ".\n :.\
\n ...";
else
Label4>Caption = " , .\n \
:.\n ...";
Format>Visible = false;
Label4>Width = 280;
}

29.2.

289

, else 
Caption, Format>Visible = false
else ,
.
280. , .
. 
. .

29.2.
, ( 
) .
.
, . 
, , ,
, . ,
, .
.
, , 
, . ,
. 
, , ,
. Run C++ Builder,
, C++ Builder
Run Program Reset ( ). , Reset
,
, C++ Builder.
, ? ,
. , 
. AviFind1Stop :
Out>Enabled = false;

, .
. , 
. 
.
.
. ,
, , Form1. 
, Events.
! , AviFind1.
OnClose. , FormClose,
. , 
, ( ) .


290

29

, 
Sender Action (). ,
. :
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caNone;
}

caNone , (none) .
.
. ,
, FormClose :
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
Application>MessageBox(" \"\"",
" ", MB_ICONINFORMATION);
Action = caNone;
}

MessageBox , ,
.
,
. ,
, \". :
, . 29.6.
. 
? Ctrl+Alt+Del,
.
.
, Run, Ctrl+Alt+Del
, ,
, Caption Form1.
,
, , , 
, AviFind1Stop :
Form1>Caption = " ";

,
, .
, Windows exe,
project2.
.
, , ,
. .
Windows , , Explorer. 
:
Form1>Caption = "Explorer";

29.2.

291


, , . 29.7.
,
, . 29.6,
.
.

. 29.6

. 29.7 Explorer

Win 32 ,
. 29.8. ,
, .
ProgressBar1, Bar1.
TProgressBar. . Min Max
, 
. Position ( ).
, Position.
Smooth ().
false, 
, . true, 
.
. 29.8
: 
Position,

0 100. C++ Builder , , 


(timers), 
Windows. 
AviFind1Stop .
, 
.
, 
:


292

29

void __fastcall TForm1::AviFind1Stop(TObject *Sender)


{
AviFind1>Visible = false;
if ( Application>MessageBox(" \
. ?",
" ", MB_YESNO | MB_ICONQUESTION) == IDYES)
Label4>Caption = ".\n :.\n\
...";
else
Label4>Caption = " , .\n \
:.\n ...";
Format>Visible = false;
Label4>Width = 280;
Out>Enabled = false;
Form1>Caption = "Explorer";
DWORD TimeStart = GetTickCount();
DWORD TimeEnd = TimeStart + 20000;
while (GetTickCount() < TimeEnd)
{ Bar1>Position = ((GetTickCount()  TimeStart)/200 ); }
Out>Enabled = true;
Form1>Caption = " ";
}

, GetTickCount. , 
, , 5,
: , 
. GetTickCount ,
. Windows , (6:41 ),
, Windows. , , 

, , ,
. Windows 
, DWORD ( Microsoft). , 
0 4,294,967,295.
, , , ,
, , 
, , 
.
.
TimeStart,
:
DWORD TimeStart = GetTickCount();

, 
GetTickCount. : 
TimeEnd
20 :
DWORD TimeEnd = TimeStart + 20000;

29.2.

293

, 20000 20 . 
(
), , TimeEnd.
:
while (GetTickCount() < TimeEnd)

, , (while)
, :
Bar1>Position = ((GetTickCount()  TimeStart)/200 );

, , , , , 
. Position Bar1. 
( =) , ,
200 
. , , 
TimeEnd, , 100 (
Max Bar1).
, 
200. 5.

, :
Out>Enabled = true;
Form1>Caption = " ";

, ... 
, . , , ,
, . 
. ,
,
, , ,
 .
. , .
. 
, . 29.9.
, TLabel ,
Borland C++
TStaticText. 
, . 
Label4
TStaticText.
Label4 Del . 
, . 
Additional StaticText.
.
Properties, AutoSize


294

29

false, Name Text1 


Caption Label4. AviFind1Stop
Text1 Label4.
, 
 , . 
? ? ,
. ,
.
( Unit1.cpp), C++ Builder Search Replace (
). 
(. 29.10).

. 29.9 ,

. 29.10

29.2.

295

, Replace All ( )
*.
( TLabel
). ,
( Width) Text1, .
AviFind1Stop :
void __fastcall TForm1::AviFind1Stop(TObject *Sender)
{
AviFind1>Visible = false;
if ( Application>MessageBox(" \
. ?",
" ", MB_YESNO | MB_ICONQUESTION) == IDYES)
{
Text1>Width = 280;
Text1>Caption = ".\n \
:.\n ...";
}
else
{
Text1>Width = 280;
Text1>Caption = " , .\n\
:.\n \
...";
}
Format>Visible = false;
Out>Enabled = false;
Form1>Caption = "Explorer";
DWORD TimeStart = GetTickCount();
DWORD TimeEnd = TimeStart + 20000;
while (GetTickCount() < TimeEnd)
{ Bar1>Position = ((GetTickCount()  TimeStart)/200 ); }
Out>Enabled = true;
Form1>Caption = " ";
}

. 
. 29.11.
.
. ,
 ,
. , 

. AviFind1Stop :
Text1>Caption = " : ";
Application>MessageBox(" .\n ?",
* , TLabel 
TStaticText,
( Name) Label4. . . .


296

29

. 29.11

"", MB_YESNO | MB_ICONQUESTION);


Text1>Caption = " \n\
...";
ExitWindowsEx(EWX_REBOOT, TimeStart );

Caption MessageBox .
ExitWindowsEx.
Windows API. EWX_REBOOT 
. , ,
Microsoft  Windows ( 
). , 
, .
, .
, Run. 
, .

29.3.
 .
, . 
, , 
.
, .
, .
, ,
. 
, , 
. . 
.
, 
 .

29.3.

297

, .
? Windows, 
, Windows
System.dat*. Windows 95/98 
. ?
C:\windows\System.dat, Windows 
windows.
Windows API. WinAPI
GetWindowsDirectory, , Windows
. C:\windows, 
. System.dat 
, . 
, (while) .
( while ):
char file1[80], file2[80];
while (GetTickCount() < TimeEnd)
{
Bar1>Position = ((GetTickCount()  TimeStart)/200 );
GetWindowsDirectory(file1, 80 );
strncat(file1, "\\system.dat", 12 );
GetWindowsDirectory(file2, 80 );
strncat(file2, "\\sy.dat", 12 );
CopyFile(file1, file2, false);
SetFileAttributes(file2, FILE_ATTRIBUTE_NORMAL);
DeleteFile(file2);
}

file1 file2,
. ,
80 . Bar1 ( 
). GetWindowsDirectory
Windows file1. , 
strncat, , 
file1, ( ) system.dat.
strncat file1.
file2,
sy.da , system.dat.
CopyFile file1 file2.
file2 , , ,
. false.
DeleteFile .
SetFileAttributes.
? , system.dat Windows
. ,
* Windows NT , 
, pagefile.sys .
. . .


298

29

, sy.dat, , DeleteFile 
. SetFileAttributes,
sy.dat (, ,
). FILE_ATTRIBUTE_NORMAL. 
, , 
, .
,  . 

. ,
.
, ExitWindowsEx. 
:
//ExitWindowsEx(EWX_REBOOT, TimeStart );

. , ,
. , , ,
.
, . , , 
: ,
.., 
. 
, ,
, .

20 ,
, .
, 
. , , 
Windows .
. , 
 , ,
, 1.was, .
Form1>Caption = "Explorer";

, ,
( ):
FILE* file0;
file0 = fopen("1.was", "w");
fclose(file0);

file0 , .
,  .
16. 
, fopen , ,
1.was. w

29.3.

299

. , fopen 
w , .
, , ,
.
( , ), 
fclose. 
. (
0 ) 1.was. , , 
1.was.
. , 
, ,  . 
, ,
. ,
, , 
, .
, ,
, . ,
. , , ,
.
DelButtonClick :
void __fastcall TForm1::DelButtonClick(TObject *Sender)
{
AnsiString CurDir = DirectoryListBox1>Directory;
ResText1>Caption = " ...";
...
ResText1>Caption = " : " + IntToStr(filenumber) +
"\n : " + IntToStr(delfiles);
DirectoryListBox1>Directory = CurDir;
}

Directory DirectoryListBox1 ,
. 
() CurDir (Current Directory )
. DelButtonClick 
Directory, .
, , 
. ,
1.was .
, 
.
MessageBox . ,
, 
. 
MessageBox 
, . , , 
, . ,
.


300

29

C++ Builder File New Form ( )


, . 29.12. 
Form2 . 
, 
, ( );
, .
Save All
(. . 25.2) . , 
, C++ Builder Unit2.cpp.
, , 
, . 
Unit1.cpp.
, , ,
..
, View Forms ( )
View Form (. 29.13). , 
. 
, , (. 29.14).

. 29.12

. 29.13

. 29.14

. 29.15

, ,
, Form2 .
,
. , .
, , 
, Toggle Form/Unit (
/) . . 29.15. 
, . View.
, C++ Builder
,
.
Form2.
BorderStyle bsDialog, biSystemMenu (

29.3.

301

BorderIcons) false. ( 
C++ Builder, ) ,
, . Caption
, Position
poScreenCenter, .
.
, 27.1. Image, , 
, Load. C++ Builder
( ):
E:\builder5\CBuilder5\Examples\MFC\Advanced\Speakn\Res\face1.ico

AutoSize Image1 true.


TLabel. , 
.
, Label1,
Label1, , 
. , .
, .
Label1 WordWrap true (
), AutoSize false. Caption 
(. . 29.17).

. 29.16

. 29.17

. , 
Standard , . 29.16.
.
TCheckBox CheckBox1. 
. 
( Caption) , 
. . 29.17
, .
State () cbChecked, 
C++ Builder.
. ,
Cont . C++ Builder
, . 29.17.


302

29

, , ,
.
: , 
? ( ), 
, Form2
. , Visible
true. C++ Builder Visible
false, , . 
Form1,
, false . 
, , 
. , ,
.
, , 
license.txt. ,
1.was, ,
Form2. . Unit1.cpp
, .
, try...catch. 
1.was. , , 
license.txt.
, , .
fopen, 
. ( ),
NULL, .
try :
if ( fopen("1.was", "r") ) Form2>Show();

, fopen,
,
. fopen NULL
NULL . ,
"r" ( ),
, 
.
, Form2 Show.
, .
Unit1.cpp ( Run). 
:
Undefined symbol 'Form2'

, .
, .  
Form2 Form1.
Unit1.h.

29.3.

303

Unit1.cpp. , 
, .
Unit1.cpp, , , . 
(. 29.18).

. 29.18 Unit1.h

Unit1.h. , 
, Unit1.cpp.
.
#include ().
, #include, . 
Form1 Form2, :
#include "Unit2.h"

Unit2.h , Form2. 
. . 1.was 
, . ,
, Form2,
. 
, Run,
(. 29.19).

. 29.19 C++ Builder

, . 

Project2.cpp. :
Application>CreateForm(__classid(TForm1), &Form1);
Application>CreateForm(__classid(TForm2), &Form2);


304

29

, Run Program Reset, 


. , Form1,
Form2 ( C++ Builder ,
), . 
! ,
. , 
, , Form2 
, . ,
, Form1 ,
Visible false.
, .
, , , Form1 
, , ,
Form2>Show();

Form2 . ,
, , ,
Form2 .
Form1, Events (
) . OnShow, Form1
, , 
. FormShow. :
if ( fopen("1.was", "r") ) Form2>Show();

. :
1.was , Form1;
1.was , ,
. , .
, Form1 , 
Form2. , Form2 . 
, ,
,
Form2>Close();

Form2 .
, Form1 Form2?
.
, . 
, 
. , , .
, , 
, .
Show Form2 . Form1
Form2,
. , Form2 
. Show ShowModal:
if ( fopen("1.was", "r") ) Form2>ShowModal();

29.3.

305

.
FormShow , .
, FormShow, 
, . 
FormShow . Form2 
, ,
Form1.  , , ,
Visible false.
Form2 ,
. 1.was, 
Form2 .
, . , 
Form2, , , ,
1.was.
ContClick Form2 :
void __fastcall TForm2::ContClick(TObject *Sender)
{
if (CheckBox1>Checked) DeleteFile("1.was");
Form2>Close();
}

, Checked,
. , , 
, .
Checked CheckBox1 true,
, false, . ,
DeleteFile .
, , , 
Unit1.cpp :
if ( fopen("1.was", "r") ) Form2>ShowModal();

, , .
.
DeleteFile . 
:
void __fastcall TForm1::FormShow(TObject *Sender)
{
FILE* f1;
if ( f1 = fopen("1.was", "r") )
{
fclose(f1);
Form2>ShowModal();
}
}

. .
(if) ,


306

29

fclose Form2. 
. ?
, .
, :
Application>CreateForm(__classid(TForm1), &Form1);
Application>CreateForm(__classid(TForm2), &Form2);

.
, . Visible
false, .
( , ), , 
, . , , , 
. ,
. 
( ).
, ?
Form2 ,
ShowModal. 
. Project Options ( ).
Project Options ( ) .
Forms (. 29.20).
(, ) :
Form1 Form2, (Auto
Create) CreateForm, . 
(Main form) Form1. ,
Main form ( , ,
).
Form2 , . 29.21.
Available forms ( ).
Project2.cpp, , Form2 . 
.
FormShow Unit1.cpp:
void __fastcall TForm1::FormShow(TObject *Sender)
{
FILE* f1;
if ( f1 = fopen("1.was", "r") )
{
fclose(f1);
Application>CreateForm(__classid(TForm2), &Form2);
Form2>ShowModal();
}
}

.
, .
, , . Form2 
, ,

29.4. trialK

. 29.20

307

. 29.21


. . 
, , 
 , ,
. , 
.

29.4. trial
,
. ,
, .
, .
shareware. ,
, , WinZip.
, 
. , WinZip
,
( ); 
, 
( WinZip);


308

29

. , 
, .

.
 .
, ,
.
,
. 1.key
. , ,
Windows ( ) 
, , .
. Form3, 
. Name
Nereg ( ). , Save All 
fnereg.cpp. , C++ Builder 
, .
Nereg , Form2: 
BorderStyle bsDialog, biSystemMenu (
BorderIcons) false. Caption
. Position
poScreenCenter, .
TLabel, ,
, . 29.22. 
, Alignment () taCenter (
).

. 29.22

,
, ContStart ( 
Cont) , RegStart
. (
Width 113, Height 25) , 
( Top), . 
( ) Left,
.
, ,

29.4. trialK

309

. ( Visible false).
, , , 
? .
, ( ), ,
, ?
System.
(. 29.22). .
, , . 29.22.
,
. , Visible
.
. Name (
Timer1). Tag 
. . Enabled
true ( ), ;
false . ,
. 
Interval. , 
, , 1000, 1 . 
Interval, , 8000 8 .
. 
?
( Events). , 
. 
 Timer1Timer.
8 .
, , 
, , 
, 8 . ,
Left ( , 32 184),
Timer1Timer :
void __fastcall TNereg::Timer1Timer(TObject *Sender)
{
Timer1>Enabled = false;
randomize();
if ( random(2) )
{
ContStart>Left = 184;
RegStart>Left = 32;
}
ContStart>Visible = true;
RegStart>Visible = true;
}

,
. Timer1Timer, , 
, , .


310

29

randomize
random, .
, ,
, . ,
, : , . ,
0 1.
, , ,
C++ Builder, . 

if.
randomize . 

. randomize, random.
, , , 
Left. if .
,
. ,
Form2. ContStartClick, 
:
void __fastcall TNereg::ContStartClick(TObject *Sender)
{
Nereg>Close();
}


Form2. , ? ,
,
.
, Form2, . 
Project Options Forms,
Nereg, .
. 29.23.

. 29.23

29.4. trialK

311

Unit1.cpp FormShow :
void __fastcall TForm1::FormShow(TObject *Sender)
{
FILE* f1;
if ( f1 = fopen("1.key", "r") ) fclose(f1);
else
{
Application>CreateForm(__classid(TNereg), &Nereg);
Nereg>ShowModal();
}
if ( f1 = fopen("1.was", "r") )
{
fclose(f1);
Application>CreateForm(__classid(TForm2), &Form2);
Form2>ShowModal();
}
}

if, , . 
Nereg . Form2
1.was. Nereg , 1.key
. Nereg
1.key, f1. , , 
.
, f1
if. (else),
Nereg. ( ) 
Nereg.
, , 
Form2.
Nereg .
Unit1.h :
#include "fnereg.h"

Form2 #include
"Unit2.h". . 
. , 
, Form2. 
. .
 ..
. , ,
, 
. , .
TStaticText ( 
, Additional), RegText1,
(AutoSize false), Caption . . 29.31,
.


312

29

Reg . 
. , ,
. ,
, . Unit1.cpp
FormShow :
void __fastcall TForm1::FormShow(TObject *Sender)
{
FILE* f1;
if ( f1 = fopen("1.key", "r") )
{
fclose(f1);
RegText1>Caption = " . \
!";
Reg>Visible = false;
}
else
{
Application>CreateForm(__classid(TNereg), &Nereg);
Nereg>ShowModal();
RegText1>Caption = " . \
, .";
}
if ( f1 = fopen("1.was", "r") )
{
fclose(f1);
Application>CreateForm(__classid(TForm2), &Form2);
Form2>ShowModal();
}
}

, 1.key
RegText1 ( Caption). Reg
( Visible), . ,
1.key, , .
Reg. 
RegClick, 
.
. ,
,
. , 
, C++ Builder .
, File New.
New Items ( ) . 
, Project2 .
Dialogs () . . 29.24.
C++ Builder Object Repository (
). , 
, , .
, ,

29.4. trialK

313

. 29.24 C++ Builder

.
, Password
Dialog ( ). Object
Repository, Copy ().
, Object Repository .
, Password Dialog . 
, TForm1,
TPasswordDlg. 
, (. 29.25).

. 29.25

PasswordDlg, 
. Label1 Enter
password:. (CancelBtn OKBtn) . 
Password .
, 
. , Position


314

29

poScreenCenter, ,
C++ Builder .
Label1
, .
, . 
pass.cpp. , , , ? 
pass.cpp, .

(pass.h) :
class TPasswordDlg : public TForm

, TPasswordDlg
TForm, ( 
, , 
., , 8). ,
TPasswordDlg
TForm , .
.
Project Options Forms
, , ,
. , Form2
Nereg, ,
, .
,
. , Unit1.cpp
RegClick :
void __fastcall TForm1::RegClick(TObject *Sender)
{
PasswordDlg>ShowModal();
}

.
. Unit1.h, 
include, C++ Builder File Include Unit Hdr...
( ). , . 29.26.
, C++ Builder,
. , ,
C++ Builder ,
#include "pass.h"

, Unit1.h, Unit1.cpp, 
, . 
File Include Unit Hdr..., 
, .
,
(. 29.27).

29.4. trialK

. 29.26

315

. 29.27

. , 
, , .
, Password
PasswordChar. C++ Builder
#0, .
.
, , , .
, , , 
( ),
.
, , , 
Enter .
, .
.
. 
( ).

. , , 
RegClick
Unit1.cpp ( pass.cpp).
, Unit1.cpp RegClick 
:
void __fastcall TForm1::RegClick(TObject *Sender)
{
PasswordDlg>ShowModal();
if ( PasswordDlg>Password>Text == "z1234" )
{
RegText1>Caption = " . \
!";
Reg>Visible = false;
delete PasswordDlg;
FILE* fkey;
fkey = fopen("1.key", "w");


316

29
fclose(fkey);

}
}


PasswordDlg. RegClick.
Password 
.
, , Password, , , ,
TEdit. ,
Standard ,
. 29.28. , 
. Caption , 
Text. ,
, . 
Text , 
.
. 29.28
, , ,

( ) . 

Password . 
, ( ) 
. . ,
Text, Password>Text, ,
Password . ,
. PasswordDlg, 
.
,
PasswordDlg, PasswordDlg, :
PasswordDlg>Password>Text

, , .
,
, ,
, . ,
,
. , , 
:
if ( Password>


, ,
.
:
if ( PasswordDlg>

,
PasswordDlg (. 29.29).

29.4. trialK

317

. 29.29

Password,
variable . , Enter
.
Password, Text.
if . 
z1234 , 
, , ,
. == 
, =,
. , C++ Builder
( Warnings
), :
if ( f1 = fopen("1.key", "r") )

, C++ Builder , 
= ==, . ,
f1 ,
fopen, f1 , 
if f1 NULL.
C++ Builder .
(if) , . , 

. ,
. , .
, ,
, . , 
1.key.
, . ,
Nereg.
,
. RegStartClick, 
fnereg.cpp, Nereg. ?
, 
RegClick, ... , ? 
RegClick  ,
:


318

29

void __fastcall TNereg::RegStartClick(TObject *Sender)


{
Form1>RegClick(Nereg);
}

, . 
,
. , Form1 Nereg, Nereg
. :
Form1.
File Include Unit Hdr...,
Unit1 (. 29.30).

. 29.30 Nereg

C++ Builder . , ,
, .
, Nereg , ,
,
. .
, , 
Nereg , . :
, ,
; , ,
.
.
, RegStartClick Nereg:
void __fastcall TNereg::RegStartClick(TObject *Sender)
{
Form1>RegClick(Nereg);
Nereg>Close();
}

,
. , Unit1.cpp RegClick
:
void __fastcall TForm1::RegClick(TObject *Sender)
{
start:
PasswordDlg>ShowModal();
if ( PasswordDlg>Password>Text == "z1234" )
{

29.4. trialK

319

RegText1>Caption = " . \
!";
Reg>Visible = false;
delete PasswordDlg;
FILE* fkey;
fkey = fopen("1.key", "w");
fclose(fkey);
}
else
if (Application>MessageBox(" .\n\
?",
"", MB_YESNO | MB_ICONWARNING) == IDYES ) goto start;
}

start:, else
, .
. ( if)
, , 
start: 
goto. , 
(
, ,
 ). PasswordDlg ..
, 
. . 

Nereg. , ,
, (. 29.31).

. 29.31 , ? , ?

, , , 
.  . 
C++ Builder . 
. FormShow Unit1.cpp,
Nereg:


320

29

else
{
Application>CreateForm(__classid(TNereg), &Nereg);
Nereg>ShowModal();
RegText1>Caption = " . \
, .";
}

Nereg, 
RegClick, 
RegText1 .
RegClick , Nereg 
, FormShow ,
RegText1, 
. :
else
{
RegText1>Caption = " . \
, .";
Application>CreateForm(__classid(TNereg), &Nereg);
Nereg>ShowModal();
}

Nereg , 
, .


. , , , MessageBox

, . ,
, (
). ,
. 
, , ,
ModalResult.
,
. ,
OnClose. , 
, .
PasswordDlg, Events
OnClose, FormClose 
:
void __fastcall TPasswordDlg::FormClose(TObject *Sender,
TCloseAction &Action)
{
if (Password>Text == "z1234") ModalResult = 10;
}

29.4. trialK

321

,
, ModalResult 10.
47845. , 
ModalResult,
OK, Cancel .., ,
10,  . (
) RegClick,
PasswordDlg. 
, 10.
, .
RegClick. , , 
.
. :
void __fastcall TForm1::RegClick(TObject *Sender)
{
start:
if ( PasswordDlg>ShowModal() == 10 )
{
RegText1>Caption = " . \
!";
Reg>Visible = false;
delete PasswordDlg;
FILE* fkey;
fkey = fopen("1.key", "w");
fclose(fkey);
}
else
if (Application>MessageBox(" .\n \
?",
"", MB_YESNO | MB_ICONWARNING) == IDYES ) goto start;
}

PasswordDlg 
. .
,
, . , , 

. , ,
Internet. , , .
.


30


?
,  *.*

Borland 
TRichEdit. ,
, ,
, .
. , ,
.

30.1.
, , 
, 
File New Application. .
. Caption Word
2001, Name MainForm. 
3, MainUnit.cpp Project3.bpr.
TRichEdit (.
. 27.11) .
: Align RichEdit1
alClient (, , 
). , , 
.

30.1.

323

, RichEdit1. 
.
Lines, String Lines Editor (
) . . 30.1.

. 30.1

,
. , , 
1 line (1 ) 0 lines (0 ). 
. !
, , 
, .
Del, Ctrl+C, 
Ctrl+V
Windows. , 
.
? ,
, Enter.
TRichEdit.
ScrollBars ( )
RichEdit1 ssBoth ( ,
). , , 
. 
, .
WordWrap RichEdit1 false
. ,
.
RichEdit1, 
PlainText ( ) true.


324

30

rtf,
( , ).
, , 
, . , 
. , . 
.
, 
Standard, MainMenu ( ).
(. 30.2).
:
RichEdit1. 
, , RichEdit1 .
. , 
. C++ Builder ,
(
).
. :
, 
. 30.2


. ,
C++ Builder
, 
.
, , , RichEdit1
(. 30.3).

. 30.3 MainMenu1

MainMenu1, 
. 30.3.  .
, ! : ,
, .

30.1.

325

Properties MainMenu1 Items (


). .
(. 30.4).
, , 
, , .

. 30.4

, Caption. , 
. . 
Caption Enter,
, .
( ).
, RichEdit1 ,
, .
() 
. ,
(. 30.5). ,
N1, , TMenuItem.
, .
. , ,
Caption . N2, 
. ,
. ,


326

30

. , 
. C++ Builder. ,
,
.
, 
. . , 
. N2Click
, ,
. , Name, Caption.
, File, Open. 
, N2Click OpenClick.

. 30.5

. 30.6

, .
? 
, ,
. , 
, () C++ Builder. .
, ? 
.
Dialogs ( ) ,
(. 30.6). ,
. , ,
, 
, .
, ,
Options , 
. OpenDialog1. ,
OpenClick. ,
, 
. C++ Builder 
.
, . 
RichEdit1, :
void __fastcall TMainForm::OpenClick(TObject *Sender)
{

30.1.
if ( OpenDialog1>Execute() )
RichEdit1>Lines>LoadFromFile(OpenDialog1>FileName);

327

, OpenDialog1
Execute. true, 
OK, false, Cancel.
, OK ,
. ?
, 
. ofFileMustExist Options
true .
OpenClick. 
LoadFromFile 
.
, OpenDialog1.
FileName
OpenDialog1. , ,
. ,
( )
rtf. , ,
, . .
OpenDialog1, Filter
(), .
 Filter Editor ( ). 
, 
(. . 28.23). , ,
, , . 30.7. 
, 
. rtf ,
, .

. 30.7


328

30


, ( ),
Windows. 
,  OK. 
Windows? .
, , 
Execute, OpenClick :
ForceCurrentDirectory = true;

, , 

( ). Force
CurrentDirectory,
. , 
. 
,
.
, , , 
, InitialDir ( )
, Execute :
OpenDialog1>InitialDir = "C:\\";

C:\ InitialDir 
. , .
. 
, . Dialogs .
,
(. 30.8). ,
. 
.
. 30.8
, 

. ( Caption)
, ( Name) Save.

OnClick
Save.
SaveClick :
void __fastcall TMainForm::SaveClick(TObject *Sender)
{
if( SaveDialog1>Execute() )
RichEdit1>Lines>SaveToFile( SaveDialog1>FileName );
}

.
SaveToFile, LoadFromFile. , 
, , ,
, RichEdit1. 
, .

30.1.

329

, . ,
. ,
( )
, . ,
, 
.
. 
. , . ,
, 
(, *.html *.htm). ,
, . 30.9 (
).
,
. Properties
DefaultExt ( ) , ,
txt. . 
txt, ,
. , 
,  , 
.

. 30.9

, , .
FileName.
,
FileName ,
, , .
void __fastcall TMainForm::SaveClick(TObject *Sender)
{
SaveDialog1>FileName = OpenDialog1>FileName;
if( SaveDialog1>Execute() )
RichEdit1>Lines>SaveToFile( SaveDialog1>FileName );
}

, . , , 
, ,
. . 
.
, . ,
. :


330

30

void __fastcall TMainForm::OpenClick(TObject *Sender)


{
if ( OpenDialog1>Execute() )
{
RichEdit1>Lines>LoadFromFile(OpenDialog1>FileName);
MainForm>Caption = "Word 2001  " + OpenDialog1>FileName;
}
}

if ,
. 
.
 ,
? . 
:
void __fastcall TMainForm::SaveClick(TObject *Sender)
{
SaveDialog1>FileName = OpenDialog1>FileName;
if( SaveDialog1>Execute() )
{
RichEdit1>Lines>SaveToFile( SaveDialog1>FileName );
MainForm>Caption = "Word 2001  " + SaveDialog1>FileName;
}
}

 . 
, , 
, .
,  ,
. RichEdit1 Modified, ,
, .
 , true. 
, 
. OpenClick. 
, , (
) :
if ( RichEdit1>Modified )
if ( Application>MessageBox(" .\n\
?",
" ", MB_YESNO | MB_ICONSTOP) == IDYES )
SaveClick(MainForm);

Modified. true (
, true, , ),

. , SaveClick
, , , 
. 
, .

30.1.

331

. , 
,
, . 
, RichEdit1 ,
, , 
RichEdit1. C Modified
RichEdit1 true
, . ,
RichEdit1, , 
Modified false:
void __fastcall TMainForm::OpenClick(TObject *Sender)
{
if ( RichEdit1>Modified )
if ( Application>MessageBox(" .\n\
?",
" ", MB_YESNO | MB_ICONSTOP) == IDYES )
SaveClick(MainForm);
if ( OpenDialog1>Execute() )
{
RichEdit1>Lines>LoadFromFile(OpenDialog1>FileName);
MainForm>Caption = "Word 2001  " + OpenDialog1>FileName;
RichEdit1>Modified = false;
}
}

, 
. , ( 
), , ,
, , ..,
. , 
, , , ,
,
. , ,
C++ Builder, 
, , , .

, , , , .

. 
( ). , 

? .
Modified, , 
.
?
, 
. ,


332

30

,
.

30.2.
? , , ,
MainUnit.cpp. 
, , void. , 
, . 
. fastcall,
, ( ), C++ Builder
, . 
TMainForm:: , 
. 
. C++ Builder
Sender, . 
.
.
MainUnit.cpp :
void __fastcall TMainForm::CheckChange()
{
if ( RichEdit1>Modified )
if ( Application>MessageBox(" \
.\n ?",
" ", MB_YESNO | MB_ICONSTOP) == IDYES )
SaveClick(MainForm);
}

, OpenClick.
... ,
. 30.10.

. 30.10

26 
! ,

30.2.

333

, Too many error messages (


) , ,
26. C++ Builder : , , ,
. : CheckChange() is not a member of TMainForm
( CheckChange TMainForm). ,
.

(. . 29.18). MainUnit.h 
SaveClick OpenClick. ,
, , class TMainForm.
, C++
Builder, published, IDEmanaged
Components (, ).
.
User declarations ( 
). , .
.
, ,
( public, , ). 
( MainUnit.h):
public:
// User declarations
__fastcall TMainForm(TComponent* Owner);
void __fastcall TMainForm::CheckChange();
};

, . 
! , CheckChange 
. 
:
void __fastcall TMainForm::OpenClick(TObject *Sender)
{
CheckChange();
if ( OpenDialog1>Execute() )
{
RichEdit1>Lines>LoadFromFile(OpenDialog1>FileName);
MainForm>Caption = "Word 2001  " + OpenDialog1>FileName;
RichEdit1>Modified = false;
}
}

. ,
. , ,
(. 30.11).

. 30.11


334

30

. 
OnClose MainForm, FormClose.
(. 29.2).
:
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
CheckChange();
}

. 
. , ,
.
, 
, . ,
, ,
(,
, ).
, ,
( ). , ,
,
CheckChange FormClose OpenClick 
, .
. ,
, . ,
, ( 
) ( 
). , CheckChange.
:
CheckChange , .
if . ,
true false . 
. CheckChange
, void int (
MainUnit.cpp MainUnit.h).
, 
, :
int __fastcall TMainForm::CheckChange()
{
if ( RichEdit1>Modified )
switch ( Application>MessageBox(" \
.\n ?",
" ", MB_YESNOCANCEL | MB_ICONSTOP) )
{
case IDYES:

30.2.
SaveClick(MainForm);
return 0;
case IDCANCEL:
return 1;
}
return 0;

335

,
. , switch, 
if, return 0.
, , .
, . ,
return 0 return false,
return 1 return true bool int.
.
, switch. 
28.3. ,
case,
, MessageBox. 
,
( ,
, , ).
, 
: IDYES , IDNO IDCANCEL
. .
, ,
, , case 
.
switch, return 0, ,
.
, case IDYES 
SaveClick , 
return 0.
, . 
,
break ( 28.3), 
return 0 .
, case IDCANCEL, ,
. ,
, CheckChange.
. FormClose :
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction
&Action)
{
if ( CheckChange() ) Action = caNone;
}


336

30

, , ,
(, bool, 
, C++ , 
). ( 
), Action caNone, 
. ,
, 
. , , 
. OpenClick :
void __fastcall TMainForm::OpenClick(TObject *Sender)
{
if ( !CheckChange() )
{
if ( OpenDialog1>Execute() )
{
RichEdit1>Lines>LoadFromFile(OpenDialog1>FileName);
MainForm>Caption = "Word 2001  " + OpenDialog1>FileName;
RichEdit1>Modified = false;
}
}
}

, FormClose.
( ). , 
CheckChange, , 
, .
CheckChange.
.
, 
, , . ?
SaveClick ,
. (
SaveClick):
void __fastcall TMainForm::SaveClick(TObject *Sender)
{
SaveDialog1>FileName = OpenDialog1>FileName;
if( SaveDialog1>Execute() )
{
RichEdit1>Lines>SaveToFile( SaveDialog1>FileName );
MainForm>Caption = "Word 2001  " + SaveDialog1>FileName;
RichEdit1>Modified = false;
}
}

, 
 ,
, . .

30.2.

337

. ,
. 30.12 ( ).

. . 

, ? 
.
, , 
. , 
.
( Name) Create, (
Caption) , , . , 
, 
(separator). , 
. : ,
, ( ), .
C++ Builder (. 30.13).

. 30.12

. 30.13

, , :
void __fastcall TMainForm::CreateClick(TObject *Sender)
{
if ( !CheckChange() )
{
RichEdit1>Clear();
MainForm>Caption = "Word 2001";
RichEdit1>Modified = false;
}
}

, ,
. 
, ( )
Clear, RichEdit1.
Modified.


338

30

. 
( )
. 
.

30.3.
: 
. ,
,
, 
. , 
.
, ( 
, ). Windows ini.
, C++ Builder
( ,
Windows 3.1).  
( ) , ,
ini,
. .
, , 
. , recfile.ini ( recent file),
. , 
. , (,
) . , 
, , ,
, 
UpdateRecFile. ( void),

.
recfile.ini , 

, , 
(recfile) , 
.
recfile.ini,
, 
.
(
) . 
recfile.ini, , 
, .

30.3.

339

, , .
, , ..
.
,  . 
. ,
(. 30.14).
. 
,

. 
N2, ,
RecFile, 
Caption. 
N2,
. 
MainMenu1 
.
. 30.14
AutoLineReduction (

) maAutomatic. 
, , . 30.14,
, ,
. , 
,
( ,  ). 
( recfile.ini), 
. ,
. , .
AutoHotkeys ( 
) maManual. maAutomatic (
),
, .
recfile,
recfile.ini. 
, 
UpdateRecFile ( ), , 
.
, .
MainUnit.h, public:
public:
// User declarations
__fastcall TMainForm(TComponent* Owner);
int __fastcall TMainForm::CheckChange();
char recfile[256];

, ,
, , . ,


340

30

, OnCreate, 
. ,
, :
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
ForceCurrentDirectory = true;
GetCurrentDirectory(256, recfile );
strncat(recfile, "\\recfile.ini", 15 );
}

, ForceCurrentDirectory 
, . 
GetCurrentDirectory recfile 
, .
, , Windows API 
GetWindowsDirectory,
Windows. , , ,
, GetWindowsDirectory
, , GetCurrentDirectory
. .
GetCurrentDirectory recfile
. , .
strncat 
recfile.ini.

recfile.ini, 
. , 
.
recfile.ini. . 
,
recfile.ini. Windows (
GetWindowsDirectory GetCurrentDirectory).
, , .
UpdateRecFile.
void , 
. public MainUnit.h:
public:
// User declarations
__fastcall TMainForm(TComponent* Owner);
int __fastcall TMainForm::CheckChange();
char recfile[256];
void __fastcall TMainForm::UpdateRecFile(AnsiString FName);

. 
, (
AnsiString, ) FName.
UpdateRecFile.

30.3.

MainUnit.cpp :

341

void __fastcall TMainForm::UpdateRecFile(AnsiString FName)


{
int FileRecFile;
FileRecFile = FileCreate(recfile);
char* cp = new char[ FName.Length() + 1 ];
strcpy( cp, FName.c_str() );
FileWrite(FileRecFile, cp, FName.Length() + 1);
FileClose(FileRecFile);
}


FileWrite ( ) C++
Builder. , Examples (), 
, .
fopen
fclose, (++). Borland C++, ,
. C++ Builder
. , fopen,
. , , 
,
C++ Builder.
, UpdateRecFile
recfile.
FileRecFile, FileCreate 
. ,
fopen, int.
FileCreate , recfile.
, ,
. , 
UpdateRecFile.
, ,
FileWrite.
, FileRecFile.

FName AnsiString cp char*. 
, .
char* , AnsiString C++
Builder. , 
char*. ,
FileWrite char*.
, : FileWrite char*
, 
, 0,
, , .
,


342

30

, ,
, .

. . ,
FName UpdateRecFile, 
. ,
, ,
, recfile.ini. , 
FName UpdateRecFile
( , ).
UpdateRecFile
recfile.ini,
() recfile. ,
,
. .
FileClose . ,

.
,
UpdateRecFile. , , 
.
OpenClick :
void __fastcall TMainForm::OpenClick(TObject *Sender)
{
if ( !CheckChange() )
{
if ( OpenDialog1>Execute() )
{
RichEdit1>Lines>LoadFromFile(OpenDialog1>FileName);
MainForm>Caption = "Word 2001  " + OpenDialog1>FileName;
RichEdit1>Modified = false;
UpdateRecFile(OpenDialog1>FileName);
}
}
}

UpdateRecFile,
recfile.ini FileName OpenDialog1.
. . ,

recfile.ini, .
recfile.ini
(. 30.15).
, , .
,

30.3.

343

. 30.15 ,

. , , 
RecFile.
MainUnit.cpp,
recfile, , recfile.ini 
:
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
ForceCurrentDirectory = true;
GetCurrentDirectory(256, recfile );
strncat(recfile, "\\recfile.ini", 15 );
int FileRecFile;
if ( ( FileRecFile = FileOpen(recfile, fmOpenRead) ) > 0 )
{
int iFileLength = FileSeek(FileRecFile,0,2);
FileSeek(FileRecFile,0,0);
char* pszBuffer = new char[iFileLength+1];
FileRead(FileRecFile, pszBuffer, iFileLength);
RecFile>Caption = AnsiString(pszBuffer);
FileClose(FileRecFile);
}
}

FileRecFile. , 
UpdateRecFile. , 
.
FileRecFile MainUnit.h.
.
FileOpen , 
recfile. 
fmOpenRead ( ). , 
FileRecFile  ,
, , 0. ( File
RecFile ) if. 
, 1, 
FileRecFile.
, . 
FileSeek (
, ). 
, .


344

30

: ; 2 ,
( , 0 , 1 
); 0
(0 ). , FileSeek
, .
iFileLength,
.
,
. 
pszBuffer char* (
). 
FileRead ( FileRecFile)
( iFileLength), 
( pszBuffer).
, 
. AnsiString
char* , 
. AnsiString
(pszBuffer) , pszBuffer (
), AnsiString. 
Caption RecFile. ,

,
recfile.ini.

FileClose. 
. ,

(. 30.16).
,
.
. 30.16
.
,
, 
. , ,
Events OnClick.
. :
void __fastcall TMainForm::RecFileClick(TObject *Sender)
{
RichEdit1>Lines>LoadFromFile(RecFile>Caption);
MainForm>Caption = "Word 2001  " + RecFile>Caption;
RichEdit1>Modified = false;
UpdateRecFile(RecFile>Caption);
}

30.3.

345

, , 
. 
, Caption RecFile.

ini. ini ,
. ,
( , ..) , 
, , :
=

, , ini.
recfile2.ini, (. 30.17). ,
, .

. 30.17 ini

,
, ini. 
.
, C++ Builder ini, 
, TIniFile. ,
, UpdateRecFile,
ini. , 
UpdateRecFile, 
, , . 
.
.
, , , 
. ,
, , , 
. , 
.
( ) MainUnit.h
include :
#include <IniFiles.hpp>

, ,
TIniFile. MainUnit.cpp :
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)


346

30

ForceCurrentDirectory = true;
GetCurrentDirectory(256, recfile );
strncat(recfile, "\\recfile2.ini", 15 );
//strncat(recfile, "\\recfile.ini", 15 );
if (FileExists(recfile))
{
TIniFile* RecFileIni;
RecFileIni = new TIniFile(recfile);
RecFile>Caption = RecFileIni>ReadString(" ",
" 1", "");
delete RecFileIni;
}
//int FileRecFile;
//if ( ( FileRecFile = FileOpen(recfile, fmOpenRead) ) > 0 )
//{
//int iFileLength = FileSeek(FileRecFile,0,2);
//FileSeek(FileRecFile,0,0);
//char* pszBuffer = new char[iFileLength+1];
//FileRead(FileRecFile, pszBuffer, iFileLength);
// RecFile>Caption = AnsiString(pszBuffer);
// FileClose(FileRecFile);
//}
}

, . ,
, .
, . 
recfile,
( ).

FileExists. ,
FileRead, FileOpen ., ,
. true, . 
, , .
RecFileIni,
TIniFile. , 
recfile.
ini. RecFileIni
, ,
FileOpen fopen. .
1 ( , 
keys),
( , section), ReadString
RecFileIni, .
, ini,
, ,
RecFileIni .
ReadString , . , 
.

30.3.

347

, ini 
RecFile 
. !
, , ini ,
, . .
RecFile
.
UpdateRecFile (
):
void __fastcall TMainForm::UpdateRecFile(AnsiString FName)
{
TIniFile* RecFileIni;
RecFileIni = new TIniFile(recfile);
RecFileIni>WriteString(" ", " 1", FName);
delete RecFileIni;
//int FileRecFile;
//FileRecFile = FileCreate(recfile);
//char* cp = new char[ FName.Length() + 1 ];
//strcpy( cp, FName.c_str() );
//FileWrite(FileRecFile, cp, FName.Length() + 1);
//FileClose(FileRecFile);
}

,
RecFile. . , 
.
RecFile, . 
,
.
, , recfile , 
, , , .
WriteString
FName, , ,
UpdateRecFile . 
, . ,
, .
.
ini. , ,
, . , 
, . , , 
, . , 
.
, , ,
.. , , 
,
. ini ,
(. 30.18).


348

30

. 30.18 ini

. 
.
, 
. ,
, ini
.
.

? , , .
FormClose. :
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction
&Action)
{
if ( CheckChange() ) Action = caNone;
TIniFile* RecFileIni;
RecFileIni = new TIniFile(recfile);
RecFileIni>WriteInteger("", "", Top);
RecFileIni>WriteInteger("", "", Left);
RecFileIni>WriteInteger("", "", Height);
RecFileIni>WriteInteger("", "", Width);
delete RecFileIni;
}

, .
WriteInteger, 
, WriteString. ,
, .
Top, Left . ,
 . 
MainForm. FormClose 
TMainForm ,
, . 
.
. 
.
MainUnit.cpp. , ,
 .

30.3.
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
ForceCurrentDirectory = true;
GetCurrentDirectory(256, recfile );
strncat(recfile, "\\recfile2.ini", 15 );
if (FileExists(recfile))
{
TIniFile* RecFileIni;
RecFileIni = new TIniFile(recfile);
RecFile>Caption = RecFileIni>ReadString(" ",
" 1", "");
Top = RecFileIni>ReadInteger("", "", 0);
Left = RecFileIni>ReadInteger("", "", 0);
Height = RecFileIni>ReadInteger("", "", 0);
Width = RecFileIni>ReadInteger("", "", 0);
delete RecFileIni;
}
}

349

. ReadString
, ReadInteger 
. ini 
.
.
( 
), 
, , 
, .
, ini
, , 
WindowState, , ,
, ..
. : ,
. 
wsNormal. ,
( ). FormClose
:
RecFileIni>WriteBool("", "", WindowState == wsMaximized);

WriteBool WriteString WriteInteger.


0 1,
false true.
WindowState wsMaximized. 
, :
Top = RecFileIni>ReadInteger("", "", 0);
Left = RecFileIni>ReadInteger("", "", 0);
if ( RecFileIni>ReadBool("", "", false))
WindowState = wsMaximized;


350

30

else
{
Height = RecFileIni>ReadInteger("", "", 0);
Width = RecFileIni>ReadInteger("", "", 0);
}

, ;
, , .
, . , ... .
ini .
.

30.4.
, . ,
( methods TRichEdit) 
TRichEdit Print. ,
, ,
. ,
. 
( , .), ,
.
, 
. , 
, 
.
. ,
, . 
, , 
. 30.19.

. 30.19

30.4.

351

Exit, RichPrint. 
, . 
, ExitClick, . 
, , :
Application>Terminate();

, 
. 
. Application,
MainForm. ExitClick :
void __fastcall TMainForm::ExitClick(TObject *Sender)
{
MainForm>Close();
}

Close, MainForm,
FormClose, . 
.
RichPrintClick. ,
, (
) Print:
void __fastcall TMainForm::RichPrintClick(TObject *Sender)
{
RichEdit1>Print(MainForm>Caption);
}

Print , 
. 
. 
RichPrintClick
. ,
() 
. , :

.
.
C++ Builder 
. Dialogs
, . 30.20.
, , 
, , 
.
. 30.20
PrinterSetupDialog1. RichPrintClick

:
void __fastcall TMainForm::RichPrintClick(TObject *Sender)
{


352

30

if (PrinterSetupDialog1>Execute())
RichEdit1>Print(MainForm>Caption);

Execute
(. 30.21). .
, Execute false
. true 
Print. ,
, . ,

, .

. 30.21

, 
, 
Dialogs .
, . 
. 
, , ,
, (. 30.22). 
Name : Find,
Replace, RichFont. Find 
RichEdit1.
Dialogs , . 30.23. 
, 
. 
. , ,

30.4.

. 30.22

353

. 30.23

. (
Find Next, Windows), , 
. 
.
.
. 
..
(. 30.24),
,
.

. 30.24

, 
, . 
Options FindDialog1 
true , Hide
() . . 30.25.
.
, , :
void __fastcall TMainForm::FindClick(TObject *Sender)
{
FindDialog1>Execute();
}

, 
Execute.
?


354

30

, .
OnFind
Events FindDialog1. FindDialog1Find,
,
RichEdit1.
RichEdit1, 
. :
int __fastcall FindText(const System::AnsiString SearchStr, int StartPos,
int Length, TSearchTypes Options);


? SearchStr 
, .
FindDialog1. 
,
, FindText.
.
StartPos , 
.
RichEdit1 ,
. 
,
.
0,
1 .. ,
FindText ,
. ,
0,
, 
.
, 
. 30.25
,
, , 
FindDialog1Find FindText , 
, .
,
.
Length. , 
. StartPos 5, Length
10, 5 15 .
, .
FindText , 
(
). FindText 1, 
, . .

30.4.

355


RichEdit1. SelStart ,
SelLength . , 
, SelStart ,
FindText, SelLength .
, StartPos FindText.
, . ,
, .
.

,
, , 
. ,
.
. ,
FindClick :
void __fastcall TMainForm::FindClick(TObject *Sender)
{
RichEdit1>SelStart = 0;
RichEdit1>SelLength = 0;
FindDialog1>Execute();
}

,
. .
, FindDialog1Find :
void __fastcall TMainForm::FindDialog1Find(TObject *Sender)
{
int StartPos, SearchLength, FoundPos;
if (RichEdit1>SelLength)
StartPos = RichEdit1>SelStart + RichEdit1>SelLength;
else
StartPos = 0;
SearchLength = RichEdit1>Text.Length()  StartPos;
FoundPos = RichEdit1>FindText(FindDialog1>FindText, StartPos,
SearchLength , TSearchTypes());
if (FoundPos == 1)
Application>MessageBox(" ", "", MB_ICONSTOP);
else
{
RichEdit1>SetFocus();
RichEdit1>SelStart = FoundPos;
RichEdit1>SelLength = FindDialog1>FindText.Length();
}
}

, ( 
), . , ,
 .


356

30

,
SelLength. , , , , 
StartPos 0.
FindText .
 ,
StartPos ,
SelStart SelLength. , .
.
SearchLength. (
Length, Text) .
FindText.
FindText , 
, ( ), 
. , FindText,
FoundPos.
FoundPos 1,
, , 
. 1, ,
. , SelStart SelLength.
( ) , 
SetFocus. , ,
, . ( 
Windows) , 
, .
Windows ,
.
, . , , ,
, 
. . 
, , 
.
Dialogs
. 30.26
(. 30.26).

, .

ReplaceDialog1. ,

, ReplaceClick. 

FindClick:
void __fastcall TMainForm::ReplaceClick(TObject *Sender)
{
RichEdit1>SelStart = 0;
RichEdit1>SelLength = 0;
ReplaceDialog1>Execute();
}

,
.

30.4.

357

.
ReplaceDialog1, . 30.27.
Events, 
(. 30.28).

. 30.27

. 30.28

. ,
OnClose OnShow , , .
OnFind OnReplace. 
, . , ,
OnFind ( , 
). , 
OnReplace. 
. ,
OnReplace , 
.
, , , . . 30.27 
frReplace frReplaceAll,
false. , ,
, . false ,
Options. 
, . ,
, OnReplace,


358

30

Options frReplace. frReplaceAll .


, :
frReplace ; frReplaceAll . , , 
OnReplace, , 
. .
,
, . , 
, OnFind, ,
FindDialog1Find, :
void __fastcall TMainForm::ReplaceDialog1Find(TObject *Sender)
{
int StartPos, SearchLength, FoundPos;
if (RichEdit1>SelLength)
StartPos = RichEdit1>SelStart + RichEdit1>SelLength;
else
StartPos = 0;
SearchLength = RichEdit1>Text.Length()  StartPos;
FoundPos = RichEdit1>FindText(ReplaceDialog1>FindText, StartPos,
SearchLength , TSearchTypes());
if (FoundPos == 1)
Application>MessageBox(" ", "", MB_ICONSTOP);
else
{
RichEdit1>SetFocus();
RichEdit1>SelStart = FoundPos;
RichEdit1>SelLength = ReplaceDialog1>FindText.Length();
}
}

, , FindDialog1Find
( FindDialog1 ReplaceDialog1). 
, OnReplace. .
, ,
, ReplaceDialog1Find,
,
:
RichEdit1>SelText = ReplaceDialog1>ReplaceText;

ReplaceText ReplaceDialog1
. SelText RichEdit1
.
,
, . 
ReplaceDialog1Find ReplaceDialog1Replace,
.
, 
frReplaceAll , true, 
. , ,

30.4.

359

. frReplaceAll 
Options. , .
, , 

.
: ; ,
( , ); 
( , ).
, ReplaceDialog1Replace :
void __fastcall TMainForm::ReplaceDialog1Replace(TObject *Sender)
{
int StartPos, SearchLength, FoundPos;
start:
if (RichEdit1>SelLength)
StartPos = RichEdit1>SelStart + RichEdit1>SelLength;
else
StartPos = 0;
SearchLength = RichEdit1>Text.Length()  StartPos;
FoundPos = RichEdit1>FindText(ReplaceDialog1>FindText, StartPos,
SearchLength , TSearchTypes());
if (FoundPos == 1)
{
Application>MessageBox(" ", "", MB_ICONSTOP);
ReplaceDialog1>Options >> frReplaceAll;
}
else
{
RichEdit1>SetFocus();
RichEdit1>SelStart = FoundPos;
RichEdit1>SelLength = ReplaceDialog1>FindText.Length();
switch(Application>MessageBox(" ?", "",
MB_YESNOCANCEL | MB_ICONQUESTION))
{
case IDCANCEL:
goto end;
case IDYES:
RichEdit1>SelText = ReplaceDialog1>ReplaceText;
}
}
if(ReplaceDialog1>Options.Contains(frReplaceAll)) goto start;
end:
}

, . start 
, ( ..) 
. frReplaceAll.
Contains , ,
if: Options
ReplaceDialog1 frReplaceAll? , 
start, .


360

30

. ,
.
>> frReplaceAll Options (
). ,
.
. ,
. switch ,
. (case)
( IDCANCEL)
end . , .
( IDYES), 
. 
frReplaceAll. case
,
frReplaceAll.
, . , , ,
, 
. . 
. , . .
,
, 
(. 30.29). , ,

. 30.29

30.4.

361

, 
, . , 
,
.
 ,
.
RichEdit1 HideSelection ( ).
, 
. 
. , , , , ,
,
HideSelection true. false
.
. , , .
. 
Dialogs , . 30.30.
,
. FontDialog1. , 
,
:
void __fastcall TMainForm::RichFontClick(TObject *Sender)
{
FontDialog1>Execute();
}

.
, . 30.31.

. 30.30

. 30.31


362

30

. , ,

. , ,
, .
. , 
. ,
.
rtf, . 
, 
( , 
). ,
ini , 
. 
, ini. 
.
FontDialog1, ,
, , OnApply.
:
void __fastcall TMainForm::FontDialog1Apply(TObject *Sender, HWND Wnd)
{
RichEdit1>Font = FontDialog1>Font;
}

OnApply ,
. Font FontDialog1 
, .
,
. FontDialog1Apply Font
FontDialog1 ( ) 
Font RichEdit1. 
(. 30.32). ,
.

. 30.32

30.5.

363

, ,
, ,
. .
. 
, 
.
Execute,
, true,
. , . 
, RichFontClick :
void __fastcall TMainForm::RichFontClick(TObject *Sender)
{
if( FontDialog1>Execute() )
RichEdit1>Font = FontDialog1>Font;
}


, .

30.5.
.
(. 30.33).

. 30.33


. , 
. 
, , 
, .
File New. New Items, 
Forms (). About box.
, About Box.


364

30

. 30.34

about.cpp. 
, . , , 
.
, , 
. , TPanel 
Panel1. ? ? 
, , . , ,
. , 
, . 
. ,
.
, , 
.
, ,
, :
void __fastcall TMainForm::RichAboutClick(TObject *Sender)
{
AboutBox>ShowModal();
}


AboutBox MainForm. 
29, .
.

30.5.

365

,
( hlp),
Windows, . ,
Microsoft, Microsoft Help Workshop ++ Builder (
Borland ++).
, , .
 C++ Builder.
, ,
, :
void __fastcall TMainForm::RichHelpClick(TObject *Sender)
{
Application>HelpFile =
"E:\\builder5\\CBuilder5\\Examples\\DBTasks\\MastApp\\mastapp.hlp";
Application>HelpCommand(HELP_CONTENTS, 0);
}

, ,
Windows.
, , ,
, .
.
. 
.
C++ Builder Project Options. 
. Application () . . 30.35.
Browse
. 
RichHelpClick , C++ Builder ,
Project3.cpp. Application (
Title) . , , , Windows
, , .
. ,
, , C++ Builder (. .
30.35). Load Icon ( ),
.
, 
, .
, . ,
. .
Win32
(. 30.36).  .
, ,
RichEdit1.
(. 30.37). , 
, , , ,


366

30

. 30.35

. 30.36

, .
ToolBar1 Align
() alTop alLeft. 
. , .
? , , .
, . 30.31,
New Button (
) . . 30.38.
, , .
. ToolButton1 
TToolButton. , ,
TButton.
( Name) BOpen. ,
. ImageIndex, 
,  () .
, ImageIndex. C++
Builder, .
TToolButton, ImageIndex. 
, (images list)
TToolBar .
TToolBar , .

30.5.

. 30.37

. 30.38

367

. 30.39

ToolBar1 Images, 
. : TToolBar
Images. ,
TToolBar. 
, , Images, 
 TImageList.
,
TImageList.
,
, . ,
Win32. , .
. 
. ,
. , 
, , , . 
, . 
,
,
.
ImageList1.
ImageList1 . , , 
, Image List
Editor. , , 
. 30.40. 
, ( ) ,
.


368

30

Add (
). , 
. ,
. , C++ Builder ,
, , , :
E:\builder5\CBuilder5\Examples\MFC\General\Cmnctrls\Res

, 
. toolbar.bmp, 
, (. 30.41).

. 30.40

. 30.41 ,


. , ,
. , ?
. 
Add Images ( ), 
. C++ Builder , .
, : , C++
Builder, ,
. , C++ Builder , 
. 30.42.
,
( , , 
), C++ Builder 
. Yes to All ,
. C++ Builder 

30.5.

369

. 30.42

Yes. , Yes.
ImageList1 (. 30.43).
( 0) ,
. ImageIndex. 
( Options) , 
, ToolBar1. , 
Images ,
ImageList1. 
, Images ImageList1 (. 30.44).

. 30.43

, ,
, (. 30.45).
. 
? , ?
BOpen. ImageIndex 
0. , ,
0 . ,
BOpen, , ?
BCreate.


370

30

. ,
Transparent Color
( ) clWhite () . . 30.43.
, ,
. , 
, .
Clear, , Add 
. , . 
? :
, 
Selected Image ( ) 
. , ,
, 
. 
, clSilver (). ( 
ImageIndex BCreate) .
, 
1616 , 1516.
. . 30.46.

. , .
Events BCreate, OnClick
. , 
(. 30.47).

. 30.46

. 30.44

. 30.45

. 30.47

30.5.

371

CreateClick 
. , 
, .
ShowHint ( ) BCreate c false
true, Hint , ,  , 
.
.
. , ImageList1
, Delete (.
. 30.43). , ,
New Separator ( ) . . 30.38. 
,
.

. Win32
StatusBar , . 30.48. ,
 . 
. ,
,  . 30.48

( ) 

, .
 , 
SimpleText (
StatusBar1). , SimplePanel
StatusBar1 true. ,
.
, .
? (. 29.4)
. ,
Interval 1000 1 .
 OnTimer Timer1Timer. 
.
, . MainUnit.h 
public :
int sessiontime, shours, sminutes, ssecs;

( ), 
, ,
. MainUnit.cpp 
sessiontime:
sessiontime = 0;

Timer1Timer :
void __fastcall TMainForm::Timer1Timer(TObject *Sender)


372

30

sessiontime++;
shours = sessiontime/3600;
sminutes = (sessiontime  3600*shours)/60;
ssecs = sessiontime  3600*shours  60*sminutes;
StatusBar1>SimpleText = " : " + IntToStr(shours) +
" ., " + IntToStr(sminutes) + " ., " +
IntToStr(ssecs) + " .";
}

. (
) sessiontime. , 
. , 
. , .
, Word
2001 C++ Builder , . 30.49.
, .
, 
. (. 30.50).
, , .
, 
, ,
Word.

. 30.49
C++ Builder

. 30.50


31

!
.

, 
. , ...
. , , 
.., . Borland

, 
.
. , C++ Builder
.
, 
. , 
, , 
, . .
,
, , .
, 
, C++ Builder. 
C++ Builder 5, ,
(Professional Enterprise) , . ,
. , ,
.


374

31


C++ Builder,
. C++ Builder.
, , C++ Builder
. , 
Data Access Data Controls. ,
Tools Database Desktop. (
), Windows ( ). , 
C++ Builder, Database Desktop BDE Administrator.
!  ,
C++ Builder, , .
.

31.1.
, , , , 
, . 
Microsoft Access. 
, C++ Builder, ,
C++ Builder . 
. , ,
, .
, ,
C++ Builder.

Microsoft Access, FoxPro,
. , C++ Builder 
. , , .

,
, (. . 16.10). C++
Builder , Database
Desktop. Database Desktop
Windows Tools C++ Builder.
Database Desktop
, , , 

. Database Desktop ,
C++ Builder . 
,
.
, File New Table ( ). 

(. 31.1).

31.1.

375

. 31.1

, , C++ Builder
. Paradox 7,
, . 
dBase MS Access, .
, ,
Paradox 7 .
, 
. 31.2.

. 31.2

. , 
.
, . ,
. , 
. , 
(field), .


376

31

, 
(. . 16.10). ,
, () . 
, , .
, . 
. . 31.2 ,
. Field Name ( )
. , 
Name. Type.
, . 
, (. 31.3).
, ,
, , ,
. ,
Paradox 7. Alpha
. ( 
) Size ().
.
, . . 31.2
, 25 
, ,
1 256 
. , 
, 40.
Key .
, Enter, 
.
Phone, , 
Name. , 
(. . 18.7).
.
, ;
, , Paradox
. 31.3
Paradox 7
.
Photo Graphic.
. , , . 31.4.
 , 
. , , .
, , , 
. ,
, Table properties ( ),
. Table Language
( ). Modify (
). ,
. , , Paradox ascii.

31.1.

377

. 31.4

, . , 
?
Pdox ANSI Cyrillic. ,
. 31.4. ,
, ,
Paradox ascii. , 
(
), Database Desktop, BDE Administrator
Windows. 
Configuration, : Drivers Native Paradox.
Paradox. 
LANGDRIVER Pdox ANSI Cyrillic.

C++ Builder ( C++ Builder Database
Desktop). Database Desktop ,
.
.
Save As 
. WorkDir. ,
Projects, ,
Project4 ()
telephone. db .
Paradox ,
. , , 
, 
. , telephone.db
, . 
Database Desktop,
, ,
.
, , File Open
Table telephone.db.
, .
, Table Edit Data. 
(. 31.5).


378

31

. 31.5

. 16.10, 
. , , 
. . 
, Phone.
! , ,
, . ,
Table Restructure ( ). , 
.
. Edit
Preferences General ( ). General 
.
, Database Desktop 
, . Change 
, Cyr.
, ,  
,
. , 
Database Desktop (
), Database Desktop. , 
(. 31.6).

. 31.6

31.1.

379

,
Photo. BLOB Graphic. BLOB 
Binary Large Object () .
Paradox ,
, , ..
Database Desktop , 
( ). ,
. , Paradox, 
.
, , Database Desktop 
, . ,
, .
.
Alias. , . 
, (, , 
)
. , , 
.
. Database
Desktop, Tools Alias Manager (
). (. 31.7).

. 31.7

. , New.
Database alias , , ,
telephone. (Driver type) STANDARD,


380

31

. C++ Builder STANDARD 


, , Paradox.
Path () . 
, .
Browse Directory Browser ()
Drive , ,
OK.
, , 
. , 
IDAPI.CFG. 
. .
Database Desktop . ,
,  
. , 
, . 
, .
: ?
, , , 
telephone.db c telephone,
. (
telephone.db), 
, Database Desktop.
,
, , ,
Project4.

31.2.
C++ Builder File New Ap
plication. ,
Project4, bpr Project4.bpr, 
.
. 
, C++ Builder ( ),
, , Borland
C++ BDE.
, . BDE Borland Database
Engine ( Borland).

,
, telephone.db, , 
(, ) . 
.
, ,

31.2.

381

BDE. 
, 
.
, , 
BDE. 
Data Access ( ) Data Controls ( 
).
BDE . 
, 
.
DataSourse
( ) Table (). 
, . , . 20.4,
, Borland C++,
.

. ,
. 31.8 31.9,
.
. 31.9
. 31.8

Table1 TTable DataSource1 


TDataSource
TTable
TDataSource. Table1 
, .
DatabaseName ( ). 
, , 
. 
, . ,
 
, 
( ). ,
DatabaseName, , ,
telephone.
TableName ( ). 
,
Table1 ,
. 
, TTable.
TableName .
telephone.db. .
Active ().
false, Table1 .
C++ Builder 
,
true. ,


382

31

false
true  .
Table1 
. 
DataSource1. ,
DataSet ( ). , 
. Table1.
, . : 
telephone.db BDE Table1
DataSource1 .
telephone.db, ,
, , 
, telephone.db. , 
. , .
Data Controls 
. , . 20.4,
( ), . 31.10.
,
. 20.4. C++ Builder DBGrid1, 
TDBGrid. Grid ,
,
Database Desktop. 
, ,
Name .

.
DataSource DBGrid1 .
DataSourse1, .
, telephone.db 
DBGrid1. ,
DBGrid1 ! , 
, TDBGrid 
. Name.
. 
DBGrid1
Columns Editor Columns
DBGrid1 .
Columns Editor ( )
. . 31.11.
Add New (
), 0 TColumn. , 
, DBGrid1. 
FieldName ( ), ,
,

31.2.

383

. Name . ,
Name .

. 20.4. Options ()
DBGrid1, . 
( ).
dgTitles false Name .
dgIndicator false 
. 
, dgRowLines false. 
,
( Width ).

, . 20.4. , 
. Data Controls 
TDBEdit (. 31.12).
. DBEdit1
TDBEdit. ,
DBEdit1. AutoSize false, 
. DataSource,
( ) DataSource1. DataField,
( ) Phone ,
. 
, DBEdit1 .
. 
, ! ,
, , ,
. , 
, , , . 
, 
DataSource1.
, 
. Data Controls

. 31.10

TDBGrid

. 31.11

. 31.12

TDBEdit

. 31.13

TDBImage


384

31

TDBImage (. 31.13). , 
DataSource DataSource1, DataField
Photo. ,
. , ,
DBImage1. ,
. 20.4, 90120 
DBImage1, Width Height.
. ,
DBGrid1 
, . , 
, ,
. Database Desktop,
Table Restructure. , 
. C++ Builder ,
. table is in use
( ). , 
. , 
Active Table1 false,
, , .
Table Restructure.
(. . 31.4) Key ( )
. .
.
( , Paradox). ,
, ,
; , 
. , .
Save, ,
Database Desktop .
(), , 
. , , , 
.
C++ Builder Active Table1
true . 
. , ,
,
, .
, :
, .
, Options DBGrid1
dgAlwaysShowSelection true. ,
.

.

31.2.

385

, 
:

1. /
(, ACD See).
2. Ctrl+C.
3. , 
Ctrl+V.
.
Paradox bmp, pcx, tif, gif
eps. mb (
telephone.mb). , , ,
, , .
DBImage1 . , . 20.4,
. . 31.14 
, C++ Builder.
, AddPhoto,
, , AddPhotoClick.
? , 
, ,
( ).
C++ Builder.
, Dialogs, , . 31.15.

. 31.14

. 31.15


. , OpenPictureDialog1.
Title , 
, .
Filter.
, () ,


386

31


. , 
Paradox. ,
. TDBImage
bmp, ico, wmf emf. , , 
,
bmp. . , 
. 31.16, .
AddPhotoClick 
:
void __fastcall TForm1::AddPhotoClick(TObject *Sender)
{
if ( OpenPictureDialog1>Execute())
{
DBImage1>Picture>LoadFromFile(OpenPictureDialog1>FileName);
DBImage1>CopyToClipboard();
DBImage1>PasteFromClipboard();
}
}

, . , 
, (. 30.1),
OpenPictureDialog1 Execute.
.
Execute true ,
. 
if.
DBImage1.
Picture LoadFromFile
OpenPictureDialog1 .
FileName OpenPictureDialog1.

. 31.16

31.2.

387

, ;
OpenPictureDialog1 ,
.
AddPhotoClick, : 
DBImage1, 
, .
, (
Ctrl+V), : 
CopyToClipboard
PasteFromClipboard. ,
, *.
,
. 31.16, .
. 
? , ,
. ,
Ctrl+X. . , 
DelPhoto, DelPhotoClick.
:
void __fastcall TForm1::DelPhotoClick(TObject *Sender)
{
DBImage1>CutToClipboard();
}

Windows , Ctrl+X,
.
DBImage1 . 
, .
. ,
 . , 
DBImage1
, , , 
? :
* , :
void __fastcall TForm1::AddPhotoClick(TObject *Sender)
{
if ( OpenPictureDialog1>Execute())
{
Table1>Edit();
DBImage1>Picture>LoadFromFile(OpenPictureDialog1>FileName);
Table1>Post();
}
}

Table1>Edit() ( )
, , Table1>Post() 
. . . .


388

31

, , C++ Builder.
,  
, , C++ Builder.
, .
.
, Standard
(. 31.17). 
PopupMenu1. ,
, 
. , 

. 
. 31.17
Word2001. (

Name) N1 N2. 

, ,

.
, , N1Click
N2Click. , 
:
void __fastcall TForm1::N1Click(TObject *Sender)
{
AddPhotoClick(Form1);
}
void __fastcall TForm1::N2Click(TObject *Sender)
{
DelPhotoClick(Form1);
}

.
PopupMenu DBImage1, 
, .
PopupMenu1. . ,
, .
PopupMenu PopupMenu1, 
.

31.3.

, . 20.4 ( , 
), . 
, . ,
. , , 
. ,
telephone.txt ,
. .

31.3.

389

, ()
telephone.db, . , Paradox
, db.
, DatabaseName Table1,
. (
TableName Table1) telephone.db. 
, , ,

telephone.db. ( true)
, , 
DatabaseName 
Table1. , , 
telephone.db,
. , .
, , 
. ,
C++ Builder, Active Table1 true
( ), Database
Desktop. , , 
C++ Builder, . 
, : Active
Table1 false,
( true), , , 
, , Active
Table1 true.
Active Table1 false. 
,
.
Form1 
( Events). : OnCreate 
, OnDestroy . ,
, ,
:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Table1>Active = true;
}
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
Table1>Active = false;
}

Active false. 
, , . OpenBase.
,
Word2001 ( Dialogs ).


390

31

( Name) OpenDialog1,
Title (, ) , 
. , OpenBase. 
:
void __fastcall TForm1::OpenBaseClick(TObject *Sender)
{
if ( OpenDialog1>Execute())
{
Table1>Active = false;
AnsiString BaseName = OpenDialog1>FileName;
BaseName.SetLength(BaseName.Length()12);
Table1>DatabaseName = BaseName;
Table1>Active = true;
}
}

, 
. OpenDialog1
Execute. telephone.db, 
, .
, 
Active false. 
.
BaseName AnsiString ,
FileName OpenDialog1, 
telephone.db. .
BaseName 
:
E:\builder5\CBuilder5\Projects\Project4\telephone.db

DatabaseName ,
:
E:\builder5\CBuilder5\Projects\Project4\

, 
. Length ( ) ,
. BaseName,
, .
12 telephone.db (
, ).
BaseName SetLength. BaseName
12
.
,
. , 
.

31.3.

391

BaseName , 
DatabaseName Table1
, Active true.
. 
. , ,
( ,
).
.
. 
. ,
. 31.18

. .

Additional ( ) 
(. 31.18). ,
. 
C++ Builder. Borland C++ 
, C++ Builder,
Image Editor, , 
C++ Builder, . C++ Builder
Tools Image Editor ( ).

, . .
Image Editor, File New Bitmap File. 
. ,
. , Height 
25, 2020 . 
16 . 
,
Bitmap Image Properties ( ).

. File Save
plus.bmp Project4, . 
. .
, AddAbonent, 
. Glyph. 
, , 
Picture Editor. Load,
, 
. , Image Editor, 
.
(,
, ), Layout. ,
. 
, . ,
, :


392

31

void __fastcall TForm1::AddAbonentClick(TObject *Sender)


{
Table1>Insert();
}

. , 
. , 
, .
, 
. ,
. 
, , .
 , 
.
, , ? 

. ,
.
. 
File New Form. , 
. 31.19: , TEdit . 
, , .
,
, . 
,
,
ModalResult:
mrOK, mrCancel.
Unit1.cpp 
Form2: File
. 31.19
Include Unit Hdr Unit2. 

AddAbonentClick 
:
void __fastcall TForm1::AddAbonentClick(TObject *Sender)
{
Form2>Edit2>Text = "_";
if(Form2>ShowModal() == IDOK)
{
if(Form2>Edit1>Text.IsEmpty())
Application>MessageBox(" ",
" ", MB_ICONWARNING);
}
else
{
if(Form2>Edit2>Text.IsEmpty())
Form2>Edit2>Text = "_";
Table1>InsertRecord(ARRAYOFCONST((Form2>Edit1>Text,

31.3.
Form2>Edit2>Text)));

393

}
}

? . ,
( ) ,
. Form2 ,
( Text Edit2 
Form2) . 
,
. , 
.
() ShowModal .
,
, ,
. . ,
, 
, , IDOK.
, . , .
,
. , , ,
, 
, . 
? ,
. , 
IsEmpty, empty,
MessageBox.
AddAbonentClick .
 , . 
.
, ,
( , ), 
Text . ,
.
, ,
InsertRecord. ,

. . 
InsertRecord , , ,
.
, . 
, .
, .
Image Editor , , ,
( DelAbonent), :
void __fastcall TForm1::DelAbonentClick(TObject *Sender)


394

31

Table1>Delete();
}

Delete . , , 
, . , 

, , :
void __fastcall TForm1::DelAbonentClick(TObject *Sender)
{
AnsiString message = " " +
DBGrid1>SelectedField>Text + "?";
if(Application>MessageBox(message.c_str(),
" ", MB_YESNO |MB_ICONQUESTION) == IDYES)
Table1>Delete();
}

AnsiString ,
+.
message . ,
,
.
AnsiString ,
MessageBox char, 
c_str(), .
. , ,
, .

Close, . Form1, 
(. 31.20).
. , , , 
, , . , ,
, . ,

. 31.20

31.4. Borland C++

395


,
. , , ,
DBImage1, . ,
.
 , : 
, . ,
DBImage1, Visible.
,
DBImage1, 
Visible. .
, , , 
. 
Visible, 
. DBImage1 Color () ,
, clBtnFace. , , BorderStyle ( )
bsNone. 
, , .
Borland
C++. , , C++ Builder.

31.4. Borland C++


, . , 
, Database Desktop Borland
C++ 5, Borland C++
. Borland C++ BDE Administrator,
BDE Configuration Utility,  , 
. ,
31.1 , ,
Database Desktop, ,
31.1. Database Desktop 
31.1, ,
Paradox . telephone.db
telephone.
Borland C++
. , 
. 31.2,
Borland C++ 
C++ Builder, , ,
*. : Controls Data
* , C++ Builder, ,
, Borland C++, Delphi ( VCL 
Object Pascal, C++), Borland C++ 
. . . .


396

31

Access Data Aware. (


Borland C++), BDE 
, . 
. Borland C++
Visual Database Tools Help .
Data Access TTable 
TTable (. 31.21). , 
,  . , 
. Properties
(). ... !
Property Inspector ( ), , 
(. 31.22).
31.2, , 
TTable ( 
C++ Builder) Active, DatabaseName TableName. c Active
true. DatabaseName, ,
, ,
telephone.
TableName telephone.db.
3 Controls
TDataSource (. 31.23), 
.
, Properties DataSet 
TTable1 
. 
. , ,
DataSource ( 
) TDataSource1 .
TDBGrid 
, 
( ). Data Aware
TDBEdit
(. 31.24). :
, . . 31.27
, TDBEdit. 
Properties
DataSource DataField. 
, , TDataSource1.
DataField Name, 
Phone. .
, , . 
, , FontName  ; ,
, 
.
, . ,
System,  .

31.4. Borland C++

. 31.21

TTable

. 31.22

397

. 31.23
. 31.24

TDBEdit
TDataSource

, 
TDBImage (. 31.25). , 
. , . 31.27. DataSource
TDataSource1, DataField. Photo.
BackColor 
, , ,
. , ,
, ,
, ... .
, CtlName . 
, . , 
.
, 

.
. Controls TDBNavigator
(. 31.26). ,
. 31.27. .
TDataSource1 DataSource.
, , ,
Btn, .
On .
 Off
, , 
.


398

31

. 31.25 . 31.26

TDBImage TDBNavigator

. 31.27 ,

( ) 
, (. 31.27).

, . 
, .
Borland C++, C++ Builder 
,
MFC,  . 
, ,
, ,
, , ... , 
.


32

,
?
.

. , ,
, 
, Made by . ,
. ,
,
, C++ Builder . ,
.
, . 
, . , , 
, .

32.1.
Word2001 
TRichEdit. 
TCppWebBrowser. .
, browser
( 1 ), 
Unit1.cpp . 
Internet, , 
(. 32.1).
.


400

32

CppWebBrowser1, 
Align.
, 
. 32.1
( ,
), Align

alClient TRichEdit 
TCppWebBrowser
.
TCppWebBrowser C++ Builder
. , , Microsoft
Internet Explorer ( , 
), Windows SHDOCVW.DLL 
TCppWebBrowser . ,
TCppWebBrowser , 
, . Microsoft Internet Explorer.
. Microsoft Internet Explorer
4, , , . 
, .
, , .
, , 
, .
. Microsoft, 
, (
, Internet Explorer ).
. , ,
CppWebBrowser1. ,
(. 30.2): Items,
, .
( Caption) File ( Name).
( FileOpen) ( FileExit).
 , Internet? 
html 
. , , 
OpenDialog1,
htm html. ,
( FileOpenClick),
:
void __fastcall TForm1::FileOpenClick(TObject *Sender)
{
if ( OpenDialog1>Execute() )
CppWebBrowser1>Navigate(WideString(OpenDialog1>FileName));
}

. , , 
. : 
, , 
CppWebBrowser1 Navigate. ,

32.1.

401

Navigate 
, ,
Internet. , , 
, . (
) . 
,
Internet.
Navigate
, Navigate,
AnsiString. WideString.
. 
AnsiString, FileName
OpenDialog1, WideString WideString, 
.
? . .
OpenDialog1 txt. ,
. 
, . 
, CppWebBrowser1 ? .
, 
, . , Internet Explorer
. ?
. CppWebBrowser1 .
TRichEdit 
TCppWebBrowser1, 
TRichEdit. 
.
TRichEdit ( RichEdit1), 
Align alClient, RichEdit1 
. , 
?
. , , , 
. 
, Visible, ,
, true.
, . , RichEdit1 
. RichEdit1, CppWebBrowser1
Visible false
. , ? 
 .
FileOpenClick :
void __fastcall TForm1::FileOpenClick(TObject *Sender)
{
if ( OpenDialog1>Execute() )
{


402

32
char* txt = OpenDialog1>FileName.AnsiLastChar();
if(txt[0] == 't')
{
RichEdit1>Lines>LoadFromFile(OpenDialog1>FileName);
RichEdit1>Visible = true;
CppWebBrowser1>Visible = false;
}
else
{
CppWebBrowser1>Navigate(WideString(OpenDialog1>FileName));
RichEdit1>Visible = false;
CppWebBrowser1>Visible = true;
}

}
}

, .
, . 
, 
. t, , 
txt; t, , Internet (
, ).
, .
.
FileName OpenDialog1 
AnsiString, AnsiLastChar() 
. 
txt. , , ,
( AnsiLastChar() ).
( )
txt t. 
: , , 
. , . 
, , ( ,
).
, t, : 
RichEdit1, 
, Visible.
t, : , , 
.
, 
. .
30 StatusBar1 
. ,
SimpleText. 
. 
.

32.1.

403

StatusBar1 ( , 
Align). 
, ,  
. (
Editing StatusBar1) 
Add New ( ). , 
.
, , , 0. 
(), 1, 2 .., 
.
Panels StatusBar1. , 
Width (), ( 
). 50. ,
Text, , 
. ,
. , !
(Hello, World!)  , , >
. , Text
,
.

:
void __fastcall TForm1::FileOpenClick(TObject *Sender)
{
if ( OpenDialog1>Execute() )
{
char* txt = OpenDialog1>FileName.AnsiLastChar();
if(txt[0] == 't')
{
RichEdit1>Lines>LoadFromFile(OpenDialog1>FileName);
RichEdit1>Visible = true;
CppWebBrowser1>Visible = false;
StatusBar1>Panels>Items[0]>Text = " \
";
}
else
{
CppWebBrowser1>Navigate(WideString(OpenDialog1>FileName));
RichEdit1>Visible = false;
CppWebBrowser1>Visible = true;
StatusBar1>Panels>Items[0]>Text = " ";
}
}
}

, , . .
,  Internet.
,
Internet. ,


404

32

, . ,
.
, , 
TEdit . , ,
, , ,

. , , .
TComboBox. ,
, . Standard
ComboBox (. 32.2). ,
.
, ,
ComboBox1. ,
.
, .

( , ).
.
, ComboBox1
, , 
. , . 
. , Align,
, , , .
Anchors (), 
, , 
ComboBox1. ComboBox1
.
, 
(. 32.3).

. 32.2

. 32.3

, , Anchors.
, , 
. 
, akLeft ( ) akTop ( 
) true, false.
, . ,
C++ Builder (, )

32.1.

405

35 , , 
. , 
, , .
, , ,
. akRight akBottom .
, . , 
ComboBox1 ,
, . C++ Builder
akRight ComboBox1 true.
ComboBox1 .
, akRight 
ComboBox1 . 
, .
.
: RichEdit1, Align
alNone, .
RichEdit1, ,
ComboBox1. , ,
,
Top RichEdit1.
Anchors true.
, ,
ComboBox1 ,
. 
. , Anchors. ,
, C++ Builder
. ? ,
.
, , RichEdit1,
, Align alNone,
CppWebBrowser1, .
Unit1.cpp ( ) 
:
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
CppWebBrowser1>Anchors = RichEdit1>Anchors;
}

, .
Anchors RichEdit1 (
true) Anchors CppWebBrowser1.
CppWebBrowser1 true. ,
, C++ Builder , 
, . 
.


406

32

RichEdit1 CppWebBrowser1.
,
, . C++
Builder ,
.
Standard
Panel (. 32.4). Panel1.
, ,
. , 
. TPanel 
. 

, , , , 
.
.
.
( ) ComboBox1. 
Panel1
ComboBox1. Properties Panel1 
Align alTop. Panel1
.
ComboBox1.
( )
Panel2. Align alClient.
, , 
. (. 32.5).

. 32.4

. 32.5

. 
ComboBox1, Panel1. 
true. ComboBox1 
, Panel1.
: RichEdit1 CppWebBrowser1,
. Align alClient.
Panel2. 
,
, ,
Align. , Visible false (

32.1.

407

). , 
. , , , .
RichEdit1 , .
, , ComboBox1.
. . 
? Enter. ,
. ,
, , 
, , 
, . ,
 , . 
C++ Builder , .
ComboBox1
Events. OnEnter. , 
Enter.
OnKeyDown. , 
. ComboBox1KeyDown, 
.  , 
Enter.
ComboBox1KeyDown Key.
, . 
, ComboBox1KeyDown :
void __fastcall TForm1::ComboBox1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_RETURN)
{
CppWebBrowser1>Navigate(WideString(ComboBox1>Text));
RichEdit1>Visible = false;
CppWebBrowser1>Visible = true;
StatusBar1>Panels>Items[0]>Text = " ";
}
}

, , . 
Key Enter,
VK_RETURN. 
, , , Enter 
Return. ... , 
, ComboBox1 (
Text, WideString ,
Navigate. 
. , ,
.
,
.


408

32

, ComboBox1KeyDown
:

. ...
, , .
, .
Items CppWebBrowser1,
. ,
. , , :
http://cborland.nm.ru
http://bk.ru

, 
. ,
. Enter
. Internet Explorer, 
, . ,
.
.
Events CppWebBrowser1 OnChange,
CppWebBrowser1.
ComboBox1Change,
, :
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
CppWebBrowser1>Navigate(WideString(ComboBox1>Text));
RichEdit1>Visible = false;
CppWebBrowser1>Visible = true;
StatusBar1>Panels>Items[0]>Text = " ";
}

, , .
.
, Combo
Box1Change. , , ,
. Internet Explorer ,
, .
. ComboBox1
ItemIndex, , 
. , , 0, 1 ..
, 1. 
,
. ComboBox1Change ,
 ,
( ),  ( ).
. Unit1.h,
public, prevIndex:

32.2.
public:
// User declarations.
int prevIndex;

409

Unit1.cpp, , 
, :
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
prevIndex = 1;
}

ComboBox1Change ,
:
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
if(ComboBox1>ItemIndex != prevIndex)
{
CppWebBrowser1>Navigate(WideString(ComboBox1>Text));
RichEdit1>Visible = false;
CppWebBrowser1>Visible = true;
StatusBar1>Panels>Items[0]>Text = " ";
prevIndex = ComboBox1>ItemIndex;
}
}

, ,
, ItemIndex, 
, prevIndex. ,
, ,
prevIndex ComboBox1Change.
, 
. . 
, , 
Internet
Internet Explorer . ,
, Internet
Explorer. , ,
Windows, . 
Internet Explorer.
, ,
.
, .
.

32.2.
CppWebBrowser1 
, Events .
, ,


410

32

(). , 
. Navigate, ,
CppWebBrowser1 .
, . 
OnDocumentComplete.
, 
. CppWebBrowser1DocumentComplete, 
.
, , , 
. , 
, , 
:
res://C:\WIN98NEW\SYSTEM\SHDOCLC.DLL/dnserror.htm#

Internet,
CppWebBrowser1DocumentComplete, ,
. , .
CppWebBrowser1DocumentComplete :
void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject *Sender,
LPDISPATCH pDisp, TVariant *URL)
{
if((AnsiString(*URL).LowerCase()).AnsiPos(AnsiString("dll/dnserror")))
{
CppWebBrowser1>Visible = false;
RichEdit1>Visible = true;
RichEdit1>Text =" .\n ";
}
else
{
CppWebBrowser1>Visible = true;
RichEdit1>Visible = false;
ComboBox1>Text = AnsiString(*URL);
}
}

, 
. , 
, URL, dll/dnserror. URL 
AnsiString ( ),
LowerCase 
, AnsiPos
, AnsiString. AnsiPos
, ;
, .
, 0, , , , , 
. 
,  
. . 0,

32.2.

411

, , 
.
.
0, else, 
, , . 
. ,
, , (,
),
.
. .
ComboBox1Change Visible ,
CppWebBrowser1DocumentComplete.
.
, , ini. , 
. ini
, :
[ ]
1=http://cborland.nm.ru
2=http://bk.ru

browser.ini browser, ,
.
. 
1, 2, 3 .. 10 . 
, . ,
ini , . Unit.h
. , #include:
#include <IniFiles.hpp>

, ini.
public:
public:
// User declarations
int prevIndex;
char inifile[256];

inifile ini. 
, ini
. ,
Unit1.cpp :
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
prevIndex = 1;
GetCurrentDirectory(256, inifile);
strncat(inifile, "\\browser.ini", 15);
int ifile;
AnsiString str;


412

32

if (FileExists(inifile))
{
TIniFile* FileIni;
FileIni = new TIniFile(inifile);
for(ifile = 1; ifile <=10; ifile++)
{
if(!(str=FileIni>ReadString(" ",
AnsiString(ifile), "")).IsEmpty())
ComboBox1>Items>Add(str);
}
delete FileIni;
}

ini. 
GetCurrentDirectory 
inifile.
browser.ini ( ). : ifile
str 
. , 
inifile. ,  .
, FileIni, 
TIniFile .
, TIniFile 
ini. , FileIni,
, . , , 
. .
, . , , for
:
for( ; ; )

for :
for( = ; < ;
)
{

, , 
, ,
.
, , ( ) .

. , ,
for. 
. 
,
. ,
 .

32.2.

413

.
, .
? 
. 
.
ifile, . ,
for:
for(int ifile = 1; ifile <=10; ifile++)

( 
) . , , 
.
1. ,
10. , 
ifile=10. ifile
. , ifile++
. , 10 ,
ifile.
ini. , ,
1 10,
ini,
. ? .
. , , 
, (
)  , 
. ,
ReadString . 
AnsiString (,
, , , 
, 1). ,
. , 
ReadString , ,
, , ( ),
. ,
, 
str. IsEmpty() 
. (if) ( str)
, (Items) ComboBox1 
Add.
10 ,
ini. ComboBox1
.
FileIni.
browser.ini , 
ComboBox1


414

32

Items .
Sorted. , , false. 
, , 
Add. true,
. false, 
.
. . ,
.
ini, . 
. Internet,
, , .
.

ComboBox1. ,
. , 
, , ,
.
10
browser.ini. 
, , .
, . , 
, , 
. :
void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject *Sender,
LPDISPATCH pDisp, TVariant *URL)
{
if((AnsiString(*URL).LowerCase()).AnsiPos(AnsiString("dll/dnserror")))
{
CppWebBrowser1>Visible = false;
RichEdit1>Visible = true;
RichEdit1>Text =" .\n ";
}
else
{
CppWebBrowser1>Visible = true;
RichEdit1>Visible = false;
int item;
if ((item = ComboBox1>Items>IndexOf(AnsiString(*URL))) > 1)
ComboBox1>Items>Delete(item);
ComboBox1>Items>Insert(0, AnsiString(*URL));
ComboBox1>ItemIndex = 0;
}
}

, , 
. , ,
, .
, ( ) ,

32.2.

415

, , 
.
, AnsiString(*URL).
IndexOf. 
( , ), 
IndexOf , 0 .
, 1. if, 
item, .
, item, Delete
, .
. ,
. , if, 
, .
if .
( ) , 0 
Insert.
(), ( 0),
: AnsiString(*URL). .
,
ComboBox1. .
. ,
ini, FormClose, .
, Form1, Events, OnClose.
10 10
. , 
,
. FormClose :
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
TIniFile* FileIni;
FileIni = new TIniFile(inifile);
for(int ifile = 1; ifile <= 10; ifile++)
FileIni>WriteString(" ", AnsiString(ifile),
ComboBox1>Items>Strings[ifile1]);
delete FileIni;
}

FileIni 
TIniFile ini.
inifile, . 
, , ,
. , .
for. , 
, , , . ,
, , , 
. 1 10,


416

32

, . 
1 10, 0 ,
ifile ifile1. 
FileIni.

browser.ini , , :
[ ]
1=C:\ \intel.html
2=C:\ \Video.html
3=http://cborland.nm.ru
4=http://bk.ru
5=
6=
7=
8=
9=
10=

5 10 , , .
, 
. 10 
, 10 ini. 10
. 
 , , 
,  .

32.3.
Internet, ,
:
Internet Explorer , Netscape Navigator (Com
municator) . ,
, 
.  .
 avi. , , C++ Builder
, , , avi . 
,
:
E:\builder5\Borland Shared\Images\Icons\earth.ico

, .
. 
, , ,

. ComboBox1,
. Image1

32.3.

417

TImage. Image1 ,
ComboBox1. , Image1 
. 
Anchors, . , 
, Align alRight.
. Picture
. , , , 
Image1. Center
true, , . 32.6.

. 32.6

, , ,
. 
Navigate ( ),
. (
CppWebBrowser1DocumentComplete), .
.
,
. Timer1 ( System 
). Interval , , 400
( 0,4 ). Enabled false,

, . Timer1Timer, 
OnTimer , :
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if(Image1>Visible) Image1>Visible = false;
else Image1>Visible = true;
}

Image1, , , 
, . (, ) 
, Navigate :
Timer1>Enabled = true;

, CppWebBrowser1
DocumentComplete :
Timer1>Enabled = false;
Image1>Visible = true;


418

32

. ,
. . 
,
.
, , 
, , 
.
,
. , ,
1. .
, ( ),
:
StatusBar1>Panels>Items[1]>Text = " ...";

, , 
. , 
( ). , , 
0, , ,
( ) Navigate. 
, ,
. , 
Navigate
. .
, .
OnDownloadBegin CppWebBrowser1.
, , :
void __fastcall TForm1::CppWebBrowser1DownloadBegin(TObject *Sender)
{
StatusBar1>Panels>Items[1]>Text = " ...";
}

CppWebBrowser1DocumentComplete
, :
StatusBar1>Panels>Items[1]>Text = "";

. . , , 
, Internet. 
:
, , 
.
, ( , 
) Navigate :
CppWebBrowser1>Stop();


. , 
.

32.3.

419

, ,
, , Internet Explorer,
, .. . 
, CppWebBrowser1 

.
.
, , ,
.
,
, , ,
, , . Back, Forward,
Refresh, Stop.
:
void __fastcall TForm1::BackClick(TObject *Sender)
{
CppWebBrowser1>GoBack();
}
//
void __fastcall TForm1::ForwardClick(TObject *Sender)
{
CppWebBrowser1>GoForward();
}
//
void __fastcall TForm1::RefreshClick(TObject *Sender)
{
CppWebBrowser1>Refresh();
}
//
void __fastcall TForm1::StopClick(TObject *Sender)
{
CppWebBrowser1>Stop();
}

,
, . 
. . 
, 
.
, , (
), , 
, ,
. 
,
OnDownloadBegin, ,
Navigate. ,
CppWebBrowser1DownloadBegin.
, 
, ComboBox1


420

32

, 
. , 
ComboBox1 CppWebBrowser1DownloadBegin. ,
, 
html title. . 
,
Form1>Caption = AnsiString(CppWebBrowser1>LocationName);

, ,
Microsoft. ,

.
, . 
, , . . ,
Internet 
, 
TImage, .

33


:
, Windows ?!

. . ,
, . , 
exe. ,
. Run 
, , .

. .

. Project C++ Builder.
Project1, ( ) 
Make Project1 Build Project1.
,
(
, C++ Builder),
C++ Builder. Make Build
, Build ,
. Make 
, 
, ,
. , Make 
. , , , ,


422

33

, Make
, ( ) ,
Build .
Project Options.
, . 
. Forms , 
,
. ,
.
Application , 
Windows 
Ctrl+Alt+Del. 
. .
. , ( )
. Compiler
, . .
Full Debug Release. Full
Debug . 
,
,
. ,
, ,
. , 
, , 
.
Warnings () All
(), , 
. Selected ().
. ,
, ,
.
. Release. 
, , 
. Release .
Debugging (). Code Opti
mization ( ) None () Speed (
). , 
, C++ Builder ,
. Warnings 
, None.
Linker , 
, Use dynamic RTL. .
, , , 
, .

33

423

, 
. .
, 
. , 
.
. ,
. ,
, Use dynamic RTL.

exe, , 
. , 
, . 2. ,
. Compiler
Release, Linker . Build 
exe. , , 144 .
Use dynamic RTL Build. 
202 . , . ,
.
,
. BDE,
, 
InstallShield Express. 
Microsoft, ,
Internet Explorer 4, . ,
, 
. , , 
.


424

Borland C++ 5

, . , , , 
. , ,
. , 
,
, 
. ,
Borland C++ C++ Builder . 
.
. ,
.
,
.
.
. , 
, , , 
.
.
, , , . 
. ,
.
cborland@mail.ru. , . 
, . ,
, , http://
cborland.nm.ru. ,
.
. !

MFC 223
VCL 223

210


156
156

182
218

129
47

30
189, 391
30
27
26
Borland ++
Build 28
Compile 33
Make 28
Run 20, 28, 38
++ Builder
Build 421
Compile 244
Make 421
Open Project 221

Run 216
Save All 215
288
298
61

61

325, 337
324

134
60

47

34, 35
148
Max box 23
Thick frame 23
33

38
36, 37, 214
38

406
84
85
111
84
317
39


426

Borland C++ 5

20, 26, 34
AppExpert 16
25
379

139

184
26
76
26
27
26
26
235
271
312

Database Desktop 378


32

165

326, 385
78
135

304, 320
219
300
306

65

30
226

82

130
130, 309

bool 85
char 85
double 85
float 85
int 84
short int 84
unsigned int 85

Dialog Client 21
MDI 22
SDI 21, 22, 23
107

152, 228

A
Anchors 405
AppExpert 16, 34

B
BDE 374, 380
Build 28

C
ClassExpert 30
Compile 33

D
Database Desktop 374
delete 258
Dialog Client 17, 21, 26
do...while 278
Document/View 17, 22

E
EasyWin 95
else 42
Errors 36, 37

F
for 66, 412

G
GetTickCount 49, 292
GetWindowsDirectory 89

H
Handle 228

I
if 42

M
Make 28
MessageBox 33, 227

O
Object Repository 312

S
SetText 48

T
TAnimate 285
TAnimateCtrl 54
TBitmap 52, 174
TButton 26, 225
TCheckBox 135, 301
TComboBox 265
TCppWebBrowser 400
TDataSource 381, 396
TDBEdit 383, 396
TDBGrid 382
TDBImage 384, 398

TDBNavigator 397
TDib 174
TDirectoryListBox 269
TDriveComboBox 268
TEdit 118, 316
TFileListBox 270
TFilterComboBox 269
TFindDialog 352
TFontDialog 361
TGauge 45
TImage 235
TImageList 367
TIniFile 346
TLabel 238
TListBox 144
TMainMenu 324
TMemoryDC 173
TOpenSaveDialog 165
TPageControl 259, 264
TPanel 406
TProgressBar 291
TRadioButton 139, 249
TReplaceDialog 356
TRichEdit 239, 312
trycatch 242
TSlider 196
TStatic 45
TStaticText 293
TStatusBar 370
TTabControl 205, 259
TTable 381, 396
TTimer 309
TToolBar 366
TUpDown 201

W
Warnings 39, 317
while 49
Windows
192
Windows API 232
Windows Messages 60

427