udfClipGetDataAsString
str udfClipGetDataAsString (hdlWnd, int, str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfClipGetDataAsString (hdlWndOwner, intFormatID, strNullChar) ; The If-Then-Else version.
hdlUser32 = DllLoad (StrCat (DirWindows(1), "USER32.DLL"))
hdlKernel32 = DllLoad (StrCat (DirWindows(1), "KERNEL32.DLL"))
strString = ""
; Open the clipboard for access.
If !!DllCall (hdlUser32, long:"OpenClipboard", long:hdlWndOwner)
   ; Check if this data format is available.
   If !!DllCall (hdlUser32, long:"IsClipboardFormatAvailable", long:intFormatID)
      ; Get the memory handle to the data.
      hdlMem = DllCall (hdlUser32, long:"GetClipboardData", long:intFormatID)
      If !!hdlMem
         ; Get the size of this memory block.
         intSize = DllCall (hdlKernel32, long:"GlobalSize", long:hdlMem)
         If !!intSize
            ; Get a pointer to the memory.
            intPtr = DllCall (hdlKernel32, long:"GlobalLock", long:hdlMem)
            If !!intPtr
               ; Allocate a binary buffer to hold the data.
               hdlBB = BinaryAlloc (intSize)
               BinaryEodSet (hdlBB, intSize)
               intptrBB = IntControl (42, hdlBB, 0, 0, 0)

               ; Copy data from the pointer into the binary buffer.
               intResult = DllCall (hdlKernel32, long:"RtlMoveMemory", long:intptrBB, long:intPtr, long:intSize)

               ; Unlock the memory block.
               intResult = DllCall (hdlKernel32, long:"GlobalUnlock", long:hdlMem)

               ; Now get the data from binary buffer as a string.
               If strNullChar != "" Then BinaryReplace (hdlBB, "", StrSub (strNullChar, 1, 1), @TRUE)
               strString = BinaryPeekStr (hdlBB, 0, intSize)
               hdlBB = BinaryFree (hdlBB)
            EndIf
         EndIf
      EndIf
   EndIf
   DllCall (hdlUser32,long:"CloseClipboard")
EndIf
hdlKernel32 = DllFree (hdlKernel32)
hdlUser32 = DllFree (hdlUser32)
Return strString
;..........................................................................................................................................
; This function udfClipGetDataAstrString returns the current clipboard data as a string.
;
; Parameter:
; hdlWndOwner
; ... Handle to the window to be associated with the open clipboard.
;     If this parameter is NULL, then the open clipboard is associated with the current task.
;     In general you can apply the WinBatch function DllHwnd ("") as current hdlWndOwner.
;
; intFormatID
; ... Specifies the type of format to be retrieved.
;     This parameter must not specify any of the predefined clipboard formats.
;
; strNullChar
; ... Depending on the current data format the clipboard data may contain binary zeroes.
;     The parameter strNullChar controls how to handle those binary zeroes.
;     strNullChar specifies a 1-byte character that replaces a NULL byte in the returning string.
;     If strNullChar is an empty string, then NULL bytes will not be removed.
;     For text/html data the strNullChar can be an empty string as default.
;..........................................................................................................................................
; Detlev Dalitz.20030119
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfClipGetDataAsString2 (hdlWndOwner, intFormatID, strNullChar) ; The Switch-Case-EndSwitch version.
hdlUser32 = DllLoad (StrCat (DirWindows(1), "USER32.DLL"))
hdlKernel32 = DllLoad (StrCat (DirWindows(1), "KERNEL32.DLL"))
strString = ""
Switch @TRUE
Case !DllCall (hdlUser32, long:"OpenClipboard", long:hdlWndOwner) ; Open the clipboard for access.
   Break
Case !DllCall (hdlUser32, long:"IsClipboardFormatAvailable", long:intFormatID) ; Check if this data format is available.
   Break
Case @TRUE
   hdlMem = DllCall (hdlUser32, long:"GetClipboardData", long:intFormatID) ; Get the memory handle to the data.
   Continue
Case !hdlMem
   Break
Case @TRUE
   intSize = DllCall (hdlKernel32, long:"GlobalSize", long:hdlMem) ; Get the memory handle to the data.
   Continue
Case !intSize
   Break
Case @TRUE
   intPtr = DllCall (hdlKernel32, long:"GlobalLock", long:hdlMem) ; Get a pointer to the memory.
   Continue
Case !intPtr
   Break
Case @TRUE
   ; Allocate a binary buffer to hold the data.
   hdlBB = BinaryAlloc (intSize)
   BinaryEodSet (hdlBB, intSize)
   intPtrBB = IntControl (42, hdlBB, 0, 0, 0)

   ; Copy data from the pointer into the binary buffer.
   intResult = DllCall (hdlKernel32, long:"RtlMoveMemory", long:intPtrBB, long:intPtr, long:intSize)

   ; Unlock the memory block.
   intResult = DllCall (hdlKernel32, long:"GlobalUnlock", long:hdlMem)

   ; Now get the data from binary buffer as a string.
   If strNullChar != "" Then BinaryReplace (hdlBB, "", StrSub (strNullChar, 1, 1), @TRUE)
   strString = BinaryPeekStr (hdlBB, 0, intSize)
   hdlBB = BinaryFree (hdlBB)
   DllCall (hdlUser32,long:"CloseClipboard")
   Break
EndSwitch
hdlKernel32 = DllFree (hdlKernel32)
hdlUser32 = DllFree (hdlUser32)
Return strString
;..........................................................................................................................................
; This function udfClipGetDataAstrString returns the current clipboard data as a string.
;
; Parameter:
; hdlWndOwner
; ... Handle to the window to be associated with the open clipboard.
;     If this parameter is NULL, then the open clipboard is associated with the current task.
;     In general you can apply the WinBatch function DllHwnd ("") as current hdlWndOwner.
;
; intFormatID
; ... Specifies the type of format to be retrieved.
;     This parameter must not specify any of the predefined clipboard formats.
;
; strNullChar
; ... Depending on the current data format the clipboard data may contain binary zeroes.
;     The parameter strNullChar controls how to handle those binary zeroes.
;     strNullChar specifies a 1-byte character that replaces a NULL byte in the returning string.
;     If strNullChar is an empty string, then NULL bytes will not be removed.
;     For text/html data the strNullChar can be an empty string as default.
;..........................................................................................................................................
; Detlev Dalitz.20030119.20090429.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfClipGetIDForCustomFormat (strFormatName)
intFormatID = DllCall ("USER32.DLL", long:"RegisterClipboardFormatA", lpstr:strFormatName)
If intFormatID < 49152 Then intFormatID = 0
Return intFormatID
;..........................................................................................................................................
; The RegisterClipboardFormat function registers a new clipboard format.
; Registered clipboard formats are identified by values in the range 0xC000 (49152) through 0xFFFF (65535).
; This format can then be used as a valid clipboard format.
;
; If the function succeeds, the return value identifies the registered clipboard format.
; If the function fails, the return value is zero.
;
; If a registered format with the specified name already exists,
; then a new format is not registered and the return value identifies the existing format.
; This enables more than one application to copy and paste data using the same registered clipboard format.
; Note that the format name comparison is case-insensitive.
;..........................................................................................................................................
; Detlev Dalitz.20030119
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

; The following code will get any information pasted onto the clipboard in HTML Format.
; HTML Format is pasted by Internet Explorer, and gives you an entire HTML document
; based on the selection you have copied to the clipboard.

intFormatID = udfClipGetIDForCustomFormat ("HTML Format")
If !!intFormatID
   strText = udfClipGetDataAsString (DllHwnd (""), intFormatID, "")
   ; Take a look with WinBatch browser.
   strFilename = FileCreateTemp ("TMP")
   FilePut (strFilename, strText)
   If Run (StrCat (DirHome(), "browser.exe"), strFilename)
      sBrowser = WinGetactive ()
      SendKeysTo (sBrowser, "^t")
      WinWaitClose (sBrowser)
   EndIf
   ; Note: If the file is empty, then you might have forgotten
   ; to copy some HTML related data to the clipboard.
   If FileExist (strFilename) == 1 Then FileDelete (strFilename)
EndIf

:CANCEL
Exit
;------------------------------------------------------------------------------------------------------------------------------------------