Board index » cppbuilder » Dragging on an TImage

Dragging on an TImage


2006-12-16 10:47:59 AM
cppbuilder106
I want to drag image files from the explorer on a TImage component and
resolve the filename of the files dropped.
To start I set e Breakpoint on the OnDragOver-method. But the program never
reaches this breakpoint.
1. What am I doing wrong?
2. How do I get the filename(s) once this works?
Regards
 
 

Re:Dragging on an TImage

"Stefan" < XXXX@XXXXX.COM >wrote:
Quote

I want to drag image files from the explorer on a TImage
component and resolve the filename of the files dropped.
Drag and Drop is quite simple when interested in only file
names but TImage does not descend from TWinControl so it
doesn't have a HWND (Handle) that is needed to be used
with a call to the Win32 API DragAcceptFiles. You might
consider using a TPanel instead.
Once you call DragAcceptFiles, to get the file names,
you first need to recieve notification in the form of a
WM_DROPFILES message. This would require that you subclass
the control's WindowProc method or subclass the control
and override it's WndProc method *or* use a message map.
If you use a TPanel v/s a TImage, you can also override it's
Paint method to display the image.
To process the WM_DROPFILES, all you need is a simple block of
code that looks something like:
HDROP hDrop = reinterpret_cast<HDROP>( Message.WParam );
int FileCount = DragQueryFile( hDrop, -1, NULL, 0 );
for( int x = 0; x < FileCount; ++x )
{
int CharCount = DragQueryFile( hDrop, x, NULL, 0 );
char *FileName = new char[ CharCount + 1 ];
DragQueryFile( hDrop, x, FileName, CharCount + 1 );
// use FileName
delete [] FileName;
}
DragFinish( hDrop );
~ JD