Sign in to follow this  
Followers 0
rover

Clipboard 'DropEffect' demo

1 post in this topic

monitors clipboard for $CF_HDROP file events and retrieves

'DropEffect' copy or cut status of folders/files on clipboard

uses modified helpfile clipboard example and Lazycats drag and drop UDF

from an idea by MrCreator in this thread.

http://www.autoitscript.com/forum/index.php?showtopic=81709

Reference links

MSDN Shell Clipboard Formats

http://msdn.microsoft.com/en-us/library/bb776902(VS.85).aspx

DROP EFFECT

http://msdn.microsoft.com/en-us/library/ms693457(VS.85).aspx

Shell Data Objects

http://www.netez.com/2xExplorer/shellFAQ/adv_drag.html

Determining If a File Is Cut or Copied to the Clipboard

http://blog.davemorton.net/2008/09/determi...-copied-to.html

NSE, copy/cust & paste, clipboard formats

http://www.eggheadcafe.com/forumarchives/p...ost23117423.asp

;Author: rover
;Oct 3 2008
;updated Nov 10 2008
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ClipBoard.au3>
#include <WinAPI.au3>
#include <GuiEdit.au3>
#include <Process.au3>
#include <Misc.au3>
;#include <SendMessage.au3>

_Singleton("Clipboard DropEffect Demo", 0)
Opt("GUIOnEventMode", 1)
Opt('MustDeclareVars', 1)

Global Const $CFSTR_PREFERREDDROPEFFECT = "Preferred DropEffect"
Global $CF_PREFERREDDROPEFFECT = 0 ; not constant, changes value
Global Const $DROPEFFECT_NONE = 0 ; Drop target cannot accept the data.
Global Const $DROPEFFECT_COPY = 1 ; Drop results in a copy. The original data is untouched by the drag source.
Global Const $DROPEFFECT_MOVE = 2 ; Drag source should remove the data.
Global Const $DROPEFFECT_LINK = 4 ; Drag source should create a link to the original data.
Global Const $DROPEFFECT_SCROLL = 0x80000000 ; Scrolling is about to start or is currently occurring in the target.

;Global Const $WM_DRAWCLIPBOARD = 0x0308
;Global Const $WM_CHANGECBCHAIN = 0x030D

Global $hGUI, $iMemo, $hMemo, $Label, $hNext, $ClipEvent, $iSequence, $sTemp, $iEvent = 1, $oMyError

$hGUI = GUICreate("Clipboard 'DropEffect' file Cut or Copy status", 600, 600, -1, -1, -1, $WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$ClipEvent = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "ShowClipBoardData")

$Label = GUICtrlCreateLabel("Cut or copy files and text to view source info", 0, 582, 600, 20, $SS_CENTER)
GUICtrlSetFont($Label, 10)
$iMemo = GUICtrlCreateEdit("", 2, 2, 596, 576, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
$hMemo = GUICtrlGetHandle($iMemo)
_GUICtrlEdit_SetLimitText($hMemo, 768000) ; tested up to 7000 folders/files cut/copied


; capture clipboard events
$hNext = _ClipBoard_SetViewer($hGUI)
GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN")
GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD")
$oMyError = ObjEvent("AutoIt.Error", "COMErrorHandler")
GUISetState()

ShowClipBoardData() ; display current clipboard contents

While 1
    Sleep(10000)
WEnd

; Show clipboard statistics
Func ShowClipBoardData()
    Local $PID, $hClipOwner, $hOpenWindow, $iFormat = 0, $iCount, $hDrop, $tData, $nSize, $pFileName, $nAmt
    Local $hDropEffect, $tDropEffect, $iDropEffect, $oShell, $oShellWindows, $sString
    MemoWrite("EVENT: " & $iEvent & @CRLF)
    $iEvent += 1
    $hClipOwner = _ClipBoard_GetOwner()
    $hOpenWindow = _ClipBoard_GetOpenWindow()
    $iSequence = _ClipBoard_GetSequenceNumber()
    _WinAPI_GetWindowThreadProcessId($hClipOwner, $PID)
    MemoWrite("Owner Handle ............: " & $hClipOwner)
    MemoWrite("OwnerThreadProcessPID ...: " & $PID)
    MemoWrite("OwnerThreadProcessName ..: " & _ProcessGetName($PID))
    MemoWrite()
    MemoWrite("GetParent ...............: " & WinGetTitle(_WinAPI_GetParent($hClipOwner)))
    MemoWrite("GetRootOwner ............: " & WinGetTitle(_WinAPI_GetAncestor($hClipOwner, $GA_ROOTOWNER)))
    MemoWrite("OwnerClass ..............: " & _WinAPI_GetClassName($hClipOwner)) ; CLIPBRDWNDCLASS
    MemoWrite()
    MemoWrite("Sequence# ...............: " & $iSequence) ; use to indicate clipboard changed
    MemoWrite("Is CF_HDROP Format ......: " & _ClipBoard_IsFormatAvailable($CF_HDROP))
    

    If $hOpenWindow Then
        MemoWrite()
        MemoWrite("The clipboard is already open")
        MemoWrite("Open Window Handle ......: " & $hOpenWindow)
        MemoWrite("Open Window Title .......: " & WinGetTitle($hOpenWindow))
        MemoWrite("Open Window Class .......: " & _WinAPI_GetClassName($hOpenWindow) & @CRLF)
        MemoWrite("----------------------------------------------------------------------------------")
    EndIf
    
    ; Open the clipboard
    If Not _ClipBoard_Open($hGUI) Then Return _WinAPI_ShowError("_ClipBoard_Open failed", False)

    MemoWrite()

    Do
        $iFormat = _ClipBoard_EnumFormats($iFormat)
        If $iFormat <> 0 Then
            $iCount += 1
            $sTemp = _ClipBoard_FormatStr($iFormat)
            If $sTemp == "Preferred DropEffect" Then $CF_PREFERREDDROPEFFECT = $iFormat
            ;not constant like CF_HDROP, value must be retrieved for each event
            $sTemp = StringFormat("%-.25s%s%-40s%s", "Format " & $iCount & " ................", ": ", $sTemp, $iFormat)
            If $iFormat Then MemoWrite($sTemp)
        EndIf
    Until $iFormat = 0

    MemoWrite()
    ; if clipboard contains cut or copied files
    If _ClipBoard_IsFormatAvailable($CF_HDROP) Then
        $hDrop = _ClipBoard_GetDataEx($CF_HDROP) ; get handle to clipboard files
        $hDropEffect = _ClipBoard_GetDataEx($CF_PREFERREDDROPEFFECT) ; get handle to DropEffect enumeration
        If $hDrop = 0 And _ClipBoard_Close() Then Return _WinAPI_ShowError("_ClipBoard_GetDataEx failed: $hDrop", False)
        If $hDropEffect = 0 And _ClipBoard_Close() Then Return _WinAPI_ShowError("_ClipBoard_GetDataEx failed: $hDropEffect", False)
        $tDropEffect = DllStructCreate("dword", $hDropEffect)
        $iDropEffect = DllStructGetData($tDropEffect, 1)
        MemoWrite("HDROP Handle ............: " & $hDrop)
        MemoWrite("DropEffect Handle .......: " & $hDropEffect)
        MemoWrite("DropEffect Value ........: " & $iDropEffect)
        If BitAND($iDropEffect, $DROPEFFECT_MOVE) = $DROPEFFECT_MOVE Then MemoWrite("DropEffect ..............: DROPEFFECT_MOVE")
        If BitAND($iDropEffect, $DROPEFFECT_COPY) = $DROPEFFECT_COPY Then MemoWrite("DropEffect ..............: DROPEFFECT_COPY")
        If BitAND($iDropEffect, $DROPEFFECT_LINK) = $DROPEFFECT_LINK Then MemoWrite("DropEffect ..............: DROPEFFECT_LINK")
        If $iDropEffect = $DROPEFFECT_NONE Then MemoWrite("DropEffect ..............: DROPEFFECT_NONE")
        MemoWrite()
        
        If _ProcessGetName($PID) = "explorer.exe" Then
            $oShell = ObjCreate("shell.application")
            If Not @error And IsObj($oShell) Then
                $oShellWindows = $oShell.windows
                If IsObj($oShellWindows) Then
                    MemoWrite("Explorer Windows# .......: " & $oShellWindows.Count)
                    For $Window In $oShellWindows ; Count all existing shell windows
                        $sString &= HWnd($window.HWnd) & @TAB
                        $sString &= $window.LocationName & @TAB
                        $sString &= StringTrimLeft(StringReplace($window.locationURL, '%20', ' '), 8)
                        MemoWrite("Explorer Window .........: " & $sString)
                        $sString = ""
                    Next
                    MemoWrite()
                EndIf
            EndIf
        EndIf
        
        GUICtrlSetData($Label, "Updating file list. Please wait ...")
        GUICtrlSetColor($Label, 0xFF0000)
        _GUICtrlEdit_BeginUpdate($hMemo)
        ; retrieve files list from clipboard (Author: Lazycat)
        $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $hDrop, "int", 0xFFFFFFFF, "ptr", 0, "int", 255) ; file count
        For $i = 0 To $nAmt[0] - 1
            $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $hDrop, "int", $i, "ptr", 0, "int", 0) ; file name size
            $nSize = $nSize[0] + 1
            $pFileName = DllStructCreate("char[" & $nSize & "]")
            DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $hDrop, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize)
            MemoWrite("File .....: " & $i + 1 & " " & DllStructGetData($pFileName, 1))
            $pFileName = 0
        Next
        MemoWrite()

        GUICtrlSetData($Label, "Cut or copy files and text to view source info")
        GUICtrlSetColor($Label, 0x000000)
        _GUICtrlEdit_EndUpdate($hMemo)
    EndIf
    
    MemoWrite("----------------------------------------------------------------------------------")
    ; Close the clipboard
    _ClipBoard_Close()
    
EndFunc   ;==>ShowData

Func MemoWrite($sMessage = "")
    _GUICtrlEdit_AppendText($iMemo, $sMessage & @CRLF)
EndFunc   ;==>MemoWrite

Func _Exit()
    _ClipBoard_ChangeChain($hGUI, $hNext)
    GUIDelete()
    Exit
EndFunc   ;==>_Exit

Func WM_CHANGECBCHAIN($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    If $iwParam = $hNext Then
        $hNext = $ilParam
    ElseIf $hNext <> 0 Then
        _SendMessage($hNext, $WM_CHANGECBCHAIN, $iwParam, $ilParam, 0, "hwnd", "hwnd")
    EndIf
EndFunc   ;==>WM_CHANGECBCHAIN

Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Beep(2000, 5)
    GUICtrlSendToDummy($ClipEvent)
    If $hNext <> 0 Then _SendMessage($hNext, $WM_DRAWCLIPBOARD, $iwParam, $ilParam)
EndFunc   ;==>WM_DRAWCLIPBOARD

Func ComErrorHandler()
    Local $sHexNumber = Hex($oMyError.number,8)
    MemoWrite("COM Error: Explorer Window .........: " & $oMyError.description)
    MemoWrite("COM Error: $oMyError.scriptline.....: " & $oMyError.scriptline)
    MemoWrite("COM Error: Error number ............: " & $oMyError.number)
    MemoWrite("COM Error: $sHexNumber .............: " & $sHexNumber)
    MemoWrite("COM Error: Windescription...........: " & $oMyError.windescription)
    $oMyError.clear
    SetError(1)
Endfunc

I see fascists...

Share this post


Link to post
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
Sign in to follow this  
Followers 0