Sign in to follow this  
Followers 0
MrCreatoR

How to check if certain file was copied or cuted?

8 posts in this topic

Hi,

I need to check some file that was cutted/copied to clipboard from explorer, so if the file is currently cutted, i will FileMove() it to some place, if it's copied, i will FileCopy() it >_<

If we use $Clip = ClipGet() then we get in $Clip variable the full path to file that was cutted/copied, but how to check the performed action, is it was cutted or copied? :)


Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites



Hi,

I need to check some file that was cutted/copied to clipboard from explorer, so if the file is currently cutted, i will FileMove() it to some place, if it's copied, i will FileCopy() it >_<

If we use $Clip = ClipGet() then we get in $Clip variable the full path to file that was cutted/copied, but how to check the performed action, is it was cutted or copied? :)

Greetings MrCreator

it's a workaround, but you could monitor the clipboard and check the active explorer window for

filename(s) when they show up and use _GUICtrlListView_GetItemCut() to get state

modified A3L Auto3Lib example cuts file in AutoIt icon folder then reads each listview item state

#include <GuiMenu.au3>
#include <GuiListView.au3>
#include <GuiToolbar.au3>

Opt("MustDeclareVars", 1)

; ===============================================================================================================================
; Description ...: ListView external control demo
; Author ........: Paul Campbell (PaulIA)
; Notes .........: This script MUST be run in SciTE in order to see the results
; ===============================================================================================================================

Global $hWnd, $hList, $iView = 9

;BlockInput(1)
OpenExplorer()
ShowItems()
;BlockInput(0)

Func OpenExplorer()
    Run("explorer.exe C:\Program Files\AutoIt3\Icons", "C:\Program Files\AutoIt3\Icons")
    WinWaitActive("[TITLE:C:\Program Files\AutoIt3\Icons; CLASS:CabinetWClass]")
    $hWnd = WinGetHandle("[TITLE:C:\Program Files\AutoIt3\Icons; CLASS:CabinetWClass]")
    If $hWnd = 0 Then _ReportError("Unable to get Explorer handle")
    $hList = ControlGetHandle($hWnd, "", "SysListView321")
    If $hList = 0 Then _ReportError("Unable to obtain ListView handle")
    _GUICtrlListView_SetItemCut($hList, 1, True) ; set item 1 to cut
EndFunc   ;==>OpenExplorer

; ===============================================================================================================================
; Show information about the items in the ListView
; ===============================================================================================================================`
Func ShowItems()
    Local $iI, $sItem, $sItemCut, $aRect

    For $iI = 0 To _GuiCtrlListView_GetItemCount($hList) - 1
        $aRect = _GuiCtrlListView_GetItemRect($hList, $iI)

        If _GuiCtrlListView_GetItemCut($hList, $iI) Then
            $sItemCut = "!Item " & $iI & " "
        Else
            $sItemCut = "+Item " & $iI & " "
        EndIf
        
        $sItem = "+Item " & $iI & " "
        ConsoleWrite($sItem & "ID ....................: " & _GUICtrlListView_MapIndexToID($hList, $iI) & @CRLF)
        ConsoleWrite($sItem & "image index ...........: " & _GuiCtrlListView_GetItemImage($hList, $iI) & @CRLF)
        ConsoleWrite($sItem & "indent ................: " & _GuiCtrlListView_GetItemIndent($hList, $iI) & @CRLF)
        ConsoleWrite($sItemCut & "is cut ................: " & _GuiCtrlListView_GetItemCut($hList, $iI) & @CRLF)
        ConsoleWrite($sItem & "is drop hilited .......: " & _GuiCtrlListView_GetItemDropHilited($hList, $iI) & @CRLF)
        ConsoleWrite($sItem & "is focused ............: " & _GuiCtrlListView_GetItemFocused($hList, $iI) & @CRLF)
        ConsoleWrite($sItem & "is selected ...........: " & _GuiCtrlListView_GetItemSelected($hList, $iI) & @CRLF)
        ConsoleWrite($sItem & "next item index .......: " & _GuiCtrlListView_GetNextItem($hList, $iI) & @CRLF)
        ConsoleWrite($sItem & "param data ............: " & _GuiCtrlListView_GetItemParam($hList, $iI) & @CRLF)
        ConsoleWrite($sItem & "position X ............: " & _GuiCtrlListView_GetItemPositionX($hList, $iI) & @CRLF)
        ConsoleWrite($sItem & "position Y ............: " & _GuiCtrlListView_GetItemPositionY($hList, $iI) & @CRLF)
        ConsoleWrite($sItem & "rectangle .............: [" & $aRect[0] & ", " & $aRect[1] & ", " & $aRect[2] & ", " & $aRect[3] & "]" & @CRLF)
        ConsoleWrite($sItem & "text ..................: " & _GuiCtrlListView_GetItemText($hList, $iI) & @CRLF)
    Next
EndFunc   ;==>ShowItems

Func _ReportError($szMsg)
    Local $szErrorFormat = "\n%s\nError: %d - %s\n"
    Local $iLastError = _WinAPI_GetLastError()
    Local $szLasterror = _WinAPI_GetLastErrorMessage()
    ConsoleWrite(StringFormat($szErrorFormat, $szMsg, $iLastError, $szLasterror))
    Exit
    ;Return $iLastError
EndFunc   ;==>_ReportError

I see fascists...

Share this post


Link to post
Share on other sites

Hi rover, thanks for reply.

it's a workaround, but you could monitor the clipboard and check the active explorer window for

filename(s) when they show up and use _GUICtrlListView_GetItemCut() to get state

It's a good workaround, thanks, but it's only effective while the app is runing, but what if i need to check it when program start? There should be an API solution for that one....

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Here is another workaround, but there is two(?) issues:

1. If the files are big, it will take a while until the function return :)

2. The cutted/copied state is lost after this function call.

$iRet = _FilesGetState() ;0 = Copied, 1 = Cutted, -1 = None.
ConsoleWrite("State: " & $iRet)

Func _FilesGetState()
    Local $aFiles = StringSplit(ClipGet(), @CRLF)
    If Not IsArray($aFiles) Then Return SetError(1, 0, -1)
    
    Local $iRet_State = -1, $sTempDir = @TempDir
    
    Local $sPath = StringRegExpReplace($aFiles[1], "\\[^\\]*$", "")
    Local $sFileName = StringRegExpReplace($aFiles[1], "^.*\\", "")
    
    If $sPath = $sTempDir Then $sTempDir = @AppDataDir
    
    Local $iPID = Run('Explorer.exe ' & $sTempDir, '', @SW_HIDE)
    If @error Then Return SetError(2, 0, -1)
    
    ProcessWait($iPID)
    
    Local $hTmpDir_Wnd = _GetHiddenExplorerWindow($sTempDir)
    If Not IsHWnd($hTmpDir_Wnd) Then Return SetError(3, 0, $hTmpDir_Wnd)
    
    ControlSend($hTmpDir_Wnd, "", "SysListView321", "^v")
    
    Local $iTimer = TimerInit(), $iAllFilesExists = 1
    
    While 1
        If TimerDiff($iTimer) >= 2000 Then ExitLoop
        
        For $i = 1 To $aFiles[0]
            $sFileName = StringRegExpReplace($aFiles[$i], "^.*\\", "")
            
            If Not FileExists($sTempDir & "\" & $sFileName) Then
                $iAllFilesExists = 0
                ExitLoop
            EndIf
        Next
        
        If $iAllFilesExists Then ExitLoop
        $iAllFilesExists = 1
        
        Sleep(10)
    WEnd
    
    If Not FileExists($aFiles[1]) And FileExists($sTempDir & "\" & $sFileName) Then
        For $i = 1 To $aFiles[0]
            $sFileName = StringRegExpReplace($aFiles[$i], "^.*\\", "")
            FileMove($sTempDir & "\" & $sFileName, $aFiles[$i])
        Next
        
        $iRet_State = 1
    ElseIf FileExists($sTempDir & "\" & $sFileName) And FileExists($aFiles[1]) Then
        For $i = 1 To $aFiles[0]
            $sFileName = StringRegExpReplace($aFiles[$i], "^.*\\", "")
            FileDelete($sTempDir & "\" & $sFileName)
        Next
        
        $iRet_State = 0
    EndIf
    
    WinClose($hTmpDir_Wnd)
    
    Return $iRet_State
EndFunc

Func _GetHiddenExplorerWindow($sPath)
    $sPath = FileGetLongName($sPath)
    Local $aWinList = WinList("[CLASS:CabinetWClass]")
    
    For $i = 1 To UBound($aWinList)-1
        If ControlGetText($aWinList[$i][1], "", "Edit1") = $sPath And BitAND(WinGetState($aWinList[$i][1]), 2) <> 2 Then _
            Return $aWinList[$i][1]
    Next
    
    Return WinGetHandle("[CLASS:CabinetWClass]", $sPath)
EndFunc

But it needs a few tweeks, for example if the file(s) exists in the Temp directory, the function could detect that and rename the destination file... or just create new temporary dir.


Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi MrCreator

try this API solution :)

will retrieve current clipboard content at runtime

and if a files list is in the clipboard will display Cut or Copied status

displays all subsequent clipboard events

a few 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

a rough example using modified help file clipboard example and Lazycats drag and drop udf

Problems:

if clipboard events occur too closely to each other

the edit control is not updated properly.

i.e. Event 4 could be followed by Event 6 then a partial result in the edit control for Event 5

Edit: corrected edit update problem

;retrieve explorer clipboard file list and cut or copy status of source files
;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/Copy Detect", 600, 600, -1, -1, -1, $WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

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

$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()

ShowData() ; display current clipboard contents

While 1
    Sleep(1000)
WEnd

; Show clipboard statistics
Func ShowData()
    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()
        ;DragFinish Function - Releases memory that the system allocated for use in transferring file names to the application.
        ;http://msdn.microsoft.com/en-us/library/bb776407(VS.85).aspx
        ;DllCall("shell32.dll", "int", "DragFinish", "hwnd", $hDrop)
        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
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

@rover

Outstanding!!! Posted Image Thank you! :P

This example is perfect to start some sort of ClipBoard Monitoring application.

I cuted of the example a little(?), this is what i needed:

#include <ClipBoard.au3>

MsgBox(64, "_ClipBoard_GetDropEffect()", "DropEffect is: " & _ClipBoard_GetDropEffect())

Func _ClipBoard_GetDropEffect()
    Local $sRetDropEffect, $iFormat, $hMemory, $hDropEffect, $tDropEffect, $iDropEffect
    Local $hClipBoard_GUI = GUICreate("_ClipBoard_GetDropEffect")
    
    Local $CF_PREFERREDDROPEFFECT = 0 ; not constant, changes value
    Local Const $DROPEFFECT_NONE = 0 ; Drop target cannot accept the data.
    Local Const $DROPEFFECT_COPY = 1 ; Drop results in a copy. The original data is untouched by the drag source.
    Local Const $DROPEFFECT_MOVE = 2 ; Drag source should remove the data.
    Local Const $DROPEFFECT_LINK = 4 ; Drag source should create a link to the original data.
    
    ; Open the clipboard
    If Not _ClipBoard_Open($hClipBoard_GUI) Then Return SetError(1, 0, "_ClipBoard_Open failed")
    
    Do
        $iFormat = _ClipBoard_EnumFormats($iFormat)
        If $iFormat <> 0 And _ClipBoard_FormatStr($iFormat) == "Preferred DropEffect" Then $CF_PREFERREDDROPEFFECT = $iFormat
    Until $iFormat = 0
    
    ; if clipboard contains cut or copied files
    If _ClipBoard_IsFormatAvailable($CF_HDROP) Then
        $hMemory = _ClipBoard_GetDataEx($CF_HDROP) ; get handle to clipboard files
        $hDropEffect = _ClipBoard_GetDataEx($CF_PREFERREDDROPEFFECT) ; get handle to DropEffect enumeration
       
        If $hMemory = 0 Then Return SetError(2, 0, "_ClipBoard_GetDataEx failed")
        If $hDropEffect = 0 Then Return SetError(3, 0, "_ClipBoard_GetDataEx failed")
        
        $tDropEffect = DllStructCreate("dword", $hDropEffect)
        $iDropEffect = DllStructGetData($tDropEffect, 1)
        
        If BitAND($iDropEffect, $DROPEFFECT_MOVE) = $DROPEFFECT_MOVE Then
            $sRetDropEffect = "DROPEFFECT_MOVE"
        ElseIf BitAND($iDropEffect, $DROPEFFECT_COPY) = $DROPEFFECT_COPY Then
            $sRetDropEffect = "DROPEFFECT_COPY"
        ElseIf BitAND($iDropEffect, $DROPEFFECT_LINK) = $DROPEFFECT_LINK Then
            $sRetDropEffect = "DROPEFFECT_LINK"
        ElseIf $iDropEffect = $DROPEFFECT_NONE Then
            $sRetDropEffect = "DROPEFFECT_NONE"
        EndIf
    Else
        $sRetDropEffect = "Error - ClipBoard does not contain cut or copied files"
    EndIf
    
    ; Close the clipboard
    _ClipBoard_Close()
    
    If $sRetDropEffect = "" Then Return SetError(2, 0, "Error - Probably last Effect was reset (files deleted?)")
    Return $sRetDropEffect
EndFunc

Thank you again, i am very appreciate your effort and the time spent on this issue.


Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

@rover

Outstanding!!! Posted Image Thank you! :P

This example is perfect to start some sort of ClipBoard Monitoring application.

[removed code box]

Thank you again, i am very appreciate your effort and the time spent on this issue.

Your welcome

all its parts fell together quite nicely :)

using the HDROP memory handle to get the files with Lazycats UDF

finding out how to get the handles to clipboard info using format values.

an interesting challenge.

Just another typical example of a Microsoft 'Can't get there from here' moment

we all run into with the Windows API.

nice to beat one of them every now and then :idea: , workarounds being so unsatisfying. :(

your reworking of my demo code into a function could be a Clipboard include function, submit it to Gary.

be seeing you...


I see fascists...

Share this post


Link to post
Share on other sites

There is one more problem, but i am not sure if the problem is in this function...

When i do _ClipPutFile(), the _ClipBoard_GetDropEffect returns «_ClipBoard_GetDataEx failed» (on $hDropEffect = 0). But when i try to put the file in explorer, there is no problem, and also ClipGet() return correct strings :mellow:

How i can check if the files was puted to clipboard? or better, how to put them with specific DropEffect (cuted or copied)?


Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

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