Jump to content

Drag&Drop From script to other programs


 Share

Recommended Posts

I'm trying to use Ascend4nt UDF for transferring files from ListView in my GUI and its work if target is SciTE or Notepad (displays text from file), but if target is windows explorer or desktop nothing happens - there are no errors, file just wont get copied to folder in the explorer right pane or desktop as expected. Is there a something wrong with the code?

#include-once
#include <WinAPI.au3>
#include <Memory.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
#include <GuiTreeView.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <GuiImageList.au3>
#include <File.au3>
#include <GuiListView.au3>
#include <WinAPIReg.au3>
#include <WinAPIShPath.au3>
#include <WinAPIShPath.au3>
#include <WinAPIShellEx.au3>
#include <WinAPISys.au3>

Global $bTreeView_DraggingInProcess = False, $bListView_DraggingInProcess = False, $sListView_DraggedFilePath = ""
Global $aInfo[28][3] = [[27,"",""]]

For $i = 1 To $aInfo[0][0]
    $aInfo[$i][0] = StringFormat("Child [%02d]", $i)
    Select
        Case $i <= 3
            $aInfo[$i][1] = "First"
        Case $i <= 16
            $aInfo[$i][1] = "Second"
        Case Else
            $aInfo[$i][1] = "Third"
    EndSelect
    $aInfo[$i][2] = $i
Next

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
Global $Form1_1 = GUICreate("Drag & Drop Test", 888, 450, (@DesktopWidth-888)/2, (@DesktopHeight-450)/2)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_1Close")
Global $idTreeView = _GUICtrlTreeView_Create($Form1_1, 8, 8, 281, 433, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
Global $idListView = GUICtrlCreateListView("0|1|2", 300, 8, 575, 430, BitOR($GUI_SS_DEFAULT_LISTVIEW,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE,$LVS_EX_GRIDLINES,$LVS_EX_SUBITEMIMAGES))
GUICtrlSendMsg($idListView, $LVM_SETCOLUMNWIDTH, 0, 510)
GUICtrlSendMsg($idListView, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg($idListView, $LVM_SETCOLUMNWIDTH, 2, 50)

$hTreeView = $idTreeView
$hListView = GUICtrlGetHandle($idListView)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "DragNDropEvents")
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "DragNDropEvents")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, "shell32.dll", 110)
_GUIImageList_AddIcon($hImage, "shell32.dll", 146)
_GUIImageList_AddIcon($hImage, "shell32.dll", 165)

_GUICtrlTreeView_SetNormalImageList($idTreeView, $hImage)
Global $iImage1 = 0, $iImage2 = 1, $iImage3 = 2

TreeViewFill()
ListViewFill()

$bTreeViewDragDropAllowed = True
$bTreeView_DraggingInProcess = False
$hTreeView_DraggedItem = -1
$hTreeView_DraggedImage = -1
$fWhere = -1

While 1
    Sleep(100)
WEnd

Func ListViewFill()

    Local $aFilelist = _FileListToArrayRec(@TempDir,"*",$FLTAR_FILES,$FLTAR_RECUR,$FLTAR_NOSORT,$FLTAR_FULLPATH)
    Local $oKnownExtIndex = ObjCreate("Scripting.Dictionary"), $iIconIndex = -1
    Local  $hImageList = _GUIImageList_Create(16, 16)

    _GUICtrlListView_BeginUpdate($hListView)
    _GUICtrlListView_DeleteAllItems($hListView)
    _GUICtrlListView_SetImageList($hListView, $hImageList, 1)

    For $i = 1 To $aFilelist[0]

        $sFilename = StringRegExpReplace($aFilelist[$i],"^.*\\","")
        $sExtention = StringRegExpReplace($aFilelist[$i],"(\A.*\.)(\w{0,8}\z)","$2")

        If Not $oKnownExtIndex.Exists($sExtention) Then
            $iIconIndex += 1
            $oKnownExtIndex.Add($sExtention,$iIconIndex)

            $sData = _WinAPI_AssocQueryString('.' & $sExtention, $ASSOCSTR_DEFAULTICON)
            $aIcon = _WinAPI_PathParseIconLocation($sData)
            $hIcon = _WinAPI_ShellExtractIcon($aIcon[0], $aIcon[1], 16, 16)

            _GUIImageList_SetImageCount($hImageList, $iIconIndex + 1)
            _GUIImageList_ReplaceIcon  ($hImageList, $iIconIndex, $hIcon )

        EndIf

        _GUICtrlListView_AddItem($hListView, $sFilename, $oKnownExtIndex.Item($sExtention))
        _GUICtrlListView_AddSubItem ($hListView, $i - 1, $sExtention, 1)
        _GUICtrlListView_AddSubItem ($hListView, $i - 1, $aFilelist[$i], 2)

    Next

    _GUICtrlListView_EndUpdate($hListView)

