Transcript

C

+

+

B

u

i

l

d

e

r

- - 2005

681.3.068+800.92++ 32.973.26-018.1 90 . . 90 C++ Builder . , 2005. 336 : . ISBN 5-94157-631-5 C++ Builder. , C++ Builder. . - .

.: -

681.3.068+800.92++ 32.973.26-018.1

: . . .

02429 24.07.00. 24.08.05. 60x90 Vie. . . . . 21. 5000 . 1241 "-", 194354, -, . , 5. - 77.99.02.953..006421.11.04 11.11.2004 . . " "" 199034, -, 9 , 12 I S B N 5-94157-631-5 . ., 200S , "-", 2005

1. - -2 -2 Internet Explorer ...-. 1 3 5 5 6 10 12 16 18 21 25 28 33 36 43 48 51 54 57 58 62 62 65 70 75

IV_ ..... - WAV Player MIDI Compact Disk Player ( 1) Compact Disk Player ( 2) Video Player 15 " " (Puzzle) " " -2

81 81 81 84 87 90 93 100 104 109 114 118 121 124 124 124 128 138 142 148 150 158 161 161 162 166 172 180 180 192 198 207 218 232

'.

V

241 246 255 ..259265

...., . ( ) "" 2. BORLAND C++ BUILDER Label Edit Button Memo RadioButton CheckBox ListBox

:

265 266 266 267 267 268 268 269 269 269 270 270 271 271 272 272 272 273 273

275 277 278 279 280 281 283 284 285 286

.

VI ComboBox StringGrid Image Timer SpeedButton UpDown ProgressBar StatusBar Animate MediaPlayer..... Table Query DataSource..... DBEdit, DBMemo, DBGrid DBNavigator

287 288 290 291 .292 294 295 296 297 298 299 .....300 ......301 301 302 304

:...,

DBText

Canvas Pen. Brush ...., . CD-ROM

,

306 306 309 310 310 310 311 312 313 315 315 317 324

. . , , , , , . , , " ". RAD- (Rapid Application Development ) , , , . RAD- ! RAD- Borland C++Builder, : . Borland C++Builder C++. , , . . , . , , , , , ,

, , . , . . , , . , . , . , , . , . , , . . - , , C++Builder , , . . C++Builder. .: -, 2004. , , , : , , Microsoft Help Workshop, , , installShield Express, ( ).

1

, .

C++Builder : ( ), . ( , Windows) . , () . . : Label ; Edit ; Button ; checkBox ; RadioButton ; ListBox ; comboBox .

, () ( ).

1.

( ). ( Edit), ( ListBox) ( comboBox). CheckBox RadoiButton. ( Label) ( ShowMessage, MessageDlg). , , , strTomt, strToFioat. , , , intTostr, F l o a t T o S t r F l o a t T o S t r F .

. TextBox L a b e l

. , (). . 1.1.\ ' '"jfll

,

":1~. (/$>Label4 Buttoni

- Editi - Edit2

'

-Button2

. 1 . 1 .

// void &Key) { // , // // Key - // , if ((Key >= '0') && (Key Text).Pos(DecimalSeparator) != 0) Key = 0; // return; fastcall TForml::EditlKeyPress(TObject *Sender, char

if (Key == VK_BACK) // return; if (Key == VK_RETURN) // { Edit2->SetFocus(); return;

// Key = 0 ; //

8 // void {

1.

fastcall TForml::Edit2KeyPress(TObject *Sender, char &Key)

if ((Key >= '0') && (Key Text).Pos(DecimalSeparator) != 0) Key = 0 ; // return;

if (Key == VK_BACK) // return; if (Key == VK_RETURN) //

IButtonl->SetFocus();// // // return;

// Key = 0 ; //

// void fastcall TForml::ButtonlClick(TObject *Sender) float usd; //

float ; //

float rub; // // , if (((Editl->Text).Length() ==0) || ((Edit2->Text).Length)) == 0)) { MessageDlgC'Haflo ", mtlnformation, TMsgDlgButtons() if ((Editl->Text).Length!) == 0) Editl->SetFocus(); // else Edit2->SetFocus(); // return; mbOK, 0);

// usd = StrToFloat(Editl->Text); k = StrToFloat(Edit2->Text); // rub = usd * k; // Label4->Caption = FloatToStrF(usd,ffGeneral,7,2) + "$ = "+FloatToStrF(rub,ffGeneral,7,2) + " ."

// void { Forml->Close(); // fastcall TForml::Button2Click(TObject *Sender)

10

1.

- -, . 1.2, . , , . . Editl Label2 I - Buttoni

