-
Apr 21st, 2017, 12:26 PM
#1
Thread Starter
PowerPoster
-
Apr 21st, 2017, 12:35 PM
#2
Re: How to get the size of the RTF content from the clipboard ?
APIs. GetClipboardData will get you a handle to the clipboard item. Then you can use GlobalSize API to determine is size (estimated). With text, there can be garbage appended and that's where lstrlenW/lstrlen APIs can help
-
Apr 21st, 2017, 01:19 PM
#3
Thread Starter
PowerPoster
Re: How to get the size of the RTF content from the clipboard ?
Hi Lavolpe, I found the following code from your AlphaImage, but did not get the size of the RTF, I don't know which parameter is wrong.
Code:
Option Explicit
' User32 APIs
Private Declare Function OpenClipboard Lib "user32.dll" (ByVal hWnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32.dll" () As Long
Private Declare Function GetClipboardData Lib "user32.dll" (ByVal wFormat As Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32.dll" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "kernel32.dll" (ByVal hMem As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalSize Lib "kernel32.dll" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32.dll" (ByVal hMem As Long) As Long
Private Sub Command1_Click()
Dim hHandle As Long, lSize As Long
If Clipboard.GetFormat(vbCFRTF) Then
If OpenClipboard(0&) Then
hHandle = GetClipboardData(vbCFEMetafile And &HFFFF&)
If hHandle Then
lSize = GlobalSize(hHandle)
'If lSize > 0& Then
'ReDim inArray(0 To lSize - 1&)
'lSize = GlobalLock(hHandle)
'CopyMemory inArray(0), ByVal lSize, UBound(inArray) + 1&
'End If
'GlobalUnlock hHandle
End If
CloseClipboard
End If
End If
End Sub
-
Apr 21st, 2017, 01:33 PM
#4
Re: How to get the size of the RTF content from the clipboard ?
Well, for starters this is wrong: vbCFEMetafile
Also, you gotta release the handle if it returned non-zero. However, vbCFRTF And &HFFFF& is returning a zero handle, looking at it now.
-
Apr 21st, 2017, 01:45 PM
#5
Re: How to get the size of the RTF content from the clipboard ?
Ok, vbCFRTF is not a valid clipboard format on my Win10 machine. When I copied RTF from WordPad to the clipboard, I enumerated all the formats placed on the clipboard and guess which isn't there? vbCFRTF. That may be an internal constant for vb and when it is used, VB retrieves the correct format handle. These types of clipboard formats are not guaranteed to be the same value day in and day out.
Code:
' API
Private Declare Function RegisterClipboardFormat Lib "user32.dll" Alias "RegisterClipboardFormatA" (ByVal lpString As String) As Long
Dim realCFRTF As Integer, lValue As Long
lValue = RegisterClipboardFormat("Rich Text Format")
' convert long to integer
If lvalue > &H7FFF Then
realCFRTF = (lValue And &H7FFF) Or &H8000
Else
realCFRTF = lValue
End If
now you can use realCFRTF with VB's Clipboard.GetFormat and convert to Long for APIs via: realCFRTF And &HFFFF&
That should do the trick. RTF is just one such clipboard format that is retrieved like shown above. When WordPad placed stuff on the clipboard, it placed 10 such formats along with 6 standard formats (none was vb's CFRTF)
-
Apr 21st, 2017, 10:12 PM
#6
Thread Starter
PowerPoster
Re: How to get the size of the RTF content from the clipboard ?
According to your advice, now the problem has been solved. Thank you very much, LaVolpe.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|