Announcement

Collapse

Maintenance

The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

Dropping file/directory onto listview

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dropping file/directory onto listview

    I had an app which had a listbox on it, with which the user could drag files or directories on it. The files were added OK and everything was alright. I decided to use a listview, but I haven't worked out which messages I need to capture when a user does the same drag drop operation. I don't need to worry about the user dragging off the listview (i.e. I don't want them to!)

    Has anyone got any ideas?

    TIA.

    Dorian

  • #2
    Dorian --
    not sure, that this is optimal solution, but enough simple:
    to place listview on modeless dialog with the same size.
    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "WIN32API.INC"
       #Include "COMMCTRL.INC"
    
       CallBack Function DlgProc
          Static iFile As Long, nFile As Long, TmpAsciiz As Asciiz * %MAX_PATH
          Select Case CbMsg
             Case %WM_DROPFILES
                nFile = DragQueryFile (CbWparam, -1, ByVal 0, 0)
                For iFile = 0 To nFile - 1
                   DragQueryFile CbWparam, iFile, TmpAsciiz, SizeOf(TmpAsciiz)
                   MsgBox TmpAsciiz
                Next
                DragFinish CbWparam
             Case %WM_INITDIALOG: DragAcceptFiles CbHndl, %True
             Case %WM_DESTROY: DragAcceptFiles CbHndl, %False
          End Select
       End Function
    
       Function PbMain()As Long
          InitCommonControls
          Dim hDlgMain As Long, hDlg As Long
          Dialog New 0,"Drag and drop",,,300, 250,%WS_SYSMENU Or %WS_THICKFRAME Or %DS_CENTER, To hDlgMain
          Dialog New hDlgMain, "", 10, 25, 280,170, %WS_CHILD To hDlg
          Control Add "SysListView32", hDlg, 101, "", 0, 0, 280, 170, %WS_CHILD Or %WS_VISIBLE, %WS_EX_CLIENTEDGE
          Dialog Show Modeless hDlg Call DlgProc
          Dialog Show Modal hDlgMain
       End Function
    ------------------

    Comment


    • #3
      I tried that out, and it works OK. The problem is that the listview cannot be the same size as the form, and unfortunately I can only get the form to respond to drop events. I used Spy++ (with Visual Studio) to see what messages were being sent to my listview. %WM_DROPFILES was among them, but I don't know how to detect this message.

      In my message handler, I've got the usual code:

      Select case wMsg
      ...
      ...
      Case %WM_DROPFILES


      This only detects the %WM_DROPFILES sent to the form, and not directly sent to the listview.

      Does anyone know how I could get this working?

      Cheers!

      Dorian.


      ------------------

      Comment


      • #4
        Originally posted by DorianDarby:
        The problem is that the listview cannot be the same size as the form
        Sounds very strange. I told about modeless dialog, not abot whole form.
        I added some buttons/textboxes to make my idea more clear.
        Drag&Drop zone is ListView' area only.
        Code:
           #Compile Exe
           #Register None
           #Dim All
           #Include "WIN32API.INC"
           #Include "COMMCTRL.INC"
           
           Global hDlgMain As Long, hDlg As Long
           CallBack Function DlgProc
              Static iFile As Long, nFile As Long, TmpAsciiz As Asciiz * %MAX_PATH
              Select Case CbMsg
                 Case %WM_DROPFILES
                    nFile = DragQueryFile (CbWparam, -1, ByVal 0, 0)
                    For iFile = 0 To nFile - 1
                       DragQueryFile CbWparam, iFile, TmpAsciiz, SizeOf(TmpAsciiz)
                       MsgBox TmpAsciiz
                    Next
                    DragFinish CbWparam
                 Case %WM_INITDIALOG: DragAcceptFiles CbHndl, %True
                 Case %WM_DESTROY: DragAcceptFiles CbHndl, %False
              End Select
           End Function
           Function PbMain()As Long
              InitCommonControls
              Dialog New 0,"Drag and drop", , , 300, 250,%WS_SYSMENU Or %WS_CAPTION Or %WS_THICKFRAME Or %DS_CENTER, To hDlgMain
              Control Add TextBox, hDlgMain, 102, "", 10, 5, 280, 15, , %WS_EX_CLIENTEDGE
              Control Add TextBox, hDlgMain, 103, "", 10, 30, 280, 15, , %WS_EX_CLIENTEDGE
              Control Add Button, hDlgMain, 104, "Button1", 10, 215, 120, 15
              Control Add Button, hDlgMain, 105, "Button2", 170, 215, 120, 15
              Dialog New hDlgMain, "", 10, 75, 280, 120, %WS_CHILD To hDlg
              Control Add "SysListView32", hDlg, 101, "", 0, 0, 280, 120, %WS_CHILD Or %WS_VISIBLE, %WS_EX_CLIENTEDGE
              Dialog Show Modeless hDlg Call DlgProc
              Dialog Show Modal hDlgMain
           End Function
        ------------------

        Comment

        Working...
        X