. 1.2. , fastcall { /* Editl ( ), */ Buttonl->Enabled = False; T F o r m l : : T F o r m l ( T C o m p o n e n t * Owner) : TForm(Owner)

// Editl void &Key) { / / // , fastcall TForml::EditlKeyPress(TObject *Sender, char

// Key - // , if ( (Key >= '0') && (Key Text).Pos(DecimalSeparator) ! = 0) Key = 0 ; // return;

if (Key == VK_BACK) // return; if (Key == VK_RETURN) // { Buttonl->SetFocus(); return;

// Key = 0 ; //

// Editl void fastcall TForml::EditlChange(TObject *Sender) { // , Editl if ( (Editl->Text).Length() == 0) Buttonl->Enabled else Buttonl->Enabled Label2->Caption = ""; = = False; // . True; // .

12// void { double funt; // double kg; //

1.

fastcall TForml::ButtonlClick(TObject *Sender)

// , // Editl . , // . funt kg = = StrToFloat(Editl->Text); funt * 0.4995; = FloatToStrF(funt,ffGeneral,5,2) + " . - " + FloatToStrF(kg,ffGeneral,5,2) + " ";

Label2->Caption

TextBox Label, " ". . 1.3.

() ()LabeU Buttoni -

EdiH - Edit2

. I; : : : * . 1.3. .

- Button2

/ / void

f a s t c a l l T F o r m l : : B u t t o n l C l i c k ( T O b j e c t *Sender)

/

3

float u; // float r; // float i; // // , // if ( ((Editl->Text).Length() = = 0 ) || ((Edit2->Text).Length() == 0)) { MessageDlg(" ", mtlnformation, TMsgDlgButtons() Text).Length() == 0) Editl->SetFocus(); // else Edit2->SetFocus; // return;

// u = StrToFloat(Editl->Text); = StrToFloat(Edit2->Text); // try { i = u/r; } catch (EZeroDivide &e) { ShowMessage(" " " "); Edit2->SetFocus(); return; //

14// Labels Label4->Caption - " : " +

1.

FloatToStrF(i,ffGeneral,7,2) + " A";

// // , // void fastcall TForml::EditlKeyPress(TObject *Sender, char &Key) { // Key - // , if ( ( Key >= '0') && ( Key Text).Pos(DecimalSeparator) != 0 ) Key = 0 ; // return;

if (Key == VK_BACK) // return; if ( Key == VK_RETURN) // Edit2->SetFocus(); return;

// Key = 0; //

75

// void fastcall TForml::Edit2KeyDown(TObject *Sender, WORD &Key,TShiftState Shift) { if ( ( Key >= '0') && ( Key Text).Pos(DecimalSeparator) != 0 ) Key = 0; // return;

if (Key == VK_BACK) // return; if ( Key == VK_RETURN) //

IButtonl->SetFocus(); // // // // . ButtonlClick return;

// Key = 0 ; //

// void fastcall TForml::Button2Click(TObject 'Sender)

16

1.

Forml->Close(); //

/* EditlChange Change Editl, Edit2. - Change Editl, - Change Edit2 EditlChange. */ void { Label4->Caption = ""; fastcall TForml::EditChange(TObject *Sender)

, . 1.4, , , . RadioButton.

, I RadioButtoni RadioButton2 j ^

Label4

. 1.4.

// void { float rl,r2,r; rl = StrToFloat(Editl->Text); r2 = StrToFloat(Edit2->Text); /* RadioButtonl RadioButton2 , */ ( RadioButtonl->Checked ) { // "" = rl + 2; ela* // // // try { = ( r l * r2) / ( r l + r 2 ) ; } catch ( EInvalidOp &e) { ShowMessage(" " ""); return; EInvalidOp "" fastcall TForml::ButtonlClick(TObject *Sender)

17_

Label4->Caption = FloatToStrF(r, ffGeneral, 6,2) + " "; }

18

1.

II "" void { Label4->Caption = ""; fastcall TForml::RadioButtonlClick(TObject *Sender)

// "" void { Label4->Caption = ""; fastcall TForml::RadioButton2Click(TObject *Sender)

, . 1.5, checkBox.

Label! Che:kBox1 CheckBox2 CheckBox3 CheckBox4 Buttoni

: - -

I::. 1.5.

float surnm; // // fastcall TForml::TForml(TComponent* Owner) : TForm(Owner)

f

// "" CheckBox2->Enabled = false;

// "-" void { if ( CheckBoxl->Checked ) { /* , */ summ += 54; // "" CheckBox2->Enabled = true; } else { /* , */ summ -= 54; // "" if (CheckBox2->Checked) CheckBox2->Checked = false; CheckBox2->Enabled = false; fastcall TFoml: :CheckBoxlClick(TObject *Sender)

// Labell->Caption = FloatToStrF(summ,ffCurrency,6,2);

20// "" void

1. faetcall TForml::CheckBox2Click(TObject *Sender)

if ( CheckBox2->Checked) summ +=10.5; la* summ -= 10.5; Labell->Caption = FloatToStrFtsumm,ffCurrency,6,2);

// "" void faetcall TForml::CheckBox3Click(TObject *Sender) if ( CheckBox3->Checked) summ += 18.5; la* summ -= 18.5; Labell->Caption = FloatToStrF(summ,ffCurrency,6,2);

// "-" void { if ( CheckBox4->Checked) s u m += 14; summ -= 14; Labell->Caption = FloatToStrF(summ,ffCurrency,6,2) faetcall TForml::CheckBox4Click(TObject *Sender)

// OK

void { if ( (CheckBoxl->Checked)&& (CheckBox2->Checked)&& (CheckBox3->Checked)&&(CheckBox4->Checked) ) /* 5% */ summ = summ * 0.95; ShowMessage(" 5%.\" fastcall TForml::ButtonlClick(TObject *Sender)

21_

" : " + FloatToStrF(summ, ffCurrency, 6,2) + " ."); } else if ( (CheckBoxl->Checked)|| (CheckBox3->Checked)|| (CheckBox4->Checked)) ShowMessage(" : " + FloatToStrF(summ,ffGeneral,6,2)+ " ."); else ShowMessage(" ");

, . 1.6, . ComboBox2

( ). comboBox2 , , . . 1.1.

22riv

1.

Labell- Label2: - LabeB

ComboBoxi

ComboBox2

. 1.6. 1.1. ComboBoxl . s t y l e csDropDownList ( ) .

ComboBox2.Style

csDropDown

.Style

csSimple

/ / fastcall TForml::TForml(TComponent* Owner) / / TForm(Owner)

ComboBox2->Sorted = t r u e ; / / ComboBox2->Items->Add("-"); ComboBox2->Items->Add("Mepjttui,a") ; ComboBox2->Items->Add("-"); ComboBox2->Items->Add(""); ComboBox2->Items->Add("");

// ComboBox2->Sorted = t r u e ; / / ComboBox3->Items->Add("4aii") ; ComboBox3->Items->Add("4aM "); ComboBox3~>Items->Add("Ko(J>e ") ; ComboBox3->Items->Add("Koe "); ComboBox3->Items->Add("KaKao");

23

// ComboBoxl void { Labell->Caption = CornboBoxl->Text; fastcall TForml::ComboBoxlClick(TObject *Sender)

// ComboBox2 void { Label2->Caption = ComboBox2->Items-> Strings[ComboBox2->ItemIndex] fastcall TForml::ComboBox2Click(TObject *Sender)

// void { Label3->Caption = ->Iterns-> Strings[ComboBox3->ItemIndex] fastcall TForml::ComboBox3Click(TObject *Sender)

// ComboBox2 void fastcall TForml::ComboBox2KeyPress(TObject *Sender, char &Key) { if (Key == VK_RETURN)

24

1. / // . . int n = ComboBox2->ltems->Add(ComboBox2->Text); ComboBox2->ItemIndex = n; Label2->Caption = ComboBox2->Items->Strings[n];

// void fastcall TForml::ComboBox3KeyPress(TObject *Sender, char &Key) AnsiString st; // , // // ComboBox if (Key == VK_RETURN) // // . , // st = ComboBox3->Text.Trim(); // if ( ComboBox3->Items->lndex0f(st) == -1 ) // int n = ComboBox3->Items->Add(st); ComboBox3->ItemIndex = n; Label3->Caption = ComboBox3->Items->Strings[n]

25

(. 1.7) , , . ' -

1052'7 I31274'2I0'96

(./)

: 212,64. [/HTbj

. 1.7. // fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) { / * , Edit2 KeyPress Edit3 */

EditKeyPress Edit2->0nKeyPress = E d i t K e y P r e s s ; Edit3->0nKeyPress = E d i t K e y P r e s s ; / * ,

KeyPress

, Edit

*/ E d i t l - > T a g = 1; Edit2->Tag = 2 ;

Tag

26 Edit3->Tag = 3;

1.

// void fastcall TForml::EditKeyPress(TObjt *Sender, char &Key) TEdit * Edit; // Edit

Edit = (TEdit*)Sender; /* ed - Edit, */ /* , . */ if ( Key == VK_RETURN) // switch (Edit->Tag) { case 1 : /* Editl Edit3 */ Edit2->SetFocus() ; break; case 2 : /* Edit2 Edit3 */ Edit3->SetFocus() ; break; case 3 /* Edit3 */ Buttonl->SetFocus ; break; } return;

if ( (( Key >= '0') && ( Key ItemIndex) { case 0 : aKs = 0.7; break; case 1 : aKs = 0.8; break; case 2 : aKs = 0.9; break; case 3 : aKs = 0.95; break; case 4 : aKs = 1.0; break;

// float T; // AnsiString st; T = * aKt * aKb * aKvs * * aKm *aKs; st = " : " + FloatToStrF(aTb,ffCurrency,5,2)+ ". : " + FloatToStrF(aKt,ffGeneral,2,2)+ ". : " +

FloatToStrF(aKb,ffGeneral,2,2)+ ". : " + FloatToStrF(aKvs,ffGeneral,2,2)+ "\.. - , : " + FloatToStrF(aKo,ffGeneral,2,2)+ "\. : " + FloatToStrF(aKm,ffGeneral,2,2)+ ". : " + FloatToStrF(aKs,ffGeneral,2,2)+ "\\: " + FloatToStrF(T,ffCurrency,5,2); ShowMessage(st) ;

3J3

// - void { Buttonl->Enabled = (ComboBoxl->ItemIndex != -1) && (ComboBox2->ItemIndex != -1) && (ComboBox3->ItemIndex != -1) && (ComboBox4->ItemIndex != -1) && (Editl->Text.LengthText.Length() != 0) && (Edit3->Text.Length() != 0); fastcall TForml::Change(TObjt *Sender)

(. 1.10) ListBox openDiaiog. () , . OpenDiaiog.

34

1.

PICT0208JPG PICT0209.JPG PICT0210.JPG PICT0211.PG PICT0212.JPG PICT0213.PG PICT0214.PG PICT0217.JPG PICT0001.JPG PICT0002.JPG PICT0003.PG PICT0004.JPG PICT0006.PG PICT0O0BJPG PICT0011.PG PICT0013JPG PICT0014.JPG01

. 1.10. L i s t B o x #include // // JPEG // , //

AnsiString aPath;

TSearchRec aSearchRec; // - // fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) Imagel->Proportional = true; if (FindFirst(aPath+ "*.jpg"/ faAnyFile, aSearchRec) == 0) ListBoxl->Items->Add(aSearchRec.Name); while ( FindNext(aSearchRec) == 0 ) / / . .

{ ListBoxl->Items->Add(aSearchRec.Name); } // ListBoxl->ItemIndex = 0; Labell->Caption = ListBoxl->Items->Strings[0]; Imagel->Picture->LoadFromFile(aPath + ListBoxl->Items->Strings[0]);

3!5

// ListBox void { int n = ListBoxl->ItemIndex; // - // Labell->Caption = ListBoxl->Items->Strings[n]; Imagel->Picture->LoadFrornFile(aPath + ListBoxl-> Items->Strings[n]); fastcall TForml::ListBoxlClick(TObject *Sender)

// void { if ( OpenDialogl->Execute() ) { // ListBoxl->Clear(); // aPath = ExtractFilePath(OpenDialogl->FileName); Forml->Caption = " - " + aPath; if ( FindFirst(aPath+ "*.jpg", faAnyFile, aSearchRec) == 0) fastcall TForml::BitBtnlClick(TObject *Sender)

36

1.

ListBoxl->Items->Add(aSearchRec.Name); w h i l e (FindNext(aSearchRec) == 0)// { ListBoxl->Items->Add(aSearchRec.Name); } // // ListBox int n = ListBoxl->Items-> IndexOf(ExtractFileName(OpenDialogl->FileName)); ListBoxl->ItemIndex = n; Labell->Caption = ListBoxl->Items->Strings[n]; Imagel->Picture->LoadFromFile(aPath + ListBoxl->Items->Strings[n]); ..

(. 1.11) . , staticText.( --'

5

I _ ! _ L J _ ^ J

. 1 . 1 1 .

float accum; // (- ) int op; /* : 1 - "+",2 - "-"; - "" ( "=" */ int f; /* f == 0 - , , , . f == 1 - */ // fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) { f =0; op = 0; // //

37^

StaticTextl->Caption = 0;

// "0" void fastcall TForml::Btn0Click(TObject *Sender) { if ( f != 0) StaticTextl->Caption = StaticTextl->Caption + "0"

// "1" void fastcall TForml::BtnlClick(TObject *Sender) { if ( f == 0) { StaticTextl->Caption = "1"; f = 1;

38 else

1.

StaticTextl->Caption = StaticTextl->Caption + "1";

// "2" void { if ( f == 0) { StaticTextl->Caption = "2"; f = 1; else StaticTextl->Caption = StaticTextl->Caption + "2"; fastcall TForml::Btn2Click(TObject *Sender)

// "3" void { if ( f == 0) { StaticTextl->Caption = "3"; f = 1; } else StaticTextl->Caption = StaticTextl->Caption + "3" fastcall TForml::Btn3Click(TObject *Sender)

// "4" void fastcall TForml::Btn4Click(TObject *Sender) { if ( f == 0) StaticTextl->Caption = "4";

f = 1; } else StaticTextl->Caption = StaticTextl->Caption + "4";

39

// "5" void fastcall TForml::Btn5Click(TObject *Sender) { if ( f == 0) { StaticTextl->Caption = "5"; f = 1; } else StaticTextl->Caption = StaticTextl->Caption + "5"

// "" void { if ( f == 0) { StaticTextl->Caption = "6"; f = 1; } else StaticTextl->Caption = StaticTextl->Caption + "6" fastcall TForml::Btn6Click(TObject *Sender)

// "7" void fastcall TForml::Btn7Click(TObject *Sender) { if ( f == 0)

40StaticTextl->Caption = "7"; f = 1; } else

1.

StaticTextl->Caption = StaticTextl->Caption

// "8" void fastcall TForml::Btn8Click(TObject *Sender) { if ( f == 0) { StaticTextl->Caption = "8"; f = 1; else StaticTextl->Caption = StaticTextl->Caption + "8";

// "9" void { if ( f == 0) { StaticTextl->Caption = "9"; f = 1; else StaticTextl->Caption = StaticTextl->Caption + "9" fastcall TForml::Btn9Click(TObject *Sender)

// ", " ( ) void fastcall TForml::BtnkClick(TObject *Sender)

{ if ( f == 0) { StaticTextl->Caption = "0,"; f = 1; else if ( StaticTextl->Caption.Pos(",") == 0) StaticTextl->Caption = StaticTextl->Caption

41_

// "" () void { StaticTextl->Caption = "0"; accum = 0; op = 0; f = 0; // fastcall TForml::BtnCClick(TObject *Sender)

// void { /* accum . , . */ float op2 = StrToFloat(StaticTextl->Caption); switch ( op ) { case 0 : accum = op2; break ; case 1 : accum += op2; break; fastcall TForml::DoOp(void)

42 case 2 : accum -= op2; break;

1.

StaticTextl->Caption = FloatToStrF(accum,ffGeneral,6,3);

// "+" void fastcall TForml::BtnPClick(TObject *Sender) { /* , , */ if ( f != 0) { // DoOp(); // f = 0; } =1; //

// "-" void fastcall TForml::BtnMClick(TObject *Sender) { if ( f != 0) { // DoOp(); // f = 0; // } = 2; //

// "="

void { if ( f != 0) { DoOp(); // f = 0; // } = 0; fastcall TForml::BtnEClick(TObject *Sender)

43

-2 -2, . 1.12, , , " ". SpeedButton. , () click. , speedButton click , .

. 1.12. -2 / / & - c l a s s TForml : p u b l i c TForm published: TStaticText *StaticTextl; // h-

44 private:

1.

// ** ** TSpeedButton * btn[16]; void public: fastcall TForml (TComponent* Ownejr) ; // // Click fastcall btnClick(TObject *Sender);

// *** *** float ; int op; int fd; // ( ) // /* fd == 0 - , , , "+"; fd = 1 - */ #define WBTN #define HBTN #define DXBTN #define DYBTN 35 20 6 6 // // // X // Y

// Char btnText[] = "789+456-123=00."; #define CM -1 #define EQ -2 ttdefine PL -3 #define MN -4 #define CL -5 // // "=" // "+" // "-" // "C" t

// int btnTagU = {7,8,9,PL,4,5,6,MN,1,2,3,EQ,0,0,CM,CL}

// fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) { int left, top; // top = 48; int = 0; // btn for ( int i = 0; i < 4; i++ ) // { left = 8; for ( int j = 0; { btn [] = new TSpeedButton {Forml),j < 4; j++) // no 4

45

btn[k]->Parent = Forml; // "" // // btn[k]->Left = left; btn[k]->Top = top; btn[k]->Width = WBTN; btn[k]->Height = HBTN; //btn[k]->Flat = true; btn[k]->Font->Color = clNavy; btn[k]->Caption = btnText[k]; // btn[k]->Tag = btnTag[k]; //

// Click btn[k]->OnClick = btnClick; // . // h- left = left + WBTN+ DXBTN;

46 top = top + HBTN + DYBTN; }

1.

// "" (btn[12] btn[13]) btn[13]->Visible = false; btn[12]->Width = 2 * WBTN + DXBTN; op = EQ;

// btn[i] // ( ) void { TSpeedButton *btn; int id; // btn = (TSpeedButton*(Sender; // Tag id = btn->Tag; // "1" .. "9" if ( id > 0 ) { if ( fd == 0 ) { StaticTextl->Caption = btn->Tag; fd = 1; } else StaticTextl->Caption = StaticTextl->Caption + btn->Tag; return; // "" if ( id == 0) { if ( StaticTextl->Caption != "0" ) StaticTextl->Caption = fastcall TForml::btnClick(TObject *Sender)

StaticTexCl->Caption + btn->Tag; return; } // "," if ( id == CM) { if ( StaticTextl->Caption.Pos(",") == 0 ) {

47

StaticTextl->Caption = StaticTextl->Caption + ","; fd = 1; } return; } // "" if ( id == CL) { ac = 0; id = EQ; fd = 0; StaticTextl->Caption = 0; return; } // : "+", "-" "=" float op2; // ( ) 2 = StrToFloat(StaticTextl->Caption); /* , , , */ switch (op) { case EQ : = op2; break; case PL : ac = ac + op2; break; case MN : ac = ac - op2; break; } StaticTextl->Caption = FloatToStrF(ac,ffGeneral,15,6); op = id; //

48fd = 0; //

1.

// void fastcall TForml::FormDestroy(TObjt *Sender) // , for ( int i = 0; i < 16; i++) delete btn[i];

, . 1.13, Timer. Label Label2 Label3

Timeri Buttoni

0:00 00:j:

Button2

. 1.13. // int min; int sec; int msec; // // //

// _fastcall TForml::TForml(TComponent* Owner) : TForm(Owner)

{ // Timerl->Enabled = false; Timerl->Interval = 10; // // 1

4

// / void { if ( ! Timerl->Enabled ) { // Timerl->Enabled = true; Buttonl->Caption = ""; Button2->Enabled = false,} else { // Timerl->Enabled = false; Buttonl->Caption = ""; Button2->Enabled = true,* fastcall TForml::ButtonlClick(TObject *Sender)

// void { if ( msec < 99) msec++; else fastcall TForml::TimerlTimer(TObject *Sender)

50 msec = 0; if ( sec < 59 ) sec++; else { sec = 0; min++;

1.

Labell->Caption = IntToStr(min); } if ( sec Caption = "0" + IntToStr(sec); else Label2->Caption = IntToStr(sec); // Label4->Visible = ! Label4->Visible; } if ( msec Caption = "0" + IntToStr(msec); else Label3->Caption = IntToStr(msec);

// void { min = 0; sec = 0; msec = 0; Labell->Caption = "0"; Label2->Caption = "00"; Label3->Caption = "00"; fastcall TForml::Button2Click(TObject *Sender)

51

(. 1.14) ProgressBar. ProgressBar . 1.2.\

"" . . Editi ProgressBarl 60' Buttoni CheckBoxi Timeri F |

. 1.14. 1.2. ProgressBar Min Step Position Smooth 60 1 60 true

#define TR 60 // , int pw; // "" int rem = TR; // // fastcall TForml::TForml(TComponent* Owner) : TForm(Owner)

52

1.

Label4->Caption = IntToStr(TR); // // , // ProgressBarl->Max = TR; ProgressBarl->Position = TR; ProgressBarl->Step = 1; // // - ProgressBarl->Smooth = true,-

// Randomize() ; pw = RandomRange(100,999); // ""

// void { rem; ProgressBarl->Position--; Label4->Caption = IntToStr(rem); if (rem == 0 ) { // , Timerl->Enabled = false; Editl->Enabled = false; Buttonl->Enabled = false; ShowMessage(" , " " \ \"\" :" + IntToStr(pw) ); fastcall TForml::TimerlTimer(TObject *Sender)

// void fastcall TFonnl::CheckBoxlClick(TObject *Sender) { if ( CheckBoxl->Checked ) { // ProgressBarl->Step = 1 ; ProgressBarl->Smooth = true; else // ProgressBarl->Step = 6 ; // ProgressBarl->Smooth = false; // - // // -

// , void fastcall TForml::isRight(void) { if ( StrToInt(Editl->Text) == pw ) { Timerl->Enabled = false; Buttonl->Enabled = false; Editl->Enabled = false; ShowMessage("!\ " + IntToStr(TR - rem)+ " ");

// void fastcall TForml::EditlKeyPress(TObject *Sender, char &Key) { if ( ( Editl->Text.Length() < 3) &&

54((Key >= '0') && (Key Text.Length() == 3) Buttonl->Enabled = true; else Buttonl->Enabled = false; fastcall TForml::EditlChange(TObject *Sender)

// OK void faatcall TForml::ButtonlClick(TObject *Sender) isRightO; // , //

-2 -2, . 1.15, statusBar.

55

, , , .!' -2

"" . . )482|: 3 " (:! j : 5,

. 1.15. # d e f i n e TR i n t pw; i n t = 0; // { // Randomize(); pw = RandomRange(100,999); / / "" 60 / / ,

/ / "" / /

i n t rem = TR; / /

f a s t c a l l TForml::TForml(TComponent* Owner) : TForm(Owner)

// void { rem--; S t a t u s B a r l - > P a n e l s - > I t e m s [ 2 ] - > T e x t = " : " + IntToStr(rem) + " "; if (rem == 0 ) / / , fastcall TForml::TimerITimer(TObject *Sender)

56^ Timerl->Enabled = false; Editl->Enabled = false;

1.

ShowMessage(" , " " \\"\" :" + IntToStr(pw) );

// void fastcall TForml::EditlKeyPress(TObject *Sender, char &Key) if ( ( Editl->Text.Length() < 3) && ( ( Key >= '0') && ( Key Text.Length() == 3)) // , if ( StrToInt(Editl->Text) == pw ) Timerl->Enabled = false; Editl->Enabled = false; ShowMessage("!\ " + IntToStr(TR - rem)+ " "); else // ++; StatusBarl->Panels->Items[I]->Text = " : " + IntToStr(p); return;

if ( Key == VK_BACK) return; // Key 0;

57

// void fastcall TForml::EditlChange(TObject *Sender) StatusBarl->Panels->Items[O]->Text = " : " + IntToStr(Editl->Text.Length()

Internet Explorer Internet , Internet Explorer -. . 1.16. Label i. Label . 1.3.

http: //www.phy.ru

Labeli. 1.16. Internet

1.3. Label i Font.Color Font.Style.fsUnderline Cursor

clBlue true crHandPoint

58// void { / / , Label 1

1.

f a s t c a l l TForml::LabellClick(TObject

*Sender)

Labell

ShellExecute(Forml->Handle,"open",Labell->Caption.c_str, NULL,NULL,SW_RESTORE);

(. 1.17) Winhelp ( ). (. 1.18) . , , , , , . (. 1.4). , , . 1.5.\-

($) (/$) J"~

EdiM Edil2 Button3

F1 -

. 1.17.

59

^

1

. Borland C++Builder. . ( onvertor.hlp) Help.

3 -

d. 1.18. Winhelp 1.4. 1 2 3 4 5 1.5. , Forml Forml Editl Edit2 HelpFile HelpContext HelpContext HelpContext conv.hlp 1 3 4

/ / "" void f a s t c a l l T F o r m l : : B u t t o n 3 C l i c k ( T O b j e c t *Sender) { WinExecCwinhlp32.exe c o n v . h l p " , SW_RESTORE) ;

3 . 1241

60

1.

-2 -2 (. 1.19) HTML Help ( chm). (. 1.20) , / . () . , KeyDown, a He KeyPress.I-.?1 -2

*1

($)

|~

(/$) |"

F1 -

. 1 . 1 9 . < F 1 >* -2 TV tLJ 51 .iql.xj

. Borland C++ Builder. . ^ (convertor.chm) Help.

ii]

. 1.20. HTML Help

/* "". KeyDown , ( KeyPress ) */ void { if (Key == VK_F1 ) /* hh.exe, Windows. mappid */ fastcall TForml::EditlKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)

61_

WinExecfhh.exe -mapid 3 converter.chm", SW_RESTORE);

// "" void fastcall TForml::Edit2KeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key == VK_F1 ) WinExecChh.exe -mapid 4 convertor.chm", SW_RESTORE)

// "" void fastcall TForml::Button3Click(TObject *Sender) { WinExecChh.exe -mapid 1 convertor.chm", SW_RESTORE)

, .

, . 1.21, , , . meteo.txt . , . , , .

7 14 3 I 28

12 8 9 15 16 22 23 .:

3 10 17 24 :

4 11 18 25 :

5 6 12 13 19 20 26 27 .

: 21.02.2005

; I

::::::

I ; : : : : ; : : : : ; ; : . : : . 1 . 2 1 .

int f; // //' fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) { MonthCalendarl->ShowTodayCircle = false; MonthCalendarl->Date = Now(); Buttonl->Enabled = false; } // void { fastcall TForml::EditlChange(TObject *Sender)

63

// "" , // . // - "", if ( (Editl->Text.Length() == 0 ) || ( (Editl->Text.Length() ==1) && (Editl->Text[l] == '-') ) ) Buttonl->Enabled = false; else Buttonl->Enabled = true; } // "" void { AnsiString st; /* fmCreate, , , , , */ fastcall TForml::ButtonlClick(TObject *Sender)

64

1. st MonthCalendarl->Date.DateString() + " " + Editl->Text + "\r\n"; /* meteo.txt */ if ( FileExists("meteo.txt") ) f = FileOpen("meteo.txt",fmOpenWrite); else = FileCreatef"meteo.txt"); // if ( f != -1 ) { // FileSeek(f,0,2); // // FileWrite(f,st.c_str(),st.Length()); FileClose(f); Buttonl->Enabled = false; } else { /* : , */ ShowMessage(" : ," " ");

// // void fastcall TForml::EditlKeyPress(TObject *Sender, char &Key)

if (( Key >= '0') && (Key Text.Pos(',') != ) Key = 0; return;

65

if ( Key == 8) return; if ((Key == '-') && (Editl->Text.Length() == 0)) // "" return; // Key = 0; } // MohthCalendar void { Editl->Text = ""; Editl->SetFocus(); // // // fastcall TForml::MonthCalendarlClick(TObject *Sender)

(. 1.22) . , meteo.txt, .

66---

1.

19.02.2005 20.02.2005 21.02.2005 22.02.2005 23,02.2005 24.02.2005

-12 -7 -5 -14 -12 -10

jJJ

]

: -8,73

OK . 1.22. #include "DateUtils.hpp" // MonthOf

/* GetString . - - */ int GetString(int f, AnsiString *st); // fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) ComboBoxl->Style = csDropDownList; ComboBoxl->Items->Add(""); ComboBoxl->Items->Add(""); ComboBoxl->Items->Add("MapT"); ComboBoxl->Items->Add(""); ComboBoxl->Items->Add(""); ComboBoxl->Items->Add("MraHb"); ComboBoxl->Items->Add(""); ComboBoxl->Items->Add("");

ComboBoxl->Items->Add(""); ComboBoxl->Items->Add(""); ComboBoxl->Items->Add(""); ComboBoxl->Items->Add(""); // - ComboBoxl->ItemIndex = MonthOf( Now() ) -1 ; } // void { int h; // h = FileOpen("meteo.txt",fmOpenRead); if ( h == -1) { ShowMessage(" meteo.txt ."); return; fastcall TForml::ButtonlClick(TObject *Sender)

(7_

Memol->Lines->Clear(); // AnsiString st; // , int Is; // // // // // ( ) //

TDateTime aDate; float temp; int nMonth; int n = 0; float sred;

float sum = 0 ; //

AnsiString buf; /* :

68 -.

1.

: .. -; - */ do Is = GetString(h,&st); // if ( Is I 0) { nMonth = MonthOf (StrToDate(st)) - 1; // buf = st; Is = GetStringfh,&st); // temp = StrToFloat(st); if ( nMonth == ComboBoxl->ItemIndex )

sum = sum + temp; buf = buf + " " + st; Memol->Lines->Add(buf);

} while ( Is != 0); FileClose(h); if ( n != 0 ) sred = sum / n; Labell->Caption = " : " + FloatToStrF(sred,ffGeneral,3,2); else Labell->Caption = " " " " + ComboBoxl->Text,}

// void { Labell->Caption = ""; Memol->Text = ""; fastcall TForml::ComboBoxlChange(TObject *Sender)

(

// GetString // . // - - int GetString(int f, AnsiString *st) { unsigned char buf[256]; // () unsigned char *p = buf; int n; / / - // ( - FileRead)

i n t l e n = 0 ; / /

// do n = FileReadff, , 1 ) ; while ((n != 0) && (* == ' '));

while (( != 0 ) && ( * ! = ' ' ) ) { if ( * == '\') { = F i l e R e a d ( f , , 1 ) ; / / break; '\'

++; n = FileRead(f, p, 1);

70* = ' \ 0 ' ; if ( l e n !=0 ) s t - > p r i n t f ( " % s " , buf) ; return l e n ; }

.

. stringGrid (. 1.23). stringGrid , .

:

. 1.23. StringGrid , // fastcall TForml::TForml(TComponent* Owner) : TFormfOwner) // *** *** StringGridl->Options goEditing goTabs; // // -

// StringGridl->Cells[O][0] = ""; StringGridl->Cells[l][0] = ""; StringGridl->Cells[2][0] = ""; // StringGridl->ColWidths[0] = 70; StringGridl->ColWidths[l] = 70; StringGridl->ColWidths[2] = 200;

7

4

// void _fastcall TForml::StringGridlKeyPress(TObject *Sender, char &Key) { int cRow, cCol; if ( Key == VKJXETURN ) { // cRow = StringGridl->Row; cCol = StringGridl->Col; if ( cCol < StringGridl->ColCount - 1 ) StringGridl->Col = StringGridl->Col + 1; else if ( cRow < StringGridl->RowCount - 1 ) { StringGridl->Row = StringGridl->Row + 1; StringGridl->Col = 1 ; /

// void fastcall TForml::ButtonlClick(TObject *Sender)

72

1. // StringGridl->Row = StringGridl->RowCount-l; StringGridl->RowCount++; StringGridl->Row = StringGridl->RowCount-l;

//

// // //

// void _fastcall TForml::FormCloseQuery(TObject *Sender, bool &CanClose) { int f; // /* fmCreate, , , , , */ if ( FileExistsC'tabl.grd") ) f = FileOpen("tabl.grd",fmOpenWrite); else f = FileCreateC'tabl.grd"); if ( f != -1 ) // for (int i = 1; i < StringGridl->RowCount;{

1

AnsiString st = StringGridl-> Rows[i]->DelimitedText +"\r\n FileWriteff,st.c_str(), st.Length());

} FileClose(f);

else // ShowMessage ('' "); }

73

int GetLine(int f, AnsiString *st); // // void { int f; AnsiString st; // // fastcall TForml::FormActivate(TObject *Sender)

bool fl = true; // true - if (( f = FileOpen("tabl.grd",fmOpenRead)) == -1 ) return; // // while ( GetLine(f, &st) != 0) { // if ( fl ) { StringGridl->Rows[StringGridl->Row]-> DelimitedText = st; fl = false; } else { StringGridl->RowCount++; StringGridl->Row = StringGridl->RowCount-l; StringGridl->Rows[StringGridl->Row]-> DelimitedText = st;

74

1.

} FileClose(f);

// // " " // - - int GetLine(int f, AnsiString *st) unsigned char buf[256]; // () unsigned char *p = buf; int n; //

// - ( - FileRead)

int len = 0; // n = FileRead(f, p, 1 ) ; while ( n != 0 ) if ( * == '\') n = FileRead(f, break; len++; ++; n = FileRead(f, p, 1 ) ; , 1 ) ; / / '\'

* = '\0'; if ( len !=0) st->printf("%s", buf) ; return len;

75

MEdit (Micro Editor) RichEdit, MainMenu, ToolBar, SpeedButton, OpenDialog saveDialog, . . 1.24, RichEdit . 1.6. MEedit, . MEedit . 1.25.MEdit -

SpeedButtoni S e d ut n p e B to 2 ToolBar!MainMenui RIchEditi

OpenDialogi SaveDialog!

j!|

. 1.24. MEdit 1.6. Align BorderStyle ScrollBars Wordwrap RichEdit

alClient bsNone ssVertical true

76 MEdit

1.

Image! M E d i t

Labeli Label2Beveli Buttoni

. C++Builder. RichEdit, MainMenu, ToolBar, SpeedButton, OpenDialog, SaveDialog. Ok . 1.25. MEedit

//

*** (MEd.itFrm.cpp) ***

#include "about.h" // TForml *Forml; AnsiString aFileName; // // fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) { aFileName = ""; /* Click ! Click / /, - . */ SpeedButtonl->OnClick = imOpenClick; SpeedButton2->0nClick = imSaveClick;

// bool fastcall TForml::SaveText()

// SaveText false, // // if ( aFileName == "" ) { // //SaveDialogl->FileName = "Text.txt"; SaveDialogl->Options ofPathMustExist ofOverwritePrompt;

if ( SaveDialogl->Execute() ) aFileName = SaveDialogl->FileName; else return false; // // } // RichEditl->Lines->SaveToFile(aFileName); return true;

// / void fastcall TForml::imOpenClick(TObject *Sender) { int r; // , if ( RichEditl->Modified ) { // = MessageDlg(" .\" " ?", mtWarning, TMsgDlgButtons () mbNo mbCancel, 0 ) ; if ( r == mrCancel )

mbYes

78

1. // Cancel // return; // Yes if ( ( == mrYes ) && ( ! SaveText() )) return;

/ / OpenDialogl->FileName = "*.txt"; OpenDialogl->Options ofPathMustExist ofFileMustExist;

if ( OpenDialogl->Execute() ) { RichEditl->Lines->LoadFromFile(OpenDialogl->FileName); RichEditl->Modified = false; Fomnl->Caption = "MEdit - " + OpenDialogl->FileName; aFileName = OpenDialogl->FileName;

// / void { // if ( SaveText() ) { RichEditl->Modified = false; Forml->Caption = "MEdit - " + aFileName; fastcall TForml::imSaveClick(TObject *Sender)

// /

void { Forml->Close(); /* FormCloseQuery, , */ fastcall TForml::imExitClick(TObject *Sender)

79

// " " void { int r; if ( RichEditl->Modified ) // { = MessageDlg(" .\n" " ?", mtWarning, TMsgDlgButtons() switch ( r ) { case mrYes : // Yes if ( ! SaveTextO ) CanClose = false; break; case mrCancel : // Cancel CanClose = false; // // // mbYes mbNo mbCancel, 0 ) ; fastcall TForml::FormCloseQuery(TObject *Sender, bool &CanClose)

80void {

1. fastcall TForml::imToolBarClick(TObject *Sender) // / ToolBarl->Visible = ! ToolBarl->Visible,// / "" / // imToolBar->Checked = ! imToolBar->Checked;

// /

// / void fastcall TForml::imAboutClick(TObject *Sender) { TAboutForm *AboutForm; // Position AboutForm // poOwnerForm AboutForm = new TAboutForm (this); AboutForm->ShowModal(); delete AboutForm;

/* " " (about.cpp). ( iinclude "about.h") (MEditFrm.cpp) */ // void fastcall TAboutForm: :ButtonlClick(TObject *Sender) ModalResult = mrOk;

, .

( image), () Canvas. (, , . .) , canvas . , , L i n e , E l l i p s e , R e c t a n g l e . .,

Canvas. , Line, E l l i p s e , Rectangle . ., Brush canvas. , Textout Font canvas.

onPaint.

, ,

82

1.

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

. 1.26. Graphics::TBitmap *bgp; // AnsiString sMonth[] = ("","","","",

"","","", "","","", "","",""}; // fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) { bgp = new Graphics::TBitmap(); try bgp->LoadFromFile("sky.tamp");

c a t c h (EFOpenError &e)

83

// Paint void fastcall TForml::FormPaint(TObject *Sender) { int h; AnsiString mes; int wt,ht; int ,; // () // // ( ) // //

h = HourOf( Now() ); if ( h Name = "Times New Roman"; //Forml->Font->Color = clBlue; Forml->Canvas->Font->Size = 20; // wt Canvas->TextWidth(mes); ht = Canvas->TextHeight(mes); x = (ClientWidth - wt) / 2; = ClientHeight / 2 - ht; // Canvas->Draw(0,0,bgp); //

84 Canvas->Brush->Style = bsClear; Canvas->TextOutA(x,y,mes);

1.

= + ht; // // // mes = FormatDateTime(" d", Ncw() ); mes = mes + " " + sMonth[MonthOf( Now())] + ", " FormatDateTime("dddd", Now() ); /* 4 */ Canvas->Font->Size -= 4; wt = Canvas~>TextWidth(mes); ht = Canvas->TextHeight(mes); x = (ClientWidth - wt) / 2; = + 6; Canvas->TextOutA(x,,mes);

// void { Forml->Refresh(); // fastcall TForml::FormResize(TObject *Sender)

(. 1.27) .

85

, , !

. 1.27. // fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) { Canvas->Font->Name = "Tahoma"; Canvas->Font->Size = 12; \

void {

fastcall TForml::FormPaint(TObject *Sender) tdefine WB 140 #define HB 80 #define D 36 // // // i

int x,y; AnsiString st = ", , !"; // = (ClientWidth - WB) / 2; = (ClientHeight - HB ) / 2 - Canvas->Font->Size; // Canvas->Brush->Color = (TColor) RGB(255,255,255); Canvas->FillRect( Rect(x,y,x+WB,y+HB) );

86

1. int xl = (ClientWidth - Canvas->TextWidth(st)) / 2;

/* , Ellipse , , Brush->Style bsClear */ Canvas->Brush->Style = bsClear; // Canvas->TextOutA(xl,y+HB+6,st); Canvas->Pen->Width = 2; // - // // 3.2 * D - , 1- // = + (WB - 3.2 * D) / 2; y=y+(HB-1.6*D)/2; Canvas->Pen->Color = (TColor) RGB(0,0,225); Canvas->Ellipse(x,y,x+D,y+D); x = x + 1.1* D , Canvas->Pen->Color = clBlack; Canvas->Ellipse(x,y,x+D,y+D); X = x + 1.1 * D; Canvas->Pen->Color = (TColor) RGB(255,0,0); Canvas->Ellipse(x,y,x+D,y+D); // x = x - D * 0.55; = + 0.6 * D; Canvas->Pen->Color = (TColor) RGB(0,128,0); Canvas->Ellipse(x,y,x+D,y+D); // // // //

X = X - 1.1 * D; Canvas->Pen->Color = (TColor) RGB(250,217,25); Canvas->Ellipse(x,y,x+D,y+D);

87

//

// void fastcall TForml::FormResize(TObject *Sender) { Forml->Refresh();

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

28,1528,15 28,11 28,08 28

27,98 27,94 ^ ^ 5

d

i

l

l

. 1.28. f l o a t d a t a [ ] = {27.98, 2 8 . 0 1 , 2 7 . 9 6 , 27.96., 2 8 . 1 1 , 2 8 . 0 8 , 28.00, 27.98, 28.15, 28.15, 28.11, 27.94, 27.86, 27.88, 27.95, 27.95};

88

1.

AnsiString Title = " "; void { int x,y; // Canvas->Font->Name = "Tahoma"; Canvas->Font->Size = 1 2 ; x = (ClientWidth - Canvas->TextWidth(Title)) /2; Canvas->Brush->Style = bsClear; Canvas->TextOutA(x,10,Title); // int n; // int wCol; // #define MC 5 // n = sizeof(data) / sizeof(float); wCol = (ClientWidth - (n - 1)*MC - 20) / n; x = 10; = ClientHeight - 20; // int min,max; min = 0 ; max = 0 ; // , , fastcall TForml::FormPaint(TObject *Sender)

// //

for (int i = 1; i < n; i++) if (datati] < data[min]) min = i;

if (data[i] > data[max]) max = i;

/* , . , . */ bool frmin = true; // true - int h; // // // ClientHeight - 90 Canvas->Font->Size -= 2; for ( int i = 0; i < n; i++) { if (I frmin) h = (ClientHeight - 90) * data[i]/data[max]; else /* . 10 */ h = (ClientHeight - 90) * (data[i] data[min])/(data[max] - data[min]) + 10; Canvas->Brush->Style = bsSolid; Canvas->Brush->Color = clLime; Canvas->Rectangle(x,y,x+wCol,y-h); // // AnsiString st; st = FloatToStrF(data[i],ffGeneral,5,2); Canvas->Brush->Style = bsClear,- // // -

90 Canvas->TextOutA(x,y-h-20,st); = + wCol + ;

1.

// void { F o r m l - > R e f r e s h ( ) ; / / fastcall TForml::FormResize(TObject *Sender)

(. 1.29) . , , . , ( ) .W 23,15 28,11 28,11

-iDlxj

. 1.29.

91_

float data[] = {27.98, 28.01, 27.96, 27.96, 28.11, 28.08, 28.00, 27.98, 28.15,28.15, 28.11, 27.94, 27.86, 27.88, 27.95, 27.95}; AnsiString Title = " "; fastcall TForml::TForml(TComponent* Owner) : TFormfOwner)

void {

fastcall TForml::FormPaint(TObject *Sender) int n; int x,y; int dx; int x0,yO; // // // X // // // Canvas->Font->Name = "Tahoma"; Canvas->Font->Size = 12, = (ClientWidth - Canvas->TextWidth(Title)) /2; Canvas->Brush->Style = bsClear; Canvas->TextOutA(x0,10,Title); n = sizeof(data) / sizeof(float); // int min,max; // . , min = 0 ; max = 0 ; // //

for (int i = 1; i < n; i++)

4 3. 1241

1. if (datafi] < data[min]) min = i; if (data[i] > data[max]) max = i;

/*

, . , . */

bool frmin = true; // true - // dx= (ClientWidth - 20) / (n-1); Canvas->Font->Size -= 2; Canvas->Pen->Color = clGreen; Canvas->Pen->Width = 1; xO = 10; yO = ClientHeight - 10; x = xO; dx= (ClientWidth - 20) / (n-1); for ( int i = 0; i < n; i++) { /* ClientHeight - 90 */ if ( frmin) ! = 0 + (ClientHeight- - 90) * data [i]/data[max] ; else // = yO-(ClientHeight - 90) * (data[i] data[min])/(data[max] - data[min])-10;

/ /

93

Canvas->Rectangle(-2,-2,+2,+2); if ( i != 0) Canvas->LineTo(x,y); // ** ** /* .. TextOutA (, LineTo, (,) */ if ( ( i == 0) || (data[i] != data[i-l])) AnsiString st; st = FloatToStrF(data[i] , ffGeneral, 5,2) , Canvas->Brush->Style = bsClear; Canvas->TextOutA(x,y-20,st); Canvas->MoveTo(x,y); x += dx;} ' .

//

// -

// void { Forml->Refresh(); // fastcall TForml::FormResize(TObject *Sender)

(. 1.30) , . "

94

1.

" ( ), . . .'

, 40% [ | | , 24% | , 23% | , 7% | , 2,5% , 0,5%

. 1.30. #include "Math.h" // sin cos TForml *Forml; #undef PEOPLE #define ENERGY #ifdef PEOPLE #define HB 6 define OBR /* ( ) */ // *** *** AnsiString Title = " "; // // " " // " "

float datafHB] = {1.25e9,19,2746,2166,1726,146}; // () float pr[HB]; // *** *** AnsiString dTitle[HB] = {"","","", "","",""}; // *** *** TColor cl[HB] = {clLime, clBlue, clMaroon, clGreen, clYellow, clTeal}; #endif #ifde ENERGY #define HB 6 #undef OBR /* - data 100 */ // *** *** AnsiString Title = " "; float data[HB] = {0.5,2.5,7,23,24,40}; // float pr[HB]; // // ()

95

// *** *** AnsiString dTitle[HB] - ("", " ", " ", "","",""}; // *** *** TColor cl[HB] = {clLime, clBlue, clPurple, clSkyBlue, clYellow, clTeal};

1, #endif #define R 80 //

#define D 160 // #define TORAD 0.0174532 // . // /* , Pi/180 */ // fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) int i,j; // "" float bd; AnsiString bt; TColor be;. for (i = 0; i < KB; i ++) for (j = 0 ; j < HB-1; j++) if (data[j+l] < datatj]) // i- i+1- bd = datatj]; datatj] = data[j+l]; data[j+l] = bd; bt = dTitletj]; dTitletj] = dTitle[j+l]; dTitle[j+l] = bt; be = cl[j];

cl[j+l] = be;

97

#ifdef OBR // - // float sum = 0; for (i = 0; i < HB; i++) sum += data[i]; for (i = 0; i < HB; i++) pr[i] = ( data[i] / sum) * 100; #else // for ( i = 0; i < HB; pr[i] = data[i]; #endif

// Paint void { int x,y;int i;

fastcall TForml::FormPaint(TObject *Sender)

// *** *** Canvas->Font->Name = "Tahoma"; Canvas->Font->Size = 12; x = (ClientWidth - Canvas->TextWidth(Title)) /2; Canvas->Brush->Style = bsClear; Canvas->TextOutA(x,15,Title);

98 // *** ***

1.

// , - // , , // = (ClientWidth - D) /2 - R; = 15 + Canvas->TextHeight(Title) + 20; int xO,yO; // () int xl,yl; // int x2,y2; // int al,a2; // , // // // int n; // ()

n = sizeof(data) / sizeof(float); xO = x + R; yO = + R; al = 0; // //Canvas->Pen->Style = psClear; for (int i = 0; i < HB; i++ ) /* - , . , */ if (i != -1) 2 = ( al + 3.6 * pr[i]);

else 2 = 359; // xl = + R * cos (2 * TORAD); yl = + R * sin (2 * TORAD); // 2 = + R * cos (al * TORAD); 2 = + R * sin (al * TORAD); if ( abs(al-a2) Pen->Style = psClear; else Canvas->Pen->Style = psSolid; Canvas->Brush->Color = Canvas->Pie(x,y,x+D,y+D,xl,yl,x2,y2);

9

al =a2; //

// Canvas->Font->Size -= 2; int dy = Canvas->TextHeight("a"); x = x + D + 40; = + 20; for (i =HB-1; i >=0; i) { Canvas->Brush->Color = cl[i]; Canvas->Rectangle(x,y,x+40,y+dy); Canvas->Brush->Style = bsClear; Canvas->TextOutA(x+50,y,dTitle[i]+ ", " + FloatToStrF(pr[i],ffGeneral,2,2)

100 = + dy +10;

1.

void

fastcall TForml::FormResize(TObject *Sender) Forml->Refresh();

(. 1.31) JPEG, . () . -. . 1.32, imagei . 1.7. - interval .ftff

I

[ !

f~

. 1 . 3 1 . -

\'

101

Label!

' Buttoni CheckBoxi Imagei .:::!::: Timerl

I

Button2

. 1.32.

1.7. imagei Autosize Stretch Proportional

false false true

#include tinclude

// SelectDirectory // // JPEG

AnsiString aPath;

// , //

TSearchRec aSearchRec; // -

102 void

1. fastcall TForml::FormCreate(TObject *Sender) aPath = ""; // - , // FirstPicture(); // , //

// void fastcall TForml::ButtonlClick(TObject *Sender) if (SelectDirectory(" , " " ", "", aPath) ! = // aPath = aPath + " \ \"; if ( FirstPicture() ) // CheckBoxl->Enabled = true; else Labell->Caption = " " + aPath + " jpg-." ;

// bool fastcall TForml::FirstPicture() { Imagel->Visible false; Button2->Enabled = false; CheckBoxl->Enabled = false; CheckBoxl->Checked = false; Labell->Caption = if (FindFirst(aPath+ "*.jpg", faAnyFile, aSearchRec) == 0) Imagel->Picture->LoadFromFile(aPath+aSearchRec.Name); // Imagel //

Imagel->Visible = true; Labell->Caption = aPath + aSearchRec.Name; if ( FindNext(aSearchRec) == 0 ) //

103

// . .

Button2->Enabled = true; // // CheckBoxl->Enabled = true; return true; } } return false;

// bool fastcall TForml::NextPicture() Imagel->Picture->LoadFromFile(aPath+aSearchRec.Name); Labell->Caption = aPath + aSearchRec.Name; if ( FindNext(aSearchRec) != 0 ) // . // // Button2->Enabled = false; CheekBoxl->Enabled = false; return false; return true; // //

// void fastcall TForml::Button2Click(TObject *Sender)

104 NextPicture();

1.

// "" void { if ( CheckBoxl->Checked) Timerl->Enabled = true; else Timerl->Enabled = false; // // - fastcall TForml::CheckBoxlClick(TObject *Sender)

/ / void {

-

f a s t c a l l T F o r m l : : T i m e r l T i m e r ( T O b j e c t *Sender) if ( ! NextPicture()) Timerl->Enabled = false;

(. 1.33) , .

. 1.33.

105

#include "DateUtils.hpp" // SecondOf, MinuteOf // HourOf include "math.h" // sin cos

/* SinCos, , . , ^include "Math.hpp" */ tdefine R 75 int , ; // // // ()

int ahr,amin,asec;

fastcall TForml::TForml(TComponent* Owner) : TFormfOwner) { TDateTime t; // // ClientHeight = (R + 30)*2; ClientWidth t = = = = (R + 30)*2; R + 30; R + 30; Now();

/* . () , , 2 3, -30 . - 6 . 12- */ ahr 90 - HourOf(t)*30-(MinuteOf(Today() ) / 12) *6;

106 amin asec = =

1. 90 - MinuteOf(t)*; 90 - SecondOf( Today() )*6; 1000; // // 1 true; //

Timerl->Interval = Timerl->Enabled =

// (0,0) // X. 1 . void fastcall TForml: .-Vector (int xO, int yO, int a, int 1) { // x0,y0 - / / a - // 1 - #define TORAD 0.0174532 // // int , ; //

Canvas->MoveTo(x0,0); = + 1 * cos(a*TORAD); 0 - 1 * sin(a*TORAD); Canvas->LineTo(x,y);

// void fastcall TForml::FormPaint(TObject *Sender) int x, ; int a; int h; // // (0,) (,) //

TBrushStyle bs; // TColor pc; //

int pw; bs pc pw = = = //

107

Canvas->Brush->Style; Canvas->Pen->Color; Canvas->Pen->Width; = = bsClear;

Canvas->Brush->Style Canvas->Pen->Width Canvas->Pen->Color =

1; clBlack;

a = 0; // 3- , // h = 3; // 0 - 3 // while ( < 360 ) { = + = R * cos( * TORAD); R * sin( * TORAD);

Forml->Canvas->MoveTo(,); if ( (a % 30) 0 ) { Canvas->Ellipse(-2,-2,+3,+3); // = + = h--; if ( h == 0 ) h = 12; } else Canvas->Ellipse (x.-l, y-1, x+1, y+1) ; a = a + 6; // 1 - 6 } // (R+15) * cos(a * TORAD); (R+15) * sin(a * TORAD); .

Canvas->TextOut(x-5,y-7,IntToStr(h));

108 Canvas->Brush->Style Canvas->Pen->Width = bs; = pw;

1.

Canvas->Pen->Color = pc; DrawClock();

void

fastcall TForml::DrawClock(void)

TDateTime t; // 6 , // - 30. // Canvas->Pen->Color = Canvas->Pen->Width // Vector(xO,yO, ahr, R-20); // Vector(xO,yO, amin, R-15); // Vector(xO,yO, asec, R-7); t = Now(); clBtnFace; = 3;

// ahr amin asec = = = 90 - HourOf(t)*30-(MinuteOf(t)% 12)*6; 90 - MinuteOf(t)*6; 90 - SecondOf(t)*6;

// // Canvas->Pen->Width = 3; clBlack; Canvas->Pen->Color =

Vector(xO,yO, a h r , R-20);

109

// Canvas->Pen-:>Width = 2; clBlack; Canvas->Pen->Color =

Vector(xO,yO, amin, R-15); // Canvas->Pen->Width = 1; clYellow,Canvas->Pen->Color =

Vector(xO,yO, asec, R-7);

/ / ' void {

f a s t c a l l T F o r m l : : T i m e r I T i m e r ( T O b j e c t *Sender) DrawClockO ;

- - , . : (. 1.34), . Timer.

. 1.34. -

110 /* "-"

1.

*/ int , ; int dx, dy; int r; // // //

TColor cBall; // TColor cBack; // int wp, hp; // ()

// int rd; // 0 - ; 1 - // ; 2 - int rxl, rx2; // X int ry; int rdx; // Y //

// fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) { r = 5; dx = 1; dy = 1; cBall = (TColor)RGB(217, 217, 25); // cBack = (TColor)RGB(33, 94, 33); Forml->Color = cBack; wp = Forml->ClientWidth; hp = Forml->ClientHeight; // // x = ; = 50; //

// // ( )

111

rd = 0; rxl = 100; 2 - 12 5;

ry = Forml->ClientHeight - 20; // // 20 rdx = 2; // // Timerl->Interval = 10; Timerl->Enabled = true,-

void {

fastcall TForml::FormPaint(TObject *Sender)

// Forml->Canvas->Pen->Color = clRed; Forml->Canvas->Rec tangle(rxl, ry, rx2, ry+1) ;

/ / void {

fastcall TForml::TimerlTimer(TObject *Sender)

// Forml->Canvas->Pen->Color = ; Forml->Canvas->Ellipse(x,y,x+r,y+r); // ** ** if ( dx > 0 ) { // if ( x + d x + r > w p ) d x = - dx;

112 else // if ( x + d x - r < O ) d x = -dx;

1.

if ( dy > 0 ) { // if (( >= rxl) && ( Forml->ClientHeight ) dy = -dy; } else { // if ((x >= rxl) && (x = ry - r) && (y < ry + r) ) { // // . // , . Forml->Canvas->Pen->Color = clRed; Forml->Canvas->Rectangle(rxl, ry, rx2, ry+1); } if ( + dy - r < 0 ) dy = -dy; } x += dx; += dy; // Forml->Canvas->Pen->Color = cBall; Forml->Canvas->Ellipse(x,y,x+r,y+r);

/ / *** if { / / // // if { // if { / / Forml->Canvas->Pen->Color = cBack,Forml->Canvas->Rectangle(rxl, ry, ry + 1 ) ; // Forml->Canvas->Pen->Color = clRed; ( rx2 < wp ) " " " " ( r d != ) ***

/3

(. FormKeyDown ) ( r d == 1 )

r x l + rdx,

Forml->Canvas->Rectangle (rx2, ry, rx2 + rdx, ry + 1) ; rxl += rdx; rx2 += rdx;

else // if (rxl > 1 ) { / / Forml->Canvas->Pen->Color = cBack; Forml->Canvas->Rectangle (rx2, ry, rx2 - rdx, ry+1); // Forml->Canvas->Pen->Color = clRed; Forml->Canvas->Rectangle(rxl - rdx, ry, rxl + rdx, ry+1);

114rxl -= rdx; rx2 -= rdx; } } } // void

1.

fastcall TForml : : ForrriKeyDown (TOb ject *Sender, WORD &Key, T ShiftState Shift) if ( r d != ) / / return,s w i t c h ( Key ) case VK_LEFT : // () rd = 2; break; case VK_RIGHT : // () rd = 1; break; ,

// void { r d = 0; fastcall TForml::FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift)

(. 1.35) ( ).

115

. 1.35.

(. 1.36) . ( ), .

. 1.36. // fastcall TForml::TForml(TComponent* Owner) : TFormlOwner) // bmp- back = new Graphics::TBitmap(); back->LoadFromFile("sky.bmp"); // () //

116 ClientWidth = back->Width; ClientHeight = back->Height; // sprite = new Graphics::TBitmap(); sprite->LoadFromFile("plane.bmp"); sprite->Transparent = true; // kadr new Graphics::TBitmap(); kadr->LoadFromFile("plane.bmp"); //

1.

j

x=-40; // "" - =20; Timerl->Interval = 10; Timerl->Enabled = true;

// void { TRect badRect; // , // TRec t f rameRec t ; fastcall TForml::TimerlTimer(TObject *Sender)

badRect = Rect(x,y,x+sprite->Width,y+sprite->Height) frameRect = Rect(0,0, kadr->Width, kadr->Height); #ifdef ONCANVAS

// *** ( *** )

1J7_

//

""

Canvas->CopyRect(badRect,back->Canvas,badRect); / / +=2; if ( > ClientWidth) { / / = -20; = random(ClientHeight - 30); // // OnTimer, Interval 10 29 // } Canvas->Draw(,,sprite); #else // , // // // / / back->Canvas,badRect); "" / / //

, ,

//

T i m e r l - > I n t e r v a l = random(20) + 10; / /

kadr->Canvas->CopyRect(frameRect, kadr->Canvas->Draw(0,0,sprite); / /

118 Forml->Canvas->Draw(x,y,kadr); // += 1; if ( > ClientWidth)

1.

// // = -20; = random(ClientHeight - 30); // // // OnTimer, , , // Interval Timerl->Interval = random(20) + 10; // // "" 10 29 #endif } void fastcall TForml::FormPaint(TObject *Sender) // Canvas->Draw(0,0,back); //

(. 1.37) . ( ) . "" - . , , , .

4 ,

119

.. + +Builder. -'

. 1.37. Graphics::TBitmap *banner; // - // int x,y; int pause; int xp; TColor be; // // // ( ) // // //

// fastcall TForml::TForml(TCoinponent* Owner) : TForm(Owner) banner = new Graphics::TBitmap(); // banner->LoadFromResourceID((int)HInstance,101); be = banner->Canvas->Pixels[O][0]; // x = Forml->ClientWidth; // "" - // = 0; // X // xp = (Forml->ClientWidth - banner->Width) / 2; if (xp < 0 ) xp = 0;

120

1.

// void fastcall TForml::TimerlTimer(TObject *Sender) if ( pause > 0 ) pause; return;

Forml->Canvas->Draw(x,,banner); if ( x == xp) pause = 100; // // 100

if ( < - banner->Width) = Forml->ClientWidth;

// Paint void fastcall TForml::FormPaint(TObject *Sender) TColor b,p; b = Canvas->Brush->Color,- // = Canvas->Pen->Color; // // // Canvas->Brush->Color = be; Canvas->Pen->Color = be; Canvas->Rectangle(O,O,ClientWidth,banner->Height);

Canvas->Brush->Color = b ; / / Canvas->Pen->Color = p ; / /

121

// void { / / // if / 2,(xp < 0 ) = 0; fastcall TForml::FormResize(TObject *Sender)

= (Forml->ClientWidth - banner->Width)

, . , . , , . 1.38.

. 1.38. () ()

122// void {

1. fastcall TForml::FormCreate(TObject *Sender)

back = new Graphics::TBitmap(); // // // try // { Forml->back->LoadFromFile("canvas.bmp"); } catch (EFOpenError &e) { return,-

// void { int x=0,y=0; // // if ( back->Empty ) // return; do { do { Canvas->Draw(x,y,back); x += back->Width; } while (x < ClientWidth); fastcall TForml::Background() ,.

= 0; += back->Height; } while ( < ClientHeight);

123

// Paint void { B a c k g r o u n d ( ) ; / / fastcall TFormlt:FormPaint(TObject *Sender)

5 3. 1241

, , .

Animate MediaPlayer.

MediaPlayer , . Animate , .

WAV Windows (. 1.39) ( WAV, RMI MID), Windows\Media. Microsoftwav ir_begin.wav ir_end.wav ir_inter.wav Windows.wav Windows.wav ringin.wav ringoutwav start wav chimes.wav chord.wav ding, wav . W . . .

1

. 1.39. Windows , WindowsVMedia

125

. , . . 1.40. Windows

Label2

ListBoxi

CheckBoxi MediaPlayeri-

V I

. 1.40. Windows / / void f a s t c a l l TForml::FormCreate(TObject *Sender) { char *wd; // Windows wd = (char*)AllocMem(MAX_PATH); GetWindowsDirectory(wd,MAX_PATH); SoundPath = wd; // Media SoundPath = SoundPath + "WMediaW" ; //

126 TSearchRec sr;

1.

if (FindFirst( SoundPath + "*.wav", faAnyFile, sr) == 0 ) // WAV ListBoxl->Items->Add(sr.Name); // // // WAV ? while (FindNext(sr) == 0 ) ListBoxl->Items->Add(sr.Name);

if (FindFirstf SoundPath + "*.mid", faAnyFile, sr) == 0 ) { // MID ListBoxl->Items->Add(sr.Name); // // // MID ? while (FindNext(sr) == 0 ) ListBoxl->Items->Add(sr.Name);

if (FindFirst( SoundPath + "*.rmi", faAnyFile, sr) == 0 { // RMI ListBoxl->Items->Add(sr.Name); // // // RMI ? while (FindNext(sr) == 0 ) ListBoxl->Items->Add(sr.Name);

// if ( ListBoxl->Items->Count != 0)

727

{Label2->Caption = ListBoxl->Items->Strings[1]; ListBoxl->ItemIndex = 0; MediaPlayerl->FileName = SoundPath + ListBoxl-> Items->Strings[1] ; MediaPlayerl->Qpen(); MediaPlayerl->Play();

// void fastcall TForml::ListBoxlClick(TObject *Sender) { if ( (CheckBoxl->Checked) && ( MediaPlayerl->Mode == mpPlaying ) ) return; Label2->Caption = ListBoxl->Items-> Strings[ListBoxl->ItemIndex]; MediaPlayerl->FileName = SoundPath + Label2->Caption; MediaPlayerl->Open(); if ( ! CheckBoxl->Checked) MediaPlayerl->Notify = false; MediaPlayerl->Play();

/* Notify , Play Notify true */ void fastcall TForml::MediaPlayerlNotify(TObject *Sender) { if ( ListBoxl->ItemIndex < ListBoxl->Items->Count ) { ListBoxl->ItemIndex = ListBoxl->ltemlndex + 1;

128

1. Label2->Caption = ListBoxl->Items-> Strings[ListBoxl->ItemIndex]; MediaPlayerl->FileName = SoundPath + Label2->Caption; MediaPlayerl->Open()j if ( ! CheckBoxl->Checked) MediaPlayerl->Notify = false; MediaPlayerl->Play();

MP3

Player

Player (. 1.41) .'S Player Thoughts o f a dying atheist. mp3 Thoughts ot a wina atheret.mc3 Butterflies and Huiricanes.mp3 Muse Map of your head.mp3 Hypernnusic.mp3 Hyper chondriac music. mp3 Endlessly. mp3 Stockholm syndrome.mp3 Sinn fmflhsnluhnnmn3 2:57

. 1.41. ,

. 1.42. , MediaPlayerl, ( ). (), , , Eject (speedButtoni). , SpeedButton2 SpeedButton4 -

,

129

speedButtoni speedButton3 (). Play/Stop (speedButton3) . : " Play", " Stop" " Play". , , 101, 102 103. . 1.8. Player Labell

ListBoxi

TrackBart

SpeedButtoniSpeedButton2 SpeedButton3 Speedbutton4 Label2 LabeH

-Timer!

. 1.42. Player 1.8. TrackBarl Orientation Min ThumbLength TickMarks Frequency ShowHint Hint vrVertical 0 -65535 10 tmBoth 8192 true

130 TForml *Forml; //

1.

fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) / * MediaPlayer. ). "MPlayer.hpp"

MediaPlayerl

(. mp3main.h), MPlayer.hpp */

( include

MediaPlayerl new TMediaPlayer(Forml->Handle);

#include "FileCtrl.hpp"

// TSearchRec

AnsiString SoundPath; // - int min,sec; int mode = 0 ; // (, ) // 0 - ""

// 1 - "" /* vaweOutSetVolume , , - . TVolume, . OxFFFF. */ union TVolume{ unsigned long Volume; struct Word Left;

Word Right; }; } volume; // void { PlayList(""); // // , waveOutGetVolume(0,&volume.Volume); TrackBarl->Position = - volume.Left; ListBoxl->Color = (TColor)RGB(56,176,222); fastcall TForml::FormCreate(TObject *Sender)

/ / -, // { / * SearchRec TSearchRec SearchRec; ListBoxl->Clear(); / / { -

void __fastcall TForml::PlayList(AnsiString path) ,

*/

if ( FindFirst(path + "*.mp3", faAnyFile, SearchRec)!= 0 ) // - SpeedButton2->Enabled = false; SpeedButton3->Glyph-> LoadFrornResourceID( (int)HInstance, 103) ; SpeedButton4->Enabled = false;

132 Labell->Caption return,-

1.

// // ListBoxl->Items->Add(SearchRec.Name); // wav while (FindNext(SearchRec) 0) ListBoxl->Iterns->Add(SearchRec.Name); ListBoxl->ItemIndex = 0; Strings [ListBoxl->ItemIndex]; SpeedButton2->Enabled = false; if (ListBoxl->Coxmt == 1) SpeedButton4->Enabled = false; else SpeedButton4->Enabled = true; SpeedButton3->Glyph-> LoadFromResourcelDf(int)HInstance,101);

Labell->Caption = ListBoxl->Items->

// -, // ListBox void { Labell->Caption = ListBoxl->Items-> Strings [ListBoxl->ItemIndex]; MediaPlayerl->FileName = SoundPath + ListBoxl->Items->Strings [ListBoxl->ItemIndex], MediaPlayerl->Open(); MediaPlayerl->Play(); fastcall TForml::Play()

min = 0; sec = ; Timerl->Enabled = true;

133

// void fastcall TForml::Stop() { MediaPlayerl->Stop(); Timerl->Enabled = false; Label2->Caption = "0"; Label4->Caption "00";

// Play/Stop // ( ) void fastcall TForml::SpeedButton3Click(TObject *Sender) { if ( mode == 1 ) { SpeedButton3->Glyph-> LoadFromResourcelD((int)Hlnstance, 101) SpeedButton3->Hint = ""; StopO; mode = 0; } else { SpeedButton3->Glyph-> LoadFromResourcelD((int)HInstance, 102); SpeedButton3->Hint = ""; Play(); mode = 1;

134 // void {

1.

fastcall TForml::TimerlTimer(TObject *Sender) // if ( sec < 59 ) { sec++; if ( sec < 10) Label4->Caption = "0" + IntToStr(sec); else Label4->Caption = IntToStr(sec); } else sec = 0; min++; Label2->Caption = IntToStr(min) Label4->Caption = "00";

// ? if ( MediaPlayerl->Position < MediaPlayerl~>Length ) // return; // Stop(); if ( ListBoxl->ItemIndex < ListBoxl->Count - 1 ) ListBoxl->ItemIndex += 1; PlayO; // // -

if ( ListBoxl->ItemIndex == ListBoxl->Count - 1 ) SpeedButton4->Enabled = false; } else { // - SpeedBut ton3->Glyph->

135

LoadFromResourcelD((int)HInstance, 101); SpeedButton3->Hint = ""; mode = 0;

// " " void fastcall TForml::SpeedButton4click(TObject *Sender) { if ( mode == 1 ) Stop(); // // ListBoxl->ItemIndex += 1; Labell->Caption = ListBoxl-> Items->Strings [ListBoxl->ItemIndex]; // , , // if ( ListBoxl->ItemIndex == ListBoxl->Count - 1) SpeedButton4->Enabled = false,if ( ! SpeedButton2->Enabled )

SpeedButton2->Enabled = true; if ( mode == 1) PlayO; // //

136

1.

// " " void fastcall TForml::SpeedButton2Click(TObject *Sender) { if ( mode == 1 ) Stop(); // // ListBoxl->ItemIndex -= 1; Labell->Caption = ListBoxl->Iteitis-> Strings [ListBoxl->ItemIndex]; // , , // if ( ! SpeedButton4->Enabled ) SpeedButton4->Enabled = true; if ( ListBoxl->ItemIndex == 0 ) SpeedButton2->Enabled = false; if (mode == 1 ) PlayO; // //

iinclude "FileCtrl.hpp" // Eject - void fastcall TForml::SpeedButtonlClick(TObject *Sender) AnsiString dir; if ( SelectDirectory(" ","",dir) ) if ( mode = = 1 ) // Stop () ; ""

SpeedButton3->Glyph->

737LoadFroirtResourcelD((int)HInstance, 101); SpeedButton3->Hint = ""; Stop(); mode = 0;

} SoundPath = dir + "\\"; PlayList(SoundPath);

// () void fastcall TForml::ListBoxlClick(TObject *Sender) { if ( MediaPlayerl->Mode ==2) // { Stop () , // Play(); //

// , , // if (ListBoxl->ItemIndex == 0 ) SpeedButton2->Enabled = false; else SpeedButton2->Enabled = true; if (ListBoxl->ItemIndex == ListBoxl->Count -1 SpeedButton4->Enabled = false; else SpeedButton4->Enabled = true; )

include "mmsystem.hpp"

138void {

1. fastcall TForml::TrackBarlChange(TObject *Sender)

//

volume.Left = - TrackBarl->Position,volume.Right = - TrackBarl->Position; waveOutSetVolume(0,volume.Volume);

MIDI 60 , . 1.43, MediaPlayer MIDI. " ", , , . 60

**! 60 , OK - 60 Timeri Label4 II ! !

MediaPlayeri

. 1.43. 60 int pw; // ""

int rem = 60; // // void fastcall TForml::FormCreate(TObject *Sender) { TSearchRec sr; if ( F i n d F i r s t ( " * . m i d " , f a A n y F i l e , s r ) == 0)

{ MediaPlayerl->FileName = sr.Name; MediaPlayerl->Open(); MediaPlayerl->Play();

739

Randomize(); pw = RandomRange(100,999); // ""

// , void fastcall TForml::isRight(void) { if ( StrToInt(Editl->Text) == pw ) { Timerl->Enabled = false; Buttonl->Enabled = false; Editl->Enabled = false; MediaPlayerl->Stop(); // ! //PlaySound("Applause.wav", 0, SND_ASYNC); ShowMessage("!\ " + IntToStr(60 - rem)+ " ");

// void fastcall TForml::EditlKeyPress(TObject *Sender, char &Key) { if ( ( E d i t l - > T e x t . L e n g t h ( ) < 3) & & ( (Key >= ' 0 ' ) Scb (Key Text.Length() == 3) Buttonl->Enabled = true,else Buttonl->Enabled = false;

// OK void fastcall TForml::ButtonlClick(TObject *Sender) { isRight(); // , //

// void fastcall TForml::TimerlTimer(TObject *Sender) rem--; Label4->Caption = IntToStr(rem);

if { // , , Timerl->Enabled = false; Editl->Enabled = false; Buttonl->Enabled = false; MediaPlayerl->Stop(); ShowMessage(" , " " \" (rem == 0 )

1_

"\"\" - " + intToStr(pw) );

// void { /* Notify true ( Play Notify true), Notyfy */ if (Timerl->Enabled) /* , . . */ MediaPlayerl->Play(); } // void fastcall TForml::FormClose(TObject *Sender, TCloseAction SAction) { Timerl->Enabled=false ; MediaPlayerl->Stop(); MediaPlayerl->Close(); fastcall TForml::MediaPlayerlNotify(TObject *Sender)

142

1.

Compact Disk Player ( 1) Compact Disk Player . , -, CD, , () (. 1.44). o p c Dc Pa e C m at s l y r i 1. 3:08 2:47

. 1.44.

, . . 1.45 ( MediaPiayer ). Timer! Shape! Label! Label2

SpeedButtoni S e d ut n S e d ut n p e B to 2 p e B to 3. 1.45. Compact Disk Player ( 1) // Play/Stop Graphics::TBitmap *bmPlay; // Play Graphics::TBitmap *tmStop; // Stop _fastcall TForml::TForml(TComponent* Owner) : TForm(Owner)

{ fcmPlay = new Graphics::TBitmap(); hmStop = new Graphics::TBitmap();

143

// Play/Stop fcmPlay->LoadFromResourceID((int)HInstance,101); fcmStop->LoadFromResourceID((int)HInstance,102); // SpeedButton2->Glyph->Assign(bmPlay);

}void { fastcall TForml::FormCreate(TObject *Sender)

I

MediaPlayer->Notify = true; // Notify

// // , ^define MINUTE(ms) ((ms/1000)/60) #define SECOND(ms) ((ms/1000)%60) // Label 1 void { int ms; // , AnsiString st; Track = MCI_TMSF_TRACK(MediaPlayer->Positicn); fastcall TForml::TrackInfo()

MediaPlayer-XFimeFonnat = tfMilliseconds; ms = MediaPlayer->TrackLength[Track]; MediaPlayer->TimeFormat = tfTMSF; st = IntToStr(SECOND(ms)); if ( st.LengthO 1)

144st = "" + s t ;

1.

st = " "+ IntToStr(Track) + ". "+ IntToStr(MINUTE(ms)} + ":" + st; Labell->Caption = st; } // void fastcall TForml::MediaPlayerNotify(TObject *Sender) { switch ( MediaPlayer->Mode ) { case mpOpen: // { SpeedButtonl->Enabled SpeedButton2->Tag Label2->Caption = = = 0; = false; "00:00"; false; SpeedButton2->Glyph->Assign(bmPlay); SpeedButton3->Enabled

/* */ Timer->Enabled } } MediaPlayer->Notify = true; = True;

// : // void {int trk; //

fastcall TForml::TimerTimer(TObject *Sender)

int min, sec; AnsiString st; //

745

if ( MediaPlayer->Mode == mpPlaying ) // { // trk = MCI_TMSF_TRACK(MediaPlayer->Position);

if ( trk != Track ) // { Tracklnf(); Track = trk; = true; // // "." if ( Track == MediaPlayer->Tracks) SpeedButton3->Enabled = false; // // "." // if ( Track > 1 ) SpeedButtonl->Enabled

// min sec = MCI_TMSF_MINUTE(MediaPlayer->Position); = MCI_TMSF_SECOND(MediaPlayer->Position);

st.printf("%d:%.2d",min,sec); Label2->Caption = st; return;

/ * AudioCD, ,

Mode == mpOpen. .. + - > 1 */

Mode == mpStopped

if ( (MediaPlayer->Mode == mpStopped) && (MediaPlayer->Tracks > 1) )

146{// Timer->Enabled = false; SpeedButton2->Enabled = true,-; SpeedButton2->Tag = 0; SpeedButton3->Enabled = true; MediaPlayer->Notify = true;

1.

// CD MediaPlayer->TimeFormat = tfMilliseconds; int ms = MediaPlayer->Length; AnsiString st = "Audio CD. : "; st = st + IntToStr(MINUTE(ms)); st = st + ":" + IntToStr(SECOND(ms)); Labell->Caption = st;

MediaPlayer->TimeFormat = tfTMSF; Labell->Visible = true; Track = 0; return;

// AudioCD if (( MediaPlayer->Mode == mpOpen ) (MediaPlayer->Tracks == 1)) { Labell->Caption = " AudioCD" , = false; = true; if ( Labell->Visible ) Labell->Visible else Labell->Visible || (MediaPlayer->Mode == mpStopped) &&

// void { MediaPlayer->Stop(); MediaPlayer->Close(); TCloseAction &Action)

147

fastcall TForml::FormClose(TObject *Sender,

// void {

fastcall TForml::SpeedButtonlClick(TObject *Sender)

MediaPlayer->Previous(); //

MediaPlayer->Previous(); // if ( MCI_TMSF_TRACK(MediaPlayer->Position) == 1 ) SpeedButtonl->Enabled SpeedButton3->Enabled TracklnfoO ; Label2->Caption = "0:00" ; = = false; true,if ( ! SpeedButton3->Enabled )

// void { MediaPlayer->Next(); // // Next MediaPlayer->Tracks ) SpeedButton3->Enabled if (!SpeedButtonl->Enabled Tracklnf(); Label2->Caption = "0:00"; = false,) SpeedButtonl->Enabled = true; , fastcall TForml::SpeedButton3Click(TObject *Sender)

if ( MCI_TMSF_TRACK(MediaPlayer->Position) ==

148 // void { if ( SpeedButton2->Tag == 0 ) { // Play MediaPlayer->Play(); Play/Stop

1.

f a s t c a l l T F o r m l : : S p e e d B u t t o n 2 C l i c k ( T O b j e c t *Sender)

SpeedButton2 ->Glyph->Ass ign (bmStop) ; SpeedButton2->Hint = ""; SpeedButton2->Tag = 1; true; // // " " MediaPlayer->Notify Timer->Enabled Tracklnf(); } else { // Stop SpeedButton2->Glyph->Assign(bmPlay); SpeedButton2->Hint = ""; SpeedButton2->Tag MediaPlayer->Notify MediaPlayer->Stop(); Timer->Enabled = false,= 0; = true; = true; = true; //SpeedButton3~>Enabled -

Compact Disk Player ( 2) Compact Disk Player, , , . 1.46 . 1.47, -. , (. 1.47), , ( shapei). . 1.9. ,

149

shape2, . MediaPiayer , Compact Disk Player ( 1). cursor shapei crDrag. Sae hp2 Shapei Label! Label2 -iDlxl Track 0 0:00-

SpeedButtoni S e d ut n S e d ut n S e d ut n p e B to 2 p e B to 3 p e B to 4. 1.46. Compact Disk Player ( 2)

. 1.47. Compact Disk Player ( 2)

1.9. BorderStyle Color TransparentColorValue TransparentColor bsNone clFuchsia clFuchsia true

int px,py; // , // Shapei void fastcall TForml::ShapelMouseDown(TObject *Sender,

150

1. TMouseButton Button, TShiftState Shift, int X, int Y) // , // = X; = Y;

// Shapel void { Forml->Left = Forml->Left + X - px; Forml->Top = Forml->Top + Y - py; fastcall TForml::ShapelMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

/ / void {

Off

()

. f a s t c a l l T F o r m l : : S p e e d B u t t o n 4 C l i c k ( T O b j e c t *Sender)

// MediaPlayer->Stop(); Forml->Close() ;

Video

Player

Video Player, . 1.48 . 1.49 , AVI MPG. , Eject (speedButtoni). speedButton2 , . . , .

151

, , . * V e P y r d o ae i l

. 1,48. Video Player

SpeedButtoni

SpeedButton2

MediaPlayeri

OpenDialogi

. 1.49. Video Player

152

1.

// , // , #define MINUTE(ms) ((ms/1000)/60) #define SECOND(ms) ((ms/1000)%60) // Graphics::TBitmap *fcmPlay; Graphics::TBitmap *fcmPause; // Play // Pause

fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) { kmPlay = new Graphics::TBitmap(); fcmPause = new Graphics::TBitmap(); // Play/Stop bmPlay->LoadFromResourceID((int)HInstance,101); bmPause->LoadFromResourceID((int)HInstance,102); // SpeedButton2->Glyph->Assign(bmPlay); MediaPlayerl->Display = Forml;

// void .fastcall GetFrameSize(AnsiString f, int *w, int *h) { if ( f.Pos(".avi") == 0 ) { // mpg- *w = 352; *h = 240; return;

// *** AVI- ***

// struct char char { RIFF[4]; // RIFF AVIH[4]; // AVIH // // AVI-

153

long int nu_l15]; / / long int nu_2[9]; // long int w; long int h; } header; TFileStream *fs; //

/* : TFileStream *fs = new TFileStreamff, fmOpenRead); */ // // fs->Read(&header, sizeof(header)); *w = header.w; *h = header.h; delete fs; // //

fs = new TFileStream(f,fmOpenRead) ;

// Eject ( ) void { int fw, fh; int sw, sh; int mw, mh; // /,/ (, ) // // ( ) int top,left; // fastcall TForml::SpeedButtonlClick(TObject *Sender)

154

1. // //

float kw, kh; // - float ;

OpenDialogl->Title = " "; OpenDialogl->InitialDir = ""; OpenDialogl->Filter = " |*.avi;*.mpg;*.mpegI" "AVI|*.avi|MPG|*.mpg|MGEG|*.mpeg"; if ( ! OpenDialogl->Execute() ) return; // /* , , . */ if ( MediaPlayerl->FileName == OpenDialogl->FileName ) return; /* . "", . , . */ II GetFrameSize(OpenDialogl->FileName,&fw, &fh); // mw = Forml->ClientWidth; mh = Forml->Panell->Top-10; if ( fw < mw ) kw = 1; // else kw = (float) mw / fw; if ( fh < mh ) kh = 1; // else kh = (float) mh / fh;

// if ( kw < kh )

155

= kw; else = kh;//

sw = fw * ,- / / sh = fh * ; / /

left = (Forml->ClientWidth - sw) / 2; top = (Panell->Top - sh) / 2; MediaPlayerl->FileName = OpenDialogl->FileName; MediaPlayerl->Open(); MediaPlayerl->DisplayRect = Rect(left,top,sw,sh); /* , ( ) */ Forml->Canvas->FillRect(Rect(0,0,ClientWidth,Panell->Top)); SpeedButton2->Enabled = true; // Play // // MediaPlayerl->TimeFormat = tfMilliseconds; int ms = MediaPlayerl->Length; AnsiString st = IntToStr(SECOND(ms)); if ( st.Length() == 1) st = "0" + st; st = IntToStr(MINUTE(ms)) + ":" + st; Labell->Caption = st; Label3->Caption = "0:00"; // SpeedButton2->Glyph->Assign(bmPause);

. 1241

156 SpeedButton2->Hint = "Pause"; SpeedButton2->Tag = 1;

1.

SpeedButtonl->Enabled = False; // Eject MediaPlayerl->Play(); Timerl->Eriabled = t r u e ;

// Play/Stop (/) void { if (SpeedButton2->Tag == 0) { // Play SpeedButton2->Glyph->Assign(bmPause); SpeedButton2->Hint = "Pause"; SpeedButton2->Tag = 1; SpeedButtonl->Enabled = False; // Eject // MediaPlayerl->Play(); Timerl->Enabled = true; } else { MediaPlayerl->Stop(); SpeedButton2->Glyph->Assign(bmPlay); SpeedButton2->Hint = "Play"; SpeedButton2->Tag = 0; SpeedButtonl->Enabled = True; // Eject Timerl->Enabled = false; // Stop fastcall TForml::SpeedButton2Click(TObject *Sender)

// void fastcall TForml::MediaPlayerlNotify(TObject *Sender)

{ if ( ( MediaPlayerl->Mode == mpStopped ) && ( SpeedButton2->Tag == 1)) {

157

Timerl->Enabled false; SpeedButton2->Glyph->Assign(bmPlay); SpeedButton2->Hint = "Play"; SpeedButton2->Tag = 0; SpeedButtonl->Enabled = True; // // Eject

/* Pain () , , , , , Video Player. */ void _fastcall TForml::FormPaint(TObject *Sender) { if ( MediaPlayerl->Mode == mpStopped ) { MediaPlayerl->Position = 1; MediaPlayerl->Position = 0;

// void fastcall TForml::FormClose(TObject *Sender, TCloseAction &Action) { MediaPlayerl->Close();

void

fastcall TForml::TimerlTimer(TObject *Sender)

158

1.

// // MediaPlayerl->TimeFormat = tfMilliseconds; int ms = MediaPlayerl->Position; AnsiString st = IntToStr(SECOND(ms)); if ( st.Length() == 1) st = "0" + st; st = IntToStr(MINUTE(ms)) + ":" + st; Label3->Caption = st;

, . 1.50, AVI- Animate. . , . , Animate , .W'j

Animaei : !

Buttoni

Play

if!?1 - delpN,avl;:

: 36 ; 90x45

. 1.50.

bool loaded = false; // // fastcall TForml::TForml(TComponent* Owner) : TForm(Owner) { /* , */ try { Animatel->FileName = "delphi.avi",} catch (Exception &e) { }

159

Forml->Caption = " - " + Animatel->FileName; loaded = true,Labell->Caption = ": " + IntToStr(Animatel->FrameCount) + " : " + IntToStr(Animatel->Width) + "x" + IntToStr(Animatel->Height);

// void { if ( loaded) // // Animatel->1(1,Animatel->FrameCount,1); fastcall TForml::FonnActivate(TObject *Sender)

160 // Play

1.

void _fastcall TForml::ButtonlClick(TObject *Sender) if ( loaded) // // Animatel->Play(1,Animatel->FrameCount,1);

C++Builder , . BDE- ADO-.

BDE Borland Database Engine. ADO ActiveX () Microsoft. , BDE-, , Borland Database Engine (BDE). BDE C++Builder. , BDE , . , (Alias) BDE Administrator.

() Database Desktop SQL Explorer. (Alias) . , CD. Borland InstallShield Express, C++Builder.

162

1.

, . 1.51, BDE Paradox. adrbk.db (. 1.10). , , , () Name. adrbk. BDE Administrator. T a b l e , D a t a S o u r c e DBGrid

. 1.11, 1.12, 1.13 . 1.10. adrbk (adrbk.db) Name Phone Cell Email A (Alpha) A (Alpha) A (Alpha) A (Alpha) 25 20 20 30 ,

. /j

|

J E-mail

BitBtnl

Button2

1

DataSourcel

Quervi

DBOridi

. 1.51.

163 1.11. Tablel

DatabaseName TableName

adrbk adrbk.db

, 1.12. DataSourcel

DataSet

Tablel

1.13. DBGridl DataSource Columns[0] FildName Columns[0] Title.Caption Columns[1] FildName Columns[1] Title.Caption Columns[2] FildName Columns[2] Title.Caption Columns[3] FildName Columns[3] Title.Caption

DataSourcel Name , Phone Cell Email E-mail

(, , , ) (FindForm) (BitBtnl). (FindForm) . 1.52.

164

1. -JnJjiJ

. 1.52. / / *** () ***

# i n c l u d e " F i n d _ . h " / / // void {

f a s t c a l l TMainForm::FormShow(TObject *Sender)

// adrbk , try { Tablel->Open(); } catch (EDBEngineError &e) { ShowMessage(" : " " adrbk\n" + .Message ); Button2->Enabled = false; BitBtnl->Enabled = false; CheckBoxl->Enabled = false;

// void fastcall TMainForm::BitBtnlClick(TObject *Sender)

{ FindForm->Tag = 0; FindForm->ShowModal(); if ( FindForm->Tag ) { // // , // Queryl->SQL->Text = //

165

"SELECT * FROM adrbk WHERE Name LIKE \042%" + FindForm->Editl->Text if ( CheckBoxl->Checked ) ShowMessage (Queryl->SQL->Text); Queryl->Open(); // () if ( Queryl->RecordCount != 0) DataSourcel->DataSet = Queryl; else { ShowMessage ( " " " : " + FindForm->Editl->Text); DataSourcel->DataSet = Tablel; +"%\042"; // \042 -

// void fastcall TMainForm::Button2Click(TObject *Sender) { // - DataSourcel->DataSet = Tablel;

//

166 void { Tablel->Close();

1. fastcall TMainForm::FormClose(TObject *Sender, TCloseAction SAction)

// void {

*** *** fastcall TFindForm::FormShow(TObject *Sender) Editl->SetFocus(); // //

//

// ( ) void { Tag = 1; // Close(); .fastcall TFindForm::ButtonlClick(TObject *Sender)

// void f a s t c a l l TFindForm::EditlKeyPress(TObject *Sender, char &Key) { if ( Key == 13) Buttonl->SetFocus(); // //

(. 1.53) BDE.

{ 3 990,00.

167 I i xl

(+4 ). 120x70. : .

[ ( 670,00. , . : 2,5 9,00. . . : , 3 990,00 (+4 ). 530,00. , 14, 40 . : 2 590,00. 614,40 . : , I 870,00.: . : . 75,00. . : . :

[: 3

;

. 1.53.

"" stock.db (. 1.14).. 1.14. stock (stock.db) Title Price Memo Image A (Alpha) $ (Money) A (Alpha) A (Alpha) 50 100 30 ( BMP)

stock. BDE Administrator.

168

1.

. 1.54, . 1.15, 1.16, 1.17, 1.18.

D EH Bd i J Bd D EG i D Mml Beo

1

" ' !'" ' i ' . j "

[ |Image

. .1

. 1.54. 1.15. Tablei DatabaseName TableName stock stock.db ,

1.16. DataSet Tablei

DataSourcei

169 1.17. DBGridi

DataSource Columns[0].FildName Columns [0] . T.itle.Caption Columns[1].FildName Columns[1].Title.Caption Columns[2].FildName Columns[2].Title.Caption Columns[3].FildName Columns[3].Title.Caption

DataSourcel Title Price Memo Image Image

1.18. DBEdi t DBMemo

DBEditl.DataSource DBEditl.DataField DBEdit2.DataSource DBEdit2.DataField DBMemol.DataSource DBMemol.DataField

DataSourcel Title DataSourcel Price DataSourcel Memo

/ / void fastcall TForml::FormShow(TObject *Sender) { try { Tablel->Open(); //

170catch ( EDBEngineError &e) {

1.

ShowMessage(" " " stock");

// void { if ( DataSourcel->State == dsBrowse) StatusBarl->Panels->Items[l]->Text = ""; else StatusBarl->Panels->Items[1]->Text = "" fastcall TForml::DataSourcelStateChange( TObject *Sender)

// At'terScroll // ( ) void { AnsiString Picture; if ( Tablel->RecNo != -1) StatusBarl->Panels->Items[0]->Text = ": " + IntToStr( Tablel->RecNo ); /* FieldValue. Image , . */ try { Picture = Tablel->Database->Directory + DataSet->FieldValues["Image"]; fastcall TForml::TablelAfterScroll(TDataSet *DataSet)

catch (EVariantTypeCastError &e) { Imagel->Visible = false; return; } ShowPhoto(Picture); else StatusBarl->Panels->Items[O]->Text = ""; StatusBarl->Panels->Itemsf1]->Text = " Imagel->Visible = false;

171

// Imagel void { . { Imagel->Picture->LoadFromFile(Picture); } catch ( EFOpenError &e) { // , Imagel->Visible = false; return; } Imagel->Visible = true; fastcall TForml::ShowPhoto(AnsiString Picture) try

// void fastcall TForml::FormClose(TObject *Sender, TCloseAction SAction)

172

1.

if (Tablel->State == dsEdit ) / / Tablel->Post(); //

ADO Microsoft Access. (, ). (, ), , " ", " " " ". , " " , , , " " (. 1.55).

-XJ

31 2004 , .12.2004 J03.01.2005 , , 16; 00 (). 12:00 I + -

SQL

. 1 . 5 5 . ,

173

"" (Planner.mdb) schedule (. 1.19). . 1.56, . 1.20, 1.21, 1.22, 1.23. ODBC: Microsoft Access Driver (*.mdb); . DPlanner; ; Planner.mdb. . 1.19. schedule "" (Planner.mdb) aDate aTask / , 50 ()

{ Label! ; Label2

[

")*!

I!

|', |'.

|!:'.", ','. ',".. [

SQL

. 1.56.

174

1. 1.20. ADOConnectionl

ConnectionString

Provider=MSDASQL.1; Persist Security Info=False; Data Source=DPlanner

DSN=DPlanner 1.21. ADODataSeti Connection CommandText ADOConnectionl SELECT


Recommended