🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Drag-and-drop 101

#151
From: Mike K
Date: Tue, 17 Jun 2008 12:14
46 lines
2245 bytes
I would like to drag files (just file names) from windows explorer into a Borland control.  Here is the implementation from the Developers Guide:

1) in the main form constructor, add:
	DragAcceptFiles(Handle,true);

2) set up a message map in the mainform class:
	.
	.
	private:
	   void virtual __fastcall WMDropFiles(TWMDropFiles &message);

	public:
 	   BEGIN_MESSAGE_MAP
	   MESSAGE_HANDLER(WM_DROPFILES,TWMDropFiles,WMDropFiles)
	   END_MESSAGE_MAP

3) write the handler:
	void __fastcall WMDropFiles(TWMDropFiles &message)
	{
		String filename;
		int count;
   		count = DragQueryFile((HDROP)message.Drop,0xFFFFFFFF,NULL,MAX_PATH);

   		for(int i=1;i<count; i++)
   		{
      			filename.SetLength(DragQueryFile((HDROP)message.Drop,i,fname.c_str(),MAX_PATH));
      			FileListBox1->Items->Add(filename);
   		}
   		DragFinish((HDROP)message.Drop);
	}

Seems easy enough. But when I compile and run this code, the app crashes into the CPU window, and the call stack shows pages of calls to TForm1::Dispatch().  I commented all the code out of the handler, and put breakpoints in the message map and in the call to DragAcceptFiles().  I never hit a breakpoint, and crash every time.  

Am I missing something very basic?  

Using BCB5. Also, what would I use the TFileListBox's OnDragDrop method for?  Drag/drop within the application?


Thanks for any help...


Mike



	
Technical Details
Message-ID: <4857aabb$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,15dfb293aacb32ec,start
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Tue, 17 Jun 2008 07:14:52 -0500
From: Mike K <nospam@nospam.net>
User-Agent: Thunderbird 1.5.0.14 (Windows/20071210)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Drag-and-drop 101
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 74.38.233.225
Message-ID: <4857aabb$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1213704891 74.38.233.225 (17 Jun 2008 05:14:51 -0700)
Lines: 46
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail