Drag Files onto Form 
Author Message
 Drag Files onto Form

Hi !!!

I want to give the future users of my programm the
possibility to simply drag one File onto a Edit-Component,
so that the correct FileName+Path appears there.

How can I do this ???? (Messages, API-Calls)

How can I limit this function to only one File beeing
dragged and to not accept the dragging of a folder ????

Please send answer to:

p.S.: I mean Windows 95



Thu, 19 Nov 1998 03:00:00 GMT  
 Drag Files onto Form


Quote:
>I want to give the future users of my programm the
>possibility to simply drag one File onto a Edit-Component,
>so that the correct FileName+Path appears there.

Repost:

Reformat the following to place all declarations on a single line, and then
add it to your project.

==== Dragdrop.bas ===================================

'THREE EASY STEPS TO BEING A DRAG/DROP CLIENT

'STEP ONE -------------------------------------------

 'Place a message blaster on the form. Set it to
 'catch the WM_DROPFILES standard message for the
 'target control

'STEP TWO -------------------------------------------

 'Register the target control (or form) with Windows
 'as a recipient of drag/drop messages, by calling
 'DragAcceptFiles in the load event of the form
 'containing the target control (or the target form)
 '-- like so:

'          DragAcceptFiles <Control>.hWnd, True

'STEP THREE -----------------------------------------

 'When the message blaster catches the WM_DROPFILES
 'message, use the GetArrayOfDroppedFiles function or
 'the GetListOfDroppedFiles function to gather all
 'the information about the dropped files.

Type Type_Point
        X As Integer
        Y As Integer
End Type

Declare Sub DragAcceptFiles Lib "Shell" (ByVal hWnd%, ByVal accept%)

Declare Function DragQueryPoint% Lib "Shell" (ByVal hDrop%, lpPNT As
Type_Point)

Declare Function DragQueryFile% Lib "Shell" (ByVal hDrop%, ByVal iFile%,
ByVal lpBuff$, ByVal BUFFSIZE%)

Declare Function DragFinish% Lib "Shell" (ByVal hDrop%)

Global Const WM_DROPFILES = 563

Function GetArrayOfDroppedFiles% (hDrop%, sFileArray$(), iX%, iY%,
iClient%)

'-----------------------------------------------------------------
'
'   hDrop%      wParam from message blaster.
'
'   sFileArray  A dynamic string array. Will be filled
'               with the names of the dropped files.
'               A string representation of the number
'               of files will be put into array(0), and
'               the file names will start in array(1).
'
'   iX%         An integer. Will be set to the
'               X coordinate of the mouse.
'
'   iY%         An integer. Will be set to the
'               Y coordinate of the mouse.
'
'   iClient%    A boolean that will be set TRUE if the files
'               were dropped in the window's client area.
'
'   The function returns the number of dropped files.
'
'-----------------------------------------------------------------

Dim iCount%, iLen%, iNumFiles%, iDummy%
Const BUFFSIZE% = 256
Dim szBuffer As String * BUFFSIZE
Dim DropXY As Type_Point

    iNumFiles = DragQueryFile(hDrop, -1, szBuffer, BUFFSIZE)
    ReDim sFileArray(0 To iNumFiles - 1)

    'fill the array
    For iCount = 0 To iNumFiles - 1
        iLen = DragQueryFile(hDrop, iCount, szBuffer, BUFFSIZE)
        sFileArray(iCount) = Left$(szBuffer, iLen)
    Next

    'get drop location
    iClient = DragQueryPoint(hDrop, DropXY)
    iX = DropXY.X
    iY = DropXY.Y

    'release the handle
    iDummy = DragFinish(hDrop)

    GetArrayOfDroppedFiles = iNumFiles

End Function

Function GetListOfDroppedFiles (hDrop%, FileList As ListBox, iX%, iY%,
iClient%)

'-----------------------------------------------------------------
'
'   hDrop%      wParam from message blaster.
'
'   FileList    A listbox. Will be filled with
'               the names of the dropped files.
'
'   iX%         An integer. Will be set to the
'               X coordinate of the mouse.
'
'   iY%         An integer. Will be set to the
'               Y coordinate of the mouse.
'
'   iClient%    A boolean that will be set TRUE if the files
'               were dropped in the window's client area.
'
'   The function returns the number of dropped files.
'
'-----------------------------------------------------------------

Dim iCount%, iLen%, iNumFiles%, iDummy%
Const BUFFSIZE% = 256
Dim szBuffer As String * BUFFSIZE

Dim DropXY As Type_Point

    FileList.Clear

    iNumFiles = DragQueryFile(hDrop, -1, szBuffer, BUFFSIZE)

    'fill the list
    For iCount = 0 To iNumFiles - 1
        iLen = DragQueryFile(hDrop, iCount, szBuffer, BUFFSIZE)
        FileList.AddItem Left$(szBuffer, iLen)
    Next

    'get drop location
    iClient = DragQueryPoint(hDrop, DropXY)
    iX = DropXY.X
    iY = DropXY.Y

    'free the handle
    iDummy = DragFinish(hDrop)

    GetListOfDroppedFiles = iNumFiles

End Function


--
VB 3.0 and Win3.1x assumed

http://www.sn.no/~balchen/
ftp://ftp.sn.no/user/balchen/



Fri, 20 Nov 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. drag OUTLOOK Attachment file ONTO a vb6 form directly

2. DRAG an ATTACHMENT from an outlook incoming email message, ONTO a vb6 form directly

3. Drag FILENAME from explorer and DROP onto VB form

4. Dragging Desktop Icon onto Form

5. VB4.0-32 OCX CreateObject vs drag onto form

6. unable to drag controls onto form

7. unable to drag controls onto the form?

8. Can not drag fields from Data Environment onto Form

9. Drag an Rectangle onto a Form with hDc and API

10. Drag items onto windows form my app???

11. Drag & drop file onto ListViewItem function

12. Dragging a File onto My App

 

 
Powered by phpBB® Forum Software