Does anyone know how I can drag a file from a windows folder, and drop it onto a ListBox in my application, and have it add the file's filename onto the ListBox???
Thanx
Printable View
Does anyone know how I can drag a file from a windows folder, and drop it onto a ListBox in my application, and have it add the file's filename onto the ListBox???
Thanx
Here ya go.
Oh yah... the list box must have the WS_EX_ACCEPTFILES style.
Code:case WM_DROPFILES:
{
int buflen = 64, temp = 0;
int numfiles = DragQueryFile ( (HDROP) wParam, -1, 0, 0 );
char * buffer = new char [buflen + 1];
for ( int i = 0; i < numfiles; i++ )
{
// If the path being dropped is larger than buflen
// Resize it to the necessary size.
while ( (temp = DragQueryFile ( (HDROP) wParam, i, buffer, buflen )) > buflen )
{
delete [] buffer;
buflen = temp;
buffer = new char [buflen + 1];
}
if ( GetFileAttributes ( buffer ) & FILE_ATTRIBUTE_DIRECTORY )
CArchiveData::AddDirectory ( buffer );
else
CArchiveData::AddFile ( buffer );
}
}
It works great.. thanx! :D
One thing though, the event gets called twice every time I add a file to the list, so every time i drop one file, it adds two new strings to the listbox... Any idea's?
Hmmm... not off the top of my head...
Maybe doing the bit-mask is only supported on 2k on up?Quote:
Use GetFileAttributes and Masking to Check File Attributes
On Windows 2000 and later, your application should check for a file bit flag attribute by calling GetFileAttributes and using a mask rather than only checking for equality. For example, the following shows the correct way to check for the FILE_ATTRIBUTE_DIRECTORY attribute.
No... it should work fine...
That's what MSDN says about that function.Quote:
Requires Windows NT 3.1 or later.
righto, I've solved that problem, I think.. But I have another.. It says that all those declared variables can't be initialized, because they are inside the case. When I move them outside the case, it gives me fatal error, I'm guessing because they are being declared too fast (re-declared for ever event) ....
error C2360: initialization of 'buffer' is skipped by 'case' label
I believe you are doing something like this
So put those code belong to the case in curly blankets.Code:switch(var)
{
case 1:
int buffer=1;...
break;
case 2:
int buffer=2;...
break;
....
}
It is all inside the MSDN. Just type C2360 in the index tab page.Code:switch(var)
{
case 1:
{int buffer=1;...}
break;
case 2:
{int buffer=2;...}
break;
....
}
Next time search MSDN first, if you can't understand what the error is about.:)
I don't understand why WM_DROPFILES: gets called twice, every time I drop one file???? It's very confusing...
Does anyone else know?
I'm really sorry bout this...
I've narrowed it down to the fact that all of my messages which are being sent to the list box are being created twice... But for every other control, only once??
Does this help?