1 | ; 2nd Fixed version of _ClipBoard_GetData |
---|
2 | |
---|
3 | ; #FUNCTION# ==================================================================================================================== |
---|
4 | ; Name...........: _ClipBoard_GetData |
---|
5 | ; Description ...: Retrieves data from the clipboard in a specified format |
---|
6 | ; Syntax.........: _ClipBoard_GetData([$iFormat = 1]) |
---|
7 | ; Parameters ....: $iFormat - Specifies a clipboard format: |
---|
8 | ; |$CF_TEXT - Text format |
---|
9 | ; |$CF_BITMAP - Handle to a bitmap (HBITMAP) |
---|
10 | ; |$CF_METAFILEPICT - Handle to a metafile picture (METAFILEPICT) |
---|
11 | ; |$CF_SYLK - Microsoft Symbolic Link (SYLK) format |
---|
12 | ; |$CF_DIF - Software Arts' Data Interchange Format |
---|
13 | ; |$CF_TIFF - Tagged image file format |
---|
14 | ; |$CF_OEMTEXT - Text format containing characters in the OEM character set |
---|
15 | ; |$CF_DIB - BITMAPINFO structure followed by the bitmap bits |
---|
16 | ; |$CF_PALETTE - Handle to a color palette |
---|
17 | ; |$CF_PENDATA - Data for the pen extensions to Pen Computing |
---|
18 | ; |$CF_RIFF - Represents audio data in RIFF format |
---|
19 | ; |$CF_WAVE - Represents audio data in WAVE format |
---|
20 | ; |$CF_UNICODETEXT - Unicode text format |
---|
21 | ; |$CF_ENHMETAFILE - Handle to an enhanced metafile (HENHMETAFILE) |
---|
22 | ; |$CF_HDROP - Handle to type HDROP that identifies a list of files |
---|
23 | ; |$CF_LOCALE - Handle to the locale identifier associated with text in the clipboard |
---|
24 | ; |$CF_DIBV5 - BITMAPV5HEADER structure followed by bitmap color and the bitmap bits |
---|
25 | ; |$CF_OWNERDISPLAY - Owner display format |
---|
26 | ; |$CF_DSPTEXT - Text display format associated with a private format |
---|
27 | ; |$CF_DSPBITMAP - Bitmap display format associated with a private format |
---|
28 | ; |$CF_DSPMETAFILEPICT - Metafile picture display format associated with a private format |
---|
29 | ; |$CF_DSPENHMETAFILE - Enhanced metafile display format associated with a private format |
---|
30 | ; Return values .: Success - Text for text based formats or Binary data for all other formats |
---|
31 | ; - @extended is set to the # of characters for Text, or # of bytes for Binary |
---|
32 | ; Failure - 0 |
---|
33 | ; Author ........: Paul Campbell (PaulIA) |
---|
34 | ; Modified.......: Gary Frost, |
---|
35 | ; Ascend4nt (now follows traditional ClipBoard 'get' code, fixed $CF_UNICODETEXT errors) |
---|
36 | ; Remarks .......: This function performs all of the steps neccesary to get data from the clipboard. It checks to see if |
---|
37 | ; the data format is available, opens the clipboard, closes the clipboard and returns the data in one of |
---|
38 | ; two formats: String format for datatypes $CF_TEXT, $CF_OEMTEXT, or $CF_UNICODETEXT, |
---|
39 | ; or Binary format for every other type. If you need a finer degree of control over retrieving data from |
---|
40 | ; the clipboard, you may want to use the _ClipBoard_GetDataEx function. |
---|
41 | ; Related .......: _ClipBoard_GetDataEx, _ClipBoard_SetData |
---|
42 | ; Link ..........; |
---|
43 | ; Example .......; Yes |
---|
44 | ; =============================================================================================================================== |
---|
45 | Func _ClipBoard_GetData($iFormat = 1) |
---|
46 | Local $hMemory, $tData, $pMemoryBlock, $iDataSize, $vReturn |
---|
47 | |
---|
48 | ; Reset Global structure, releast memory |
---|
49 | $_stClipGetStruct = 0 |
---|
50 | |
---|
51 | If Not _ClipBoard_IsFormatAvailable($iFormat) Then Return SetError(-1, 0, 0) |
---|
52 | If Not _ClipBoard_Open(0) Then Return SetError(-2, 0, 0) |
---|
53 | $hMemory = _ClipBoard_GetDataEx($iFormat) |
---|
54 | |
---|
55 | ;_ClipBoard_Close() ; moved to end: traditionally done *after* copying over the memory |
---|
56 | |
---|
57 | If $hMemory=0 Then |
---|
58 | _ClipBoard_Close() |
---|
59 | Return SetError(-3, 0, 0) |
---|
60 | EndIf |
---|
61 | |
---|
62 | Local $pMemoryBlock=_MemGlobalLock($hMemory) |
---|
63 | |
---|
64 | If $pMemoryBlock=0 Then |
---|
65 | _ClipBoard_Close() |
---|
66 | Return SetError(-4,0,0) |
---|
67 | EndIf |
---|
68 | |
---|
69 | ; Get the actual memory size of the ClipBoard memory object (in bytes) |
---|
70 | $iDataSize=_MemGlobalSize($hMemory) |
---|
71 | |
---|
72 | If $iDataSize = 0 Then |
---|
73 | _MemGlobalUnlock($hMemory) |
---|
74 | _ClipBoard_Close() |
---|
75 | Return SetError(-5,0,"") |
---|
76 | EndIf |
---|
77 | |
---|
78 | Switch $iFormat |
---|
79 | Case $CF_TEXT, $CF_OEMTEXT |
---|
80 | $tData = DllStructCreate("char[" & $iDataSize & "]", $pMemoryBlock) |
---|
81 | Case $CF_UNICODETEXT |
---|
82 | ; Round() shouldn't be necessary, as CF_UNICODETEXT should be 2-bytes wide & thus evenly-divisible |
---|
83 | $iDataSize=Round($iDataSize/2) |
---|
84 | $tData = DllStructCreate("wchar[" & $iDataSize & "]", $pMemoryBlock) |
---|
85 | Case Else |
---|
86 | ; Binary data return for all other formats |
---|
87 | $tData = DllStructCreate("ubyte[" & $iDataSize & "]", $pMemoryBlock) |
---|
88 | EndSwitch |
---|
89 | ; Grab the data from the Structure so the Memory can be unlocked |
---|
90 | $vReturn = DllStructGetData($tData, 1) |
---|
91 | |
---|
92 | ; Unlock the memory & Close the clipboard now that we have grabbed what we needed |
---|
93 | _MemGlobalUnlock($hMemory) |
---|
94 | _ClipBoard_Close() |
---|
95 | |
---|
96 | ; Return the size of the string or binary object in @extended |
---|
97 | SetError(0,$iDataSize) |
---|
98 | Return $vReturn |
---|
99 | EndFunc ;==>_ClipBoard_GetData |
---|