|
-
Oct 25th, 2002, 05:16 AM
#1
Thread Starter
Hyperactive Member
Drag/Drop ***Resolved
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
Last edited by Wak; Nov 4th, 2002 at 11:32 PM.
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Oct 25th, 2002, 07:12 AM
#2
Member
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 );
}
}
-
Oct 25th, 2002, 05:18 PM
#3
Thread Starter
Hyperactive Member
query...
It works great.. thanx! 
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?
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Oct 28th, 2002, 07:06 AM
#4
Member
Hmmm... not off the top of my head...
-
Oct 31st, 2002, 09:21 PM
#5
Lively Member
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.
Maybe doing the bit-mask is only supported on 2k on up?
-
Nov 1st, 2002, 07:10 AM
#6
Member
No... it should work fine...
Requires Windows NT 3.1 or later.
That's what MSDN says about that function.
-
Nov 4th, 2002, 02:33 AM
#7
Thread Starter
Hyperactive Member
:D
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
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Nov 4th, 2002, 05:52 AM
#8
Hyperactive Member
I believe you are doing something like this
Code:
switch(var)
{
case 1:
int buffer=1;...
break;
case 2:
int buffer=2;...
break;
....
}
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.
Next time search MSDN first, if you can't understand what the error is about.
-
Nov 4th, 2002, 07:48 PM
#9
Thread Starter
Hyperactive Member
mmm
I don't understand why WM_DROPFILES: gets called twice, every time I drop one file???? It's very confusing...
Does anyone else know?
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Nov 4th, 2002, 08:48 PM
#10
Thread Starter
Hyperactive Member
ok
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?
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|