Sign in to follow this  
Followers 0
semedboy

File in clipboard

13 posts in this topic

This UDF checks if there is a file in the clipboard or not, it is only tested on windwos xp SP2.... if you find any bugs let me know

Func _file_in_clipboard()
    DllCall("User32.dll", "int", "OpenClipboard", "hwnd", "")
    $file=DllCall("User32.dll", "int", "EnumClipboardFormats", "int", 49158)
    DllCall("User32.dll", "int", "CloseClipboard")
    If $file[0]=49159 Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

0x5748415420444F20594F552057414E543F

Share this post


Link to post
Share on other sites

Tried with a multitude of different file types, including folders, and it seems to work flawlessly from what I could tell. I could see this being quite useful as a safety-checking function (or error handling/prevention) for lots of different scripts that rely on the clipboard in some way or another; Nice work. :idea:


Share this post


Link to post
Share on other sites

Just for my education, does this do the same?

Nope, it doesn't. You're checking if there's anything on the clipboard to paste to a variable. He's checking wether the clipboard content is of a specific format, in this case a file... see also standard UDF _ClipBoard_EnumFormats(). What I don't know is, what format 49159 should be :idea:... I would've assumed $CF_HDROP, but that's defined as 15.

Share this post


Link to post
Share on other sites

Copied to clipboard files are also plain text, but of a special format so that Windows knows they're meant for a copy/cut & paste operation. Start this and copy a plain text to clipboard (text / your function will trigger), a file or more files (text / both function will trigger) and finally copy picture content (Bitmap(?) / no function will trigger).

ClipPut("")

While 1
    Sleep(1000)
    ConsoleWrite(TimerInit() & @tab & "_ClipCheck()" & @TAB & @TAB & _ClipCheck() & @CRLF)
    ConsoleWrite(TimerInit() & @tab & "_file_in_clipboard()" & @TAB & _file_in_clipboard() & @CRLF)
WEnd

Func _ClipCheck()
    $Clip = ClipGet()
    If $Clip = "" Then Return 0
    Return 1
EndFunc   ;==>_ClipCheck

Func _file_in_clipboard()
    DllCall("User32.dll", "int", "OpenClipboard", "hwnd", "")
    $file=DllCall("User32.dll", "int", "EnumClipboardFormats", "int", 49158)
    DllCall("User32.dll", "int", "CloseClipboard")
    If $file[0]=49159 Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

Perhaps that number is some calculation of all the filetypes, much like they are in msgbox flags.

Could be, ya never know with those crazy Microsoft devs >.>


Share this post


Link to post
Share on other sites

thanks for the comments :idea: .... and can anyone tell me how to post on example scripts


0x5748415420444F20594F552057414E543F

Share this post


Link to post
Share on other sites

Just post the same as anywhere else now you have 5 posts.

thanks

0x5748415420444F20594F552057414E543F

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Can you explain where you got "49158" format from, and what it means ?

Edit: dosent matter I got it

"Format ID #49158: Format Name = "FileName""

So it identifies that the data in the clipboard has a filename, hence it is a file rather than just a chunck of text copied from somewhere etc...

some others

Format ID #49161: Format Name = "DataObject"

Format ID #49267: Format Name = "Shell IDList Array"

Format ID #15: Format Name = ""

Format ID #49314: Format Name = "Preferred DropEffect"

Format ID #49305: Format Name = "Shell Object Offsets"

Format ID #49158: Format Name = "FileName"

Format ID #49159: Format Name = "FileNameW" ;Next available I assume.

Format ID #49171: Format Name = "Ole Private Data"

more

Format ID #49166: Format Name = "Object Descriptor"

Format ID #49272: Format Name = "Rich Text Format"

Format ID #49457: Format Name = "HTML Format"

Format ID #49156: Format Name = "Native"

Format ID #49167: Format Name = "Link Source Descriptor"

Format ID #49154: Format Name = "ObjectLink"

Format ID #49545: Format Name = "Hyperlink"

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

To be on the safe side, you might want to do this first before checking (in case number values change):

$iCF_FileNameW=_ClipBoard_RegisterFormat("FileNameW")
If _ClipBoard_IsFormatAvailable($iCF_FileNameW) Then $bFileInClipboard=True

Also, a slightly modified version of the Help file script for Function _ClipBoard_EnumFormats which will show the numbers of the formats:

#include <GuiConstantsEx.au3>
#include <ClipBoard.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $iMemo

_Main()

Func _Main()
    Local $hGUI, $iFormat, $iCount

    ; Create GUI
    $hGUI = GUICreate("Clipboard", 600, 400)
    $iMemo = GUICtrlCreateEdit("", 2, 2, 596, 396, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Open the clipboard
    If Not _ClipBoard_Open ($hGUI) Then _WinAPI_ShowError ("_ClipBoard_Open failed")

    ; Show clipboard formats available
    MemoWrite("Clipboard formats ..: " & _ClipBoard_CountFormats ())

    ; Enumerate clipboard formats
    Do
    $iFormat = _ClipBoard_EnumFormats ($iFormat)
    If $iFormat <> 0 Then
    $iCount += 1
    MemoWrite("Clipboard format " & $iCount & " Number:"&$iFormat&" String: " & _ClipBoard_FormatStr ($iFormat))
    EndIf
    Until $iFormat = 0

    ; Close the clipboard
    _ClipBoard_Close ()

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc ;==>_Main

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite
Edited by Ascend4nt

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