Re:Dropping files onto Delphi app
Quote
>Patrick Vanbrabandt <p...@hemmis.be> wrote in article
<3379bcf6.12383...@news.belgium.eu.net>...
Quote
> Hello everyone,
> In my application, I have a form in which I indicate which files
> belong to a certain project. To make it more user-friendly, I want
> the user to be able to select the files in the File Explorer and drop
> them on my form (i.e. the way Installshield allows it). Has anyone an
> idea how I can do this ?
> Thanks very much for your time !!
> Patrick Vanbrabandt
> R&D
> ---------------------------------------------------------
> HEMMIS n.v.
> K. LeopoldIII-laan 2
> 8500 Kortrijk
> BELGIUM
> Tel: +32-56-37.26.37
> Fax: +32-56-37.23.24
> ---------------------------------------------------------
Patrick, (and the whole world):
This works for me: (Delphi 1.0)
================================================
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle,true); {sets up everything}
{other stuff removed for clarity}
end;
procedure TForm1.RecordDragDrop(Drop: THandle; Min: Boolean);
var
stringFileName: string;
stringPathName: string;
arraycharFileNameBuffer : array[0..255] of Char;
begin
{"Cardinal(-1)" is $FFFF in 16-bit, $FFFFFFFFF in 32-bit}
{ assume only one file; at least only get the first one}
{ 0 is the FIRST file being dropped; 80 is the length of the buffer}
DragQueryFile(Drop, 0, arraycharFileNameBuffer, 80);
stringFileName := ExtractFileName(strpas(arraycharFileNameBuffer));
if uppercase(stringFileName) <> uppercase('junk.txt') then
begin
messagebeep(MB_ICONASTERISK);
ShowMessage('This Program Only Wants A File Called junk.txt');
exit;
end;
DragFinish(Drop);
{now you have the file name, and can do something with it.}
{other stuff removed for clarity}
end;
procedure TForm1.WMDropFiles(VAR Msg: TWMDropFiles);
{Called only if TApplication is NOT receiving drag/drop}
begin
RecordDragDrop(Msg.Drop, False);
Msg.Result := 0;
end;
=================================================
Hope this helps!
Frank Cowan
fr...@signaldata.com
Chattanooga TN USA