EndFunc

Func TreeViewFill()

    _GUICtrlTreeView_BeginUpdate($idTreeView)
    _GUICtrlTreeView_DeleteAll($idTreeView)
    $hRootItem1 = _GUICtrlTreeView_Add($idTreeView, 0, "Root 1", $iImage1, $iImage2)
    $hRootItem2 = _GUICtrlTreeView_Add($idTreeView, 0, "Root 2", $iImage1, $iImage2)
    $hRootItem3 = _GUICtrlTreeView_Add($idTreeView, 0, "Root 3", $iImage1, $iImage2)

    For $i = 1 To $aInfo[0][0]
        If $aInfo[$i][1] = "First" Then
            $aInfo[$i][2] -= $aInfo[0][0] + 1
        EndIf
    Next
    _ArraySort($aInfo,0,1,$aInfo[0][0],2)
    ;_ArraySort($aInfo,0,1,$aInfo[0][0],1)

    For $i = 1 To $aInfo[0][0]

        $aInfo[$i][2] = $i

        Switch $aInfo[$i][1]
            Case "First"
                $hItem = _GUICtrlTreeView_AddChild($idTreeView, $hRootItem1, $aInfo[$i][0], $iImage3, $iImage2)
            Case "Second"
                $hItem = _GUICtrlTreeView_AddChild($idTreeView, $hRootItem2, $aInfo[$i][0], $iImage3, $iImage2)
            Case "Third"
                $hItem = _GUICtrlTreeView_AddChild($idTreeView, $hRootItem3, $aInfo[$i][0], $iImage3, $iImage2)
        EndSwitch
        _GUICtrlTreeView_SetItemParam ($idTreeView, $hItem, $i+8800 )
    Next
    _GUICtrlTreeView_SetItemParam ($idTreeView, $hRootItem1, 8800-1 )
    _GUICtrlTreeView_SetItemParam ($idTreeView, $hRootItem2, 8800-2 )
    _GUICtrlTreeView_SetItemParam ($idTreeView, $hRootItem3, 8800-3 )

    _GUICtrlTreeView_Expand ($idTreeView, $hRootItem1, True)
    _GUICtrlTreeView_Expand ($idTreeView, $hRootItem2, True)
    _GUICtrlTreeView_EndUpdate($idTreeView)

EndFunc

;----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam )

    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
    $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
    $iCode = DllStructGetData( $tNMHDR, "Code" )
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $LVN_BEGINDRAG
                    $iIndex = _GUICtrlListView_HitTest($hListView)[0]
                    $sListView_DraggedFilePath = _GUICtrlListView_GetItemText($hListView, $iIndex, 2)

                    If FileExists($sListView_DraggedFilePath) Then
                        $bListView_DraggingInProcess = True
                    EndIF

            EndSwitch

        Case $hTreeView
            Switch $iCode
                Case $TVN_BEGINDRAGA, $TVN_BEGINDRAGW
                    If $bTreeViewDragDropAllowed Then
                        $hTreeView_DraggedItem = DragNDropTreeItemFromPoint()
                        If _GUICtrlTreeView_Level($hTreeView, $hTreeView_DraggedItem) > 0 Then
                            $bTreeView_DraggingInProcess = True

                            _GUICtrlTreeView_SetSelected($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView), False)
                            $hTreeView_DraggedImage = _GUICtrlTreeView_CreateDragImage($hTreeView, $hTreeView_DraggedItem)

                            DragNDropDrawDragImage($hTreeView, $hTreeView_DraggedImage)
                        EndIf
                    EndIf

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func DragNDropEvents()

    Switch @GUI_CtrlId
        Case $GUI_EVENT_PRIMARYUP
            If $bListView_DraggingInProcess Then

                $bListView_DraggingInProcess = False

                If FileExists($sListView_DraggedFilePath) Then
                    Local $tPointStruct = _WinAPI_GetMousePos ()
                    Local $hWndDragDropTarget = _WinAPI_WindowFromPoint($tPointStruct)

                    Local $aWindows = _WinAPI_EnumWindows()
                    For $i = 1 To $aWindows[0][0]
                        If _WinAPI_IsChild ($hWndDragDropTarget, $aWindows[$i][0] ) Then
                            $hWndDragDropTarget = $aWindows[$i][0]
                            ConsoleWrite(WinGetTitle($hWndDragDropTarget) & " --> "&$hWndDragDropTarget & @CRLF)
                        EndIf
                    Next

                    $tPointStruct = _WinAPI_GetMousePos (True, $hWndDragDropTarget)
                    _FileDragDrop($hWndDragDropTarget,$sListView_DraggedFilePath,DllStructGetData($tPointStruct, "x"),DllStructGetData($tPointStruct, "y"))
                    ConsoleWrite("@error = "&@error & @CRLF)
                EndIf
            EndIf

            If $bTreeView_DraggingInProcess Then
                _WinAPI_InvalidateRect($hTreeView)
                $bTreeView_DraggingInProcess = False
                _GUIImageList_Destroy($hTreeView_DraggedImage) ;delete drag image
                _SendMessage($hTreeView, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget
                _SendMessage($hTreeView, $TVM_SETINSERTMARK, 0, 0) ;remove InsertMark

                $hTreeView_TargetItem = DragNDropTreeItemFromPoint()
                $hTreeView_TargetItemParent = _GUICtrlTreeView_GetParentHandle ($hTreeView, $hTreeView_TargetItem)
                $hTreeView_DraggedItemParent = _GUICtrlTreeView_GetParentHandle ($hTreeView, $hTreeView_DraggedItem)

                If ($hTreeView_TargetItem = $hTreeView_DraggedItem) Or ($hTreeView_TargetItemParent <> $hTreeView_DraggedItemParent) Or ($hTreeView_TargetItem = $hTreeView_TargetItemParent) Or ($hTreeView_TargetItemParent = 0) Or ($hTreeView_DraggedItemParent = 0) Then Return

                $iIndexTarget = _GUICtrlTreeView_GetItemParam ($hTreeView, $hTreeView_TargetItem) - 8800
                $iIndexDragged = _GUICtrlTreeView_GetItemParam ($hTreeView, $hTreeView_DraggedItem) - 8800

                $iIndexTarget = ($fWhere > 0)?($iIndexTarget + 0.5):($iIndexTarget - 0.5)

                $aInfo[$iIndexDragged][2] = $iIndexTarget

                TreeViewFill()
            EndIf

        Case $GUI_EVENT_MOUSEMOVE
            If $bTreeView_DraggingInProcess = False Then Return
            Local $tPoint = DllStructCreate("int;int")
            DllStructSetData($tPoint, 1, MouseGetPos(0))
            DllStructSetData($tPoint, 2, MouseGetPos(1))
            Local $hWndPoint = _WinAPI_WindowFromPoint($tPoint)
            ;cancel drag in progress and cleanup if moved outside treeview:
            if $hWndPoint <> $hTreeView then
                $bTreeView_DraggingInProcess = False
                _WinAPI_InvalidateRect($hTreeView)
                _GUIImageList_Destroy($hTreeView_DraggedImage) ;delete drag image
                _SendMessage($hTreeView, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget
                _SendMessage($hTreeView, $TVM_SETINSERTMARK, 0, 0) ;remove InsertMark
                Return
            EndIf
            $hItemHover = DragNDropTreeItemFromPoint()
            If $hItemHover = 0 Then
                ;meh
            Else
                $aRect = _GUICtrlTreeView_DisplayRect($hTreeView, $hItemHover)
                $iTreeY = _WinAPI_GetMousePosY(True, $hTreeView)
                Switch $iTreeY
                    Case $aRect[1] To $aRect[1]+Int(($aRect[3]-$aRect[1])/2)
                        _SendMessage($hTreeView, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget
                        _SendMessage($hTreeView, $TVM_SETINSERTMARK, 0, $hItemHover) ;add InsertMark before item
                        $fWhere = -1
                    Case 1+$aRect[1]+Int(($aRect[3]-$aRect[1])/2) To $aRect[3]
                        _SendMessage($hTreeView, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget
                        _SendMessage($hTreeView, $TVM_SETINSERTMARK, 1, $hItemHover) ;add InsertMark after item
                        $fWhere = 1
                EndSwitch
            EndIf
            DragNDropDrawDragImage($hTreeView, $hTreeView_DraggedImage)
    EndSwitch
EndFunc
;----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;   DragNDropTreeItemFromPoint()
;   Returns handle of tree item under mouse:
Func DragNDropTreeItemFromPoint()
    Local $tMPos = _WinAPI_GetMousePos(True, $hTreeView)
    Return _GUICtrlTreeView_HitTestItem($hTreeView, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2))
EndFunc

;----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
; Draw drag image
; by Gary Frost (gafrost) (?)
Func DragNDropDrawDragImage(ByRef $hControl, ByRef $aDrag)
    Local $hDC = _WinAPI_GetWindowDC($hControl)
    Local $tPoint = _WinAPI_GetMousePos(True, $hControl)
    _WinAPI_InvalidateRect($hControl)
    _GUIImageList_Draw($aDrag, 0, $hDC, DllStructGetData($tPoint, "X")-10, DllStructGetData($tPoint, "Y")-8)
    _WinAPI_ReleaseDC($hControl, $hDC)
EndFunc   ;==>DragNDropDrawDragImage
;==============================================================================================================================================================================================
Func Form1_1Close()
    GUIDelete()
    Exit
EndFunc


;==============================================================================================================================================================================================
; https://www.autoitscript.com/forum/topic/122881-files-drag-drop/
;==============================================================================================================================================================================================
; ===============================================================================================================================
; <_FileDragDrop.au3>
;
;   Function to pass a 'Drag&Drop Files' message (WM_DROPFILES) to another control/window.
;
; Functions:
;   _FileDragDrop()     ; sends a WM_DROPFILES message to another control/window
;
; References:
;   Original code by Martin in Thread: 'Drag and Drop - the other way around', Post # 60
;       @ http://www.autoitscript.com/forum/topic/89808-drag-and-drop-the-other-way-around/page__st__40__p__650573#entry650573
;   'How to Implement Drag and Drop Between Your Program and Explorer - CodeProject':
;       @ http://www.codeproject.com/KB/shell/explorerdragdrop.aspx
; See also:
;   ProgAndy's COM implementation of Drag&Drop: 'Drag and Drop with Explorer'
;       @ http://www.autoitscript.com/forum/topic/90831-drag-and-drop-with-explorer/
;
; Author: Martin (original code), Ascend4nt (modifications - see function header)
; ===============================================================================================================================


; ==========================================================================================================================
; Func _FileDragDrop($hWnd,$sFiles,$iXPos=0,$iYPos=0,$sSep='|',$bUnicode=True)
;
; Function to pass a 'Drag&Drop Files' message to another window.
;
; $hWnd = Target control, or in many cases target window
; $sFiles = String of files to copy. For more than one, $sSep is used to separate them
; $iXPos = X Position in window, in client coordinates (0 [default] = left side of window). Parameter is often ignored
; $iYPos = Y Position in window, in client coordinates (0 [default] = top of window). Parameter is often ignored
; $sSep = Separator character(s) that were used to separate the passed list of file strings
; $bUnicode = If True, sends a Unicode WM_DROPFILES message, otherwise sends an ANSI message
;
; Returns:
;   Success: True, @error = 0
;   Failure: False, with @error set:
;       @error =  1 = invalid parameter(s)
;       @error = -1 = memory allocation failure
;       @error = 16 = PostMessage failure (could be the window handle is invalid, or it doesn't accept drag-drop)
;
; Authors: Martin, Ascend4nt (fixed Global memory issues, code cleanup, error handling, Unicode & x64 support)
; ==========================================================================================================================

Func _FileDragDrop($hWnd,$sFiles,$iXPos=0,$iYPos=0,$sSep='|',$bUnicode=True)
    Local Const $WM_DROPFILES=0x0233
#cs
    ; DROPFILES structure: dword offset;int x,int y;BOOL fNC;BOOL fWide
    ;   (offset is offset of start of file list, x,y point is location in window [client coords],
    ;     fNC = if dropped on non-client area [in which case point is in screen coords ], fWide= Unicode flag)
#ce
    Local Const $tagDROP_FILES = "dword offset;int px;int py;bool fNC;bool fWide"
;~  Parameter checks
    If Not IsHWnd($hWnd) Or Not IsString($sFiles) Or $sFiles='' Or $sSep='' Then Return SetError(1,0,False)
;~  Local vars
    Local $pDropFiles,$stDropFiles,$iExtra=0,$sType=';byte'
    Local $iStSize=DllStructGetSize(DllStructCreate($tagDROP_FILES)),$iStrLen=StringLen($sFiles)+2  ; 2 for double-NULL term

    If $bUnicode Then
        $iExtra=$iStrLen    ; Unicode = 2 bytes per character, so we need to add a 2nd $iStrLen to the allocation
        $bUnicode=-1
        $sType=';wchar'     ; change type of data (note 'byte' is needed for ANSI/ASCII - not sure why, but it chokes otherwise)
    EndIf

;~  Allocate memory for the structure and strings, get a pointer to it
;~      0x40 = $GMEM_ZEROINIT (zero-initialize memory) 0 = $GMEM_FIXED (returns a pointer instead of a handle)
    $pDropFiles = _MemGlobalAlloc($iStSize + $iStrLen+$iExtra,0x40)
    If $pDropFiles=0 Then Return SetError(-1,0,False)

;~  Create the structure with strings appended
    $stDropFiles = DllStructCreate($tagDROP_FILES & $sType & " filelist[" & $iStrLen & "]", $pDropFiles)

    DllStructSetData($stDropFiles, "offset", $iStSize)  ; Offset of file list

;~  X,Y Position, in client coords (makes a difference in some programs [Notepad++ for example - center of window is good])
    DllStructSetData($stDropFiles, "px", $iXPos)
    DllStructSetData($stDropFiles, "py", $iYPos)

    DllStructSetData($stDropFiles, "fWide", $bUnicode)  ; TRUE = unicode
;~  DllStructSetData($stDropFiles, "fNC", 0)        ; FALSE = in client area, TRUE = non-client (and x,y pos in screen coords)
    DllStructSetData($stDropFiles, "filelist", StringReplace($sFiles,$sSep,ChrW(0)))

    ; Attempt to Post the Message to the window (SendMessage doesn't work here)
    If Not _WinAPI_PostMessage($hWnd, $WM_DROPFILES, $pDropFiles, 0) Then
;~      Failed to send message. We can free the memory in this case
        _MemGlobalFree($pDropFiles)
        Return SetError(16,0,False)
    EndIf
#cs
    ; NOTE: We do *not* free the memory - this is handled by the program receiving the message (and by Windows)
    ;   Technically if that program doesn't handle the message correctly, then we'll wind up with a memory leak
    ;   However, since we can not be sure when/if the message was or will be received, we can't just discard the memory
    ;   that will be used by Windows
;~  _MemGlobalFree($pDropFiles)
#ce
    Return True
EndFunc ;==> _FileDragDrop()

 

Link to comment
Share on other sites

Your request for help probably should have been posted in the AutoIt GUI Help and Support  section, as it is GUI control related.

Perhaps you could Report your topic and ask for it to be moved there (please don't create another though :) ). You should get better targeted help there.

Looking at your script, it is awfully complex, and I am not sure it needs to be, but I have never used that UDF before or indeed tried to do as you are wanting. It would seem to me though, that you are needing to get folder destination from your mouse location, and that is where your problem most likely resides. It is relatively easy to get the details of source from your Listview, but you need to determine what folder (active window) your are in when you release your mouse button.

In any case, there are lots of Drag & Drop topics in that section of the forum.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

#include <ClipBoard.au3>
#include <Memory.au3>
#include <WinAPI.au3>
#include <Misc.au3>

Global Const $DROPFILES = "DWORD pFiles; int pt[2]; int fNC; int fWide;"
Global Const $CFSTR_PREFERREDDROPEFFECT = "Preferred DropEffect"
Global Const $CF_PREFERREDDROPEFFECT = _ClipBoard_RegisterFormat($CFSTR_PREFERREDDROPEFFECT)
Global Const $DROPEFFECT_NONE = 0
Global Const $DROPEFFECT_COPY = 1
Global Const $DROPEFFECT_MOVE = 2
Global Const $DROPEFFECT_LINK = 4
Global Const $DROPEFFECT_SCROLL = 0x80000000

For $i = 0 To 2

    $sFilename = @ScriptDir & "\Test" & TimerInit() & ".txt"
    FileWriteLine($sFilename, "test")
    ConsoleWrite(_Move_File_to_Clipboard($sFilename) & @CRLF)

    While 1
        If _IsPressed("01") Then ; left mouse button
            While _IsPressed("01") ; left mouse button
                Sleep(10)
            WEnd
            Send("^v")
            ExitLoop
        EndIf
    WEnd
Next

Exit

Func _Move_File_to_Clipboard($sFile)
    Local $hDeskWin = _WinGetDesktopHandle()
    Local $hClip = _ClipBoard_Open($hDeskWin)
    If $hClip Then
        _ClipBoard_Empty()
        Local $HDROP = _CreateDROPFILES($sFile)
        Local $DROPEFFECT = _CreatePREFERREDDROPEFFECT($DROPEFFECT_MOVE)
        _ClipBoard_SetDataEx($HDROP, $CF_HDROP)
        _ClipBoard_SetDataEx($DROPEFFECT, $CF_PREFERREDDROPEFFECT)
        _ClipBoard_Close()
        Return 1
    EndIf
    Return 0
EndFunc   ;==>_Move_File_to_Clipboard


;===============================================================================
;
; Function Name:   _CreateDROPFILES
; Description::    Creates a DROPFILES-structure
; Parameter(s):    $Files - Pipe-separated list of files to copy: example: C:\File1.bin|D:\AnotherFile.dat
; Requirement(s):  COM/OLE UDF
; Return Value(s): HGLOBAL-Pointer to a DROPFILES structure
; Author(s):       prog@ndy
;
;===============================================================================
; http://www.autoitscript.com/forum/index.php?showtopic=91046&view=findpost&p=654849
; http://www.autoit.de/index.php?page=Thread&postID=81909&highlight=hdrop#post81909

Func _CreateDROPFILES($Files)
    $Files = String($Files)
    Local $hMem = _MemGlobalAlloc(_DragDrop_SIZEOF($DROPFILES) + ((StringLen($Files) + 2) * 2), $GPTR)
    $Files = StringSplit($Files, "|")
    Local $stDROPFILES = DllStructCreate($DROPFILES, $hMem)
    Local $hPtr = $hMem + DllStructGetSize($stDROPFILES)
    DllStructSetData($stDROPFILES, "fWide", 1)
    DllStructSetData($stDROPFILES, 1, DllStructGetSize($stDROPFILES))
    For $i = 1 To $Files[0]
        $next = DllStructCreate("wchar[" & StringLen($Files[$i]) + 1 & "]", $hPtr)
        DllStructSetData($next, 1, $Files[$i] & ChrW(0))
        $hPtr += (StringLen($Files[$i]) + 1) * 2
    Next
    Local $next = DllStructCreate("wchar[1]", $hPtr)
    DllStructSetData($next, 1, ChrW(0))
    Return $hMem
EndFunc   ;==>_CreateDROPFILES

; Prog@ndy
Func _CreatePREFERREDDROPEFFECT($dwEffect)
    Local $pMem = _MemGlobalAlloc(4, $GPTR) ; 4 bytes - 1 DWORD
    If Not $pMem Then Return SetError(1, 0, 0)
    DllStructSetData(DllStructCreate("DWORD", $pMem), 1, $dwEffect)
    Return $pMem
EndFunc   ;==>_CreatePREFERREDDROPEFFECT

; Author: Prog@ndy
Func _DragDrop_SIZEOF($tagStruct)
    Return DllStructGetSize(DllStructCreate($tagStruct, 1))
EndFunc   ;==>_DragDrop_SIZEOF

Func _WinGetDesktopHandle()
    Local $i, $hDeskWin, $hSHELLDLL_DefView, $h_Listview_Configs
    ; The traditional Windows Classname for the Desktop, not always so on newer O/S's
    $hDeskWin = WinGetHandle("[CLASS:Progman]")
    ; Parent->Child relationship: Desktop->SHELLDLL_DefView
    $hSHELLDLL_DefView = ControlGetHandle($hDeskWin, '', '[CLASS:SHELLDLL_DefView; INSTANCE:1]')
    ; No luck with finding the Desktop and/or child?
    If $hDeskWin = '' Or $hSHELLDLL_DefView = '' Then
        ; Look through a list of WorkerW windows - one will be the Desktop on Windows 7+ O/S's
        $aWinList = WinList("[CLASS:WorkerW]")
        For $i = 1 To $aWinList[0][0]
            $hSHELLDLL_DefView = ControlGetHandle($aWinList[$i][1], '', '[CLASS:SHELLDLL_DefView; INSTANCE:1]')
            If $hSHELLDLL_DefView <> '' Then
                $hDeskWin = $aWinList[$i][1]
                ExitLoop
            EndIf
        Next
    EndIf
    ; Parent->Child relationship: Desktop->SHELDLL_DefView->SysListView32
    $h_Listview_Configs = ControlGetHandle($hSHELLDLL_DefView, '', '[CLASS:SysListView32; INSTANCE:1]')
    If $h_Listview_Configs = '' Then Return SetError(-1, 0, '')
    Return SetExtended($h_Listview_Configs, $hDeskWin)
EndFunc   ;==>_WinGetDesktopHandle

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...