🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8506

Re: drag & drop files

#8506
From: Dave
Date: Tue, 19 Oct 2004 21:52
82 lines
3161 bytes
On Tue, 19 Oct 2004 15:02:42 -0400, Stephan wrote:

> Hi,
> I want to implement file drag and drop into my application.
> 
> I've been looking with google, through borland,
> through this newsgroup, without success.
> 
> In this instance, I only want to open files.
> I saw some advice concerning OLE drag & drop,
> but I don't think I need this
> (I'll let experts advise me if this is a bad decision)
> so I am trying to handle  WM_DROPFILES
> in my code.
> 
> I've been looking through the win32 help file at
> DragAcceptFiles, DragFinish, DragQueryFile,
> and WM_DROPFILES
> 
> The only example I've found was off borland,
> for delphi.
> it handles the WM_DROPFILES message
> in the header with
> 
>   procedure WMDROPFILES(var Message: TWMDROPFILES);
>   message WM_DROPFILES;
> 
> in the header.
> what do  have to do to get this working?

Dear Stephan,

Maybe you should try this.

__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WMDropFiles (TWMDropFiles &message)
{
  // Get a count of the number of files being dropped.
  UINT filecount = DragQueryFile ((HDROP) message.Drop, 0xFFFFFFFF, NULL,
0) ;
  for (UINT i = 0 ; i < filecount ; ++i)
  {
    // Get the path of one file.
    AnsiString filename;
    filename.SetLength (MAX_PATH);
    int length = DragQueryFile ((HDROP) message.Drop, i, filename.c_str (),
filename.Length())                                 ;
    filename.SetLength (length);
    Memo1->Lines->Add(filename);
  }
  DragFinish ((HDROP) message.Drop) ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
  Action = caFree ;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  DragAcceptFiles(Form1->Handle, true);
}
//---------------------------------------------------------------------------


in the header file:

...
  void  __fastcall WMDropFiles (TWMDropFiles &message);
...

BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DROPFILES,TWMDropFiles,WMDropFiles)
END_MESSAGE_MAP (TForm)

Goood Luck !
Dave
Technical Details
Message-ID: <1w155fi0nlc30$.o5vmp47hm4wk$.dlg@40tude.net>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <417564ef@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,cfe1aa651e368c07
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Dave <dave_xse@nospam.org>
Subject: Re: drag & drop files
Newsgroups: borland.public.cppbuilder.nativeapi
User-Agent: 40tude_Dialog/2.0.10.1
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
References: <417564ef@newsgroups.borland.com>
Date: Tue, 19 Oct 2004 23:52:17 +0200
Message-ID: <1w155fi0nlc30$.o5vmp47hm4wk$.dlg@40tude.net>
NNTP-Posting-Host: 80.218.152.5
X-Trace: newsgroups.borland.com 1098222738 80.218.152.5 (19 Oct 2004 14:52:18 -0700)
Lines: 82
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail