Listbox Delphi

LISTBOX DELPHI
Many programs such as the popular music player iTunes or not, can drag and drop files in Windows Explorer directly into the list Playlistnya. Facilities drag and drop ListBox is a sophisticated, it can also create your own to explain the program with Delphi you.
Do not believe?! So .. So if you believe, what I have examples that you can ngeDrag ListBox and drop such as iTunes or not. How easy .. You do not need but a scar, to be imprisoned under the tree later all.
It is important you know the secret of how to manipulate the windows procedure for meresponds control messages sent. In case this is the message WM_DROPFILES, so that you can use it for the sake of your program.
Here is an example of how to make ListBox can ngeDrag and Drop sekeren iTunes or not. So that you may add Stop, not an if you try to contact more with the Windows API functions such as "DragAcceptFiles'," DragQueryFile "and" DragFinish "
Congratulations to try ..
Do not forget to add the ShellApi.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ShellAPI;

type
pDaftarFile = ^TDaftarFile;
TDaftarFile = Record
Filename : String;
Path : String;
end;

TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
DaftarFile : pDaftarFile;
procedure NgeDROPFiles(var Msg: TMessage);
procedure CustomWindowProc(var Message: TMessage);
procedure IsiList(sFileName: string);
end;

var
Form1: TForm1;

implementation
var
WindowProcAwal: TWndMethod;

{$R *.DFM}
procedure TForm1.IsiList(sFileName: string);
begin
New(DaftarFile);
DaftarFile^.Filename := ExtractFilename(sFilename);
DaftarFile^.Path := ExtractFilePath(sFilename);
ListBox1.Items.AddObject(DaftarFile^.Filename, TObject(DaftarFile));
end;

procedure TForm1.CustomWindowProc(var Message: TMessage);
begin
// Jika Message yang dikirim, user sedang mendrop file kedalam list box
// maka jalankan prosudur buatan anda sendiri
if Message.Msg = WM_DROPFILES then
NgeDROPFiles(Message);
// Pastikan Original WindowProc dari ListBox juga menerima message
// biar tidak ngiri..
WindowProcAwal(Message);
end;

//Proses manipulasi pesan dari Windows
procedure TForm1.NgeDROPFiles(var Msg: TMessage);
var
NamaFile: PChar;
i, SizeBuffer, JumlahFile: integer;
begin
// Inisialisasi Nama File
NamaFile := '';
// Hitung Jumlah File Yang Akan Di Drop Pada ListBox
JumlahFile := DragQueryFile(Msg.wParam, $FFFFFFFF, NamaFile, 255);
for i := 0 to JumlahFile - 1 do
begin
//Cari Nilai Buffer Dari File yang akan dimuat
SizeBuffer := DragQueryFile(Msg.wParam, i, nil, 0) + 1;
//Alokasikan Buffer Dari File yang akan dimuat
NamaFile := StrAlloc(SizeBuffer);
//Ambil nama file yang akan didrop
DragQueryFile(Msg.wParam, i, NamaFile, SizeBuffer);
//Jika file tersebut ada maka masukkan kedalam ListBox
if FileExists(NamaFile) then
IsiList(NamaFile);
//Alokasi kembali buffer yang digunakan sebelumnya
StrDispose(NamaFile);
end;
//Bersihkan kembali Memory yang dialokasikan untuk mendrop file
DragFinish(Msg.wParam);
//Letakkan Posisi Kursor ListBox ke file yang telah didrop
Listbox1.ItemIndex := ListBox1.Items.Count-JumlahFile;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
// Simpan Original WindowProc ListBox
WindowProcAwal := ListBox1.WindowProc;
// Ganti WindowProc ListBox dengan Fungsi milik anda sendiri
ListBox1.WindowProc := CustomWindowProc;
// Pastikan Bahwa ListBox anda kini bisa menerima fungsi Drag File
DragAcceptFiles(ListBox1.Handle, True);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
// Kembalikan WindowProc ListBox Ke Originalnya
ListBox1.WindowProc := WindowProcAwal;
// Pastikan Bahwa ListBox anda kini tidak bisa menerima fungsi Drag File lagi
DragAcceptFiles(ListBox1.Handle, False);
end;

end.

Postingan populer dari blog ini

vb6 msflexgrid

Tutorial Visual Basic 6.0 : Listbox in VB6

How to Use Mshflexgrid