Function Reference


_ClipBoard_GetDataEx

Retrieves data from the clipboard in a specified format

#include <Clipboard.au3>
_ClipBoard_GetDataEx ( [$iFormat = $CF_TEXT] )

Parameters

$iFormat [optional] Specifies a clipboard format:
$CF_TEXT - Text format (default)
$CF_BITMAP - Handle to a bitmap (HBITMAP)
$CF_METAFILEPICT - Handle to a metafile picture (METAFILEPICT)
$CF_SYLK - Microsoft Symbolic Link (SYLK) format
$CF_DIF - Software Arts' Data Interchange Format
$CF_TIFF - Tagged image file format
$CF_OEMTEXT - Text format containing characters in the OEM character set
$CF_DIB - BITMAPINFO structure followed by the bitmap bits
$CF_PALETTE - Handle to a color palette
$CF_PENDATA - Data for the pen extensions to Pen Computing
$CF_RIFF - Represents audio data in RIFF format
$CF_WAVE - Represents audio data in WAVE format
$CF_UNICODETEXT - Unicode text format
$CF_ENHMETAFILE - Handle to an enhanced metafile (HENHMETAFILE)
$CF_HDROP - Handle to type HDROP that identifies a list of files
$CF_LOCALE - Handle to the locale identifier associated with text in the clipboard
$CF_DIBV5 - BITMAPV5HEADER structure followed by bitmap color and the bitmap bits
$CF_OWNERDISPLAY - Owner display format
$CF_DSPTEXT - Text display format associated with a private format
$CF_DSPBITMAP - Bitmap display format associated with a private format
$CF_DSPMETAFILEPICT - Metafile picture display format associated with a private format
$CF_DSPENHMETAFILE - Enhanced metafile display format associated with a private format

Return Value

Success: Handle to a clipboard object in the specified format
Failure: 0

Remarks

The clipboard controls the handle that the _ClipBoard_GetData() function returns, not the application.
You should copy the data immediately. The application must not free the handle nor leave it locked.
The application must not use the handle after the _ClipBoard_Empty() or _ClipBoard_Close() function is called, or after the _ClipBoard_SetData() function is called with the same clipboard format.

Related

_ClipBoard_GetData, _ClipBoard_SetData

See Also

Search GetClipboardData in MSDN Library.

Example

Example 1 use _ClipBoard_SetData()

#include "Extras\HelpFileInternals.au3"

#include <Clipboard.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIError.au3>
#include <WindowsStylesConstants.au3>

Example()

Func Example()
    ; Create GUI
    Local $hGUI = GUICreate("Clipboard Get/Set DataEx (v" & @AutoItVersion & ")", 600, 450)
    _MemoCreate(2, 2, 596, 396, $WS_VSCROLL)
    Local $idBtn_SetData = GUICtrlCreateButton("Set ClipBoard Data", 150, 410, 120, 30)
    Local $idBtn_GetData = GUICtrlCreateButton("Get ClipBoard Data", 300, 410, 120, 30)
    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    Local $hMemory, $tData
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idBtn_SetData
                _ClipBoard_SetData("ClipBoard Library")
            Case $idBtn_GetData
                ; Open the clipboard
                If _ClipBoard_Open($hGUI) Then

                    ; Read clipboard text
                    $hMemory = _ClipBoard_GetDataEx($CF_TEXT)
                    If $hMemory = 0 Then _WinAPI_ShowError("_ClipBoard_GetDataEx failed")
                    $tData = DllStructCreate("char Text[8192]", $hMemory)
                    _MemoWrite(DllStructGetData($tData, "Text"))

                    ; Close the clipboard
                    _ClipBoard_Close()
                Else
                    _WinAPI_ShowError("_ClipBoard_Open failed")
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Example

Example 2 use _ClipBoard_GetData()

#include "Extras\HelpFileInternals.au3"

#include <Clipboard.au3>
#include <GUIConstantsEx.au3>
#include <Memory.au3>
#include <WinAPIError.au3>
#include <WindowsStylesConstants.au3>

Example()

Func Example()
    ; Create GUI
    GUICreate("Clipboard Get/Set DataEx (v" & @AutoItVersion & ")", 600, 450)
    _MemoCreate(2, 2, 596, 396, $WS_VSCROLL)
    Local $idBtn_SetData = GUICtrlCreateButton("Set ClipBoard Data", 150, 410, 120, 30)
    Local $idBtn_GetData = GUICtrlCreateButton("Get ClipBoard Data", 300, 410, 120, 30)
    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    Local $hMemory, $hLock, $tData, $sData, $iSize
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idBtn_SetData
                ; Open clipboard
                If _ClipBoard_Open(0) Then

                    ; Empty clipboard
                    If _ClipBoard_Empty() Then

                        ; Create global memory buffer (show why using _ClipBoard_SetData is MUCH easier!)
                        $sData = "Hello from AutoIt"
                        $iSize = StringLen($sData) + 1
                        $hMemory = _MemGlobalAlloc($iSize, $GHND)
                        If $hMemory <> 0 Then
                            $hLock = _MemGlobalLock($hMemory)
                            If $hLock = 0 Then _WinAPI_ShowError("_Mem_GlobalLock failed")
                            $tData = DllStructCreate("char Text[" & $iSize & "]", $hLock)
                            DllStructSetData($tData, "Text", $sData)
                            _MemGlobalUnlock($hMemory)

                            ; Write clipboard text
                            If Not _ClipBoard_SetDataEx($hMemory, $CF_TEXT) Then _WinAPI_ShowError("_ClipBoard_SetDataEx failed")
                        Else
                            _WinAPI_ShowError("_Mem_GlobalAlloc failed")
                        EndIf

                        ; Close clipboard
                        _ClipBoard_Close()
                    Else
                        ; Close clipboard
                        _ClipBoard_Close()
                        _WinAPI_ShowError("_ClipBoard_Empty failed")
                    EndIf
                Else
                    _WinAPI_ShowError("_ClipBoard_Open failed")
                EndIf

            Case $idBtn_GetData
                _MemoWrite(_ClipBoard_GetData())
        EndSwitch
    WEnd
EndFunc   ;==>Example