.


:




:

































 

 

 

 


.




Windows .

 

.

1. Caption . 4 ListView , . File/Save Project As. D:\ Lab_4 P_work_4.bpr U_work_4.cpp.

2. DriveComboBox1 DriveComboBox2, .1.

 

.1.

3. DirectoryListBox1 DirectoryListBox2, .2.

4. ListView1 ListView2, .3.

5. .

6. Label1 Label2. Caption .4.

 

 

.2.

 

 

. 3.

 

7. ComboBox1 ComboBox2, .4.. Items :

.

8. void __fastcall TForm1::FormCreate(TObject *Sender); U_work_13.cpp.

9. void __fastcall TForm1::DirectoryListBox1Change(TObject *Sender); void __fastcall TForm1::DirectoryListBox2Change(TObject *Sender); U_work_13.cpp.

10. void __fastcall TForm1::ComboBox1Click(TObject *Sender); void __fastcall TForm1::ComboBox2Click(TObject *Sender); U_work_13.cpp.

11. , .5.

 

.4.

 

 

. 5. Windows.

 

U_work_4.cpp.

 

//---------------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

 

#include "U_work_4A.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

//---------------------------------------------------------------------------

void UpdateFiles_1()

{

TSearchRec sr1;

// TSHFileInfo * fi1;

TListItem *pItem1 = NULL;

int IconIndex1;

TSHFileInfo * fi1 = new TSHFileInfo;

Form1->ListView1->Items->BeginUpdate();

Form1->ListView1->Items->Clear();

if (FindFirst(Form1->DirectoryListBox1->Directory + "\\*.*", faAnyFile, sr1) == 0)

do

{

if (sr1.Attr == faDirectory) continue;

pItem1 = Form1->ListView1->Items->Add();

pItem1->Caption = sr1.Name;

SHGetFileInfo(("*" + LowerCase(ExtractFileExt(pItem1->Caption))).c_str(),

0, fi1, sizeof(fi1),

SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_TYPENAME);

pItem1->ImageIndex = fi1->iIcon;

if (sr1.Size < 1024)

pItem1->SubItems->Add(IntToStr(sr1.Size) + " byte");

else if (sr1.Size < 1024 * 1024)

pItem1->SubItems->Add(IntToStr(sr1.Size / 1024) + " KByte");

else pItem1->SubItems->Add(IntToStr(sr1.Size / (1024 * 1024)) + " MByte");

pItem1->SubItems->Add(fi1->szTypeName);

}

while (FindNext(sr1) == 0);

FindClose(sr1);

Form1->ListView1->Items->EndUpdate();

}

//---------------------------------------------------------------------------

void UpdateFiles_2()

{

TSearchRec sr2;

// TSHFileInfo * fi2;

TListItem *pItem2 = NULL;

int IconIndex2;

TSHFileInfo * fi2 = new TSHFileInfo;

Form1->ListView2->Items->BeginUpdate();

Form1->ListView2->Items->Clear();

if (FindFirst(Form1->DirectoryListBox2->Directory + "\\*.*", faAnyFile, sr2) == 0)

do

{

if (sr2.Attr == faDirectory) continue;

pItem2 = Form1->ListView2->Items->Add();

pItem2->Caption = sr2.Name;

SHGetFileInfo(("*" + LowerCase(ExtractFileExt(pItem2->Caption))).c_str(),

0, fi2, sizeof(fi2),

SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_TYPENAME);

pItem2->ImageIndex = fi2->iIcon;

if (sr2.Size < 1024)

pItem2->SubItems->Add(IntToStr(sr2.Size) + " byte");

else if (sr2.Size < 1024 * 1024)

pItem2->SubItems->Add(IntToStr(sr2.Size / 1024) + " KByte");

else pItem2->SubItems->Add(IntToStr(sr2.Size / (1024 * 1024)) + " MByte");

pItem2->SubItems->Add(fi2->szTypeName);

}

while (FindNext(sr2) == 0);

FindClose(sr2);

Form1->ListView2->Items->EndUpdate();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)

{

TSHFileInfo * fi1, *fi2;

DriveComboBox1->DirList = DirectoryListBox1;

ListView1->SmallImages->Height = 16;

ListView1->SmallImages->Width = 16;

DriveComboBox2->DirList = DirectoryListBox2;

ListView2->SmallImages->Height = 16;

ListView2->SmallImages->Width = 16;

// SHGetFileInfo("*.*", 0, fi,

// sizeof(fi), SHGFI_SMALLICON | SHGFI_ICON | SHGFI_SYSICONINDEX);

ListView1->SmallImages->Handle =

SHGetFileInfo("*.*", 0, fi1,

sizeof(fi1), SHGFI_SMALLICON | SHGFI_ICON | SHGFI_SYSICONINDEX);

ListView1->LargeImages->Handle = SHGetFileInfo("*.*", 0, fi1,

sizeof(fi1), SHGFI_LARGEICON | SHGFI_ICON | SHGFI_SYSICONINDEX);

ComboBox1->ItemIndex = 0;

 

ListView1->SmallImages->Handle =

SHGetFileInfo("*.*", 0, fi2,

sizeof(fi2), SHGFI_SMALLICON | SHGFI_ICON | SHGFI_SYSICONINDEX);

ListView2->LargeImages->Handle = SHGetFileInfo("*.*", 0, fi2,

sizeof(fi2), SHGFI_LARGEICON | SHGFI_ICON | SHGFI_SYSICONINDEX);

ComboBox2->ItemIndex = 0;

UpdateFiles_1();

UpdateFiles_2();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::DirectoryListBox1Change(TObject *Sender)

{

UpdateFiles_1();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::ComboBox1Click(TObject *Sender)

{

switch (ComboBox1->ItemIndex)

{

case 0: ListView1->ViewStyle = vsIcon;

break;

case 1: ListView1->ViewStyle = vsSmallIcon;

break;

case 2: ListView1->ViewStyle = vsList;

break;

case 3: ListView1->ViewStyle = vsReport;

}

}

//---------------------------------------------------------------------------

 

void __fastcall TForm1::ComboBox2Click(TObject *Sender)

{

switch (ComboBox2->ItemIndex)

{

case 0: ListView2->ViewStyle = vsIcon;

break;

case 1: ListView2->ViewStyle = vsSmallIcon;

break;

case 2: ListView2->ViewStyle = vsList;

break;

case 3: ListView2->ViewStyle = vsReport;

}

}

//---------------------------------------------------------------------------

 

void __fastcall TForm1::DirectoryListBox2Change(TObject *Sender)

{

UpdateFiles_2();

}

//---------------------------------------------------------------------------

 

 

U_work_4.h

//---------------------------------------------------------------------------

 

#ifndef U_work_4H

#define U_work_4H

//---------------------------------------------------------------------------

#include <Classes.hpp>

#include <Controls.hpp>

#include <StdCtrls.hpp>

#include <Forms.hpp>

#include <ComCtrls.hpp>

#include <FileCtrl.hpp>

#include "ShellAPI.h"

#include "shlwapi.h"

#include <ImgList.hpp>

//---------------------------------------------------------------------------

class TForm1: public TForm

{

__published: // IDE-managed Components

TListView *ListView1;

TDirectoryListBox *DirectoryListBox1;

TDriveComboBox *DriveComboBox1;

TComboBox *ComboBox1;

TImageList *ImageList1;

TImageList *ImageList2;

TLabel *Label1;

TDriveComboBox *DriveComboBox2;

TDirectoryListBox *DirectoryListBox2;

TListView *ListView2;

TLabel *Label2;

TComboBox *ComboBox2;

void __fastcall FormCreate(TObject *Sender);

void __fastcall DirectoryListBox1Change(TObject *Sender);

void __fastcall ComboBox1Click(TObject *Sender);

void __fastcall ComboBox2Click(TObject *Sender);

void __fastcall DirectoryListBox2Change(TObject *Sender);

private: // User declarations

public: // User declarations

__fastcall TForm1(TComponent* Owner);

};

//---------------------------------------------------------------------------

extern PACKAGE TForm1 *Form1;

//---------------------------------------------------------------------------

#endif

 

 

.

1. .

2. .

3. .

 

 

5

 

Drag & Doc

Windows

Drag & Doc ( ).





:


: 2017-02-11; !; : 314 |


:

:

- , .
==> ...

1863 - | 1652 -


© 2015-2024 lektsii.org - -

: 0.046 .