Results 1 to 10 of 10

Thread: Drag/Drop ***Resolved

  1. #1

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    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

  2. #2
    Member
    Join Date
    Oct 2002
    Location
    Look out your window.
    Posts
    54
    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 );
    
                }
    
            }

  3. #3

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    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

  4. #4
    Member
    Join Date
    Oct 2002
    Location
    Look out your window.
    Posts
    54
    Hmmm... not off the top of my head...

  5. #5
    Lively Member
    Join Date
    May 2002
    Location
    Oregon
    Posts
    64
    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?

  6. #6
    Member
    Join Date
    Oct 2002
    Location
    Look out your window.
    Posts
    54
    No... it should work fine...

    Requires Windows NT 3.1 or later.
    That's what MSDN says about that function.

  7. #7

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    :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

  8. #8
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    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.

  9. #9

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    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

  10. #10

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    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
  •  



Click Here to Expand Forum to Full Width