#include <ClipBoard.au3>
#include <SendMessage.au3>
#include <WindowsConstants.au3>
OnAutoItExitRegister('_OnExit')
$hGUI = GUICreate('*_Clipboard_*')
$hCBViewer = _ClipBoard_SetViewer($hGUI)
GUIRegisterMsg($WM_CHANGECBCHAIN, 'WM_CHANGECBCHAIN')
GUIRegisterMsg($WM_DRAWCLIPBOARD, 'WM_DRAWCLIPBOARD')
While 1
Sleep(100)
WEnd
Func _OnExit()
_ClipBoard_ChangeChain($hGUI, $hCBViewer)
EndFunc
Func _CopyGUI()
AdlibUnRegister('_CopyGUI')
MsgBox(64, 'Title', 'Copy: ' & @LF & ClipGet())
EndFunc
Func WM_CHANGECBCHAIN($hWnd, $iMsg, $iwParam, $ilParam)
; If the next window is closing, repair the chain
If $iwParam = $hCBViewer Then
$hCBViewer = $ilParam
; Otherwise pass the message to the next viewer
ElseIf $hCBViewer <> 0 Then
_SendMessage($hCBViewer, $WM_CHANGECBCHAIN, $iwParam, $ilParam, 0, 'hwnd', 'hwnd')
EndIf
EndFunc
Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $iwParam, $ilParam)
If _ClipBoard_GetDropEffect() = 'DROPEFFECT_COPY' Then
AdlibRegister('_CopyGUI', 100)
EndIf
; Pass the message to the next viewer
If $hCBViewer <> 0 Then
_SendMessage($hCBViewer, $WM_DRAWCLIPBOARD, $iwParam, $ilParam)
EndIf
EndFunc
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, GUIDelete($hClipBoard_GUI), '_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, GUIDelete($hClipBoard_GUI), _
'_ClipBoard_GetDataEx failed to get handle to clipboard files')
If $hDropEffect = 0 Then Return SetError(3, GUIDelete($hClipBoard_GUI), _
'_ClipBoard_GetDataEx failed to get handle to DropEffect enumeration')
$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()
GUIDelete($hClipBoard_GUI)
If $sRetDropEffect = '' Then Return SetError(2, 0, 'Error - Probably last Effect was reset (files deleted?)')
Return $sRetDropEffect
EndFunc