How to get clipboard data size?

  • Thread starter Thread starter yxq
  • Start date Start date
Y

yxq

Hello
I want to get Windows clipboard data size, seem to use the function
"GetClipboardDataSize".

Could anyone please tell how to do using vb.net?

Thanks
 
Thanks

But i dont know how to get the size.

I found the vb6 code to get text and image size, but how to get all data
size?

'***
Private Declare Function OpenClipboard Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" _
(ByVal wFormat As Long) As Long
Private Declare Function GetClipboardData Lib "user32" _
(ByVal wFormat As Long) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" _
(ByVal lpString As Long) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" _
(ByVal hObject As Long, ByVal nCount As Long, _
ByRef lpObject As Any) As Long
Private Declare Sub RtlMoveMemory Lib "kernel32" _
(ByRef Destination As Any, ByRef Source As Any, _
ByVal Length As Long)

Private Type Bitmap ' 24 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type

Private Const CF_TEXT As Long = &H1
Private Const CF_BITMAP As Long = &H2

Private Sub Form_Load()
Dim TextPtr As Long
Dim DataPtr As Long
Dim ClipboardText As String
Dim hDIB As Long
Dim BMInfo As Bitmap
Dim DIBSize As Long


' Try and open the clipboard
If (OpenClipboard(Me.hwnd)) Then
If (IsClipboardFormatAvailable(CF_TEXT)) Then
TextPtr = GetClipboardData(CF_TEXT)

' De-reference the pointer
Call RtlMoveMemory(DataPtr, ByVal TextPtr, &H4)

Debug.Print "CF_TEXT size: " & BytesToDisplay(lstrlen(DataPtr))
Else
Debug.Print "No text in clipboard buffer"
End If

If (IsClipboardFormatAvailable(CF_BITMAP)) Then
hDIB = GetClipboardData(CF_BITMAP)

If (GetObject(hDIB, Len(BMInfo), BMInfo)) Then
' Get data and BMIH size
DIBSize = (BMInfo.bmWidthBytes * BMInfo.bmHeight) + 40

' Append palette size if required
If ((BMInfo.bmBitsPixel <= 8) And (BMInfo.bmBitsPixel > 0))
Then _
DIBSize = DIBSize + (2 ^ BMInfo.bmBitsPixel) * 4

Debug.Print "CF_BITMAP size: " & BytesToDisplay(DIBSize)
Else
Debug.Print "Error getting Bitmap information..."
End If
Else
Debug.Print "No DIB in clipboard buffer"
End If

' Make sure we close the clipboard before quitting
Call CloseClipboard
End If
End Sub

Private Function BytesToDisplay(ByVal inSize As Variant, _
Optional ByVal inShowBytes As Boolean = False) As String
Dim CheckSize As Variant, LastSize As Variant ' Coerced into decimal
Dim LoopSize As Long

CheckSize = CDec(1)
For LoopSize = 0 To 8
LastSize = CheckSize
CheckSize = (2 ^ 10) ^ LoopSize
If (CheckSize > inSize) Then Exit For
Next LoopSize

' Byte, KiloB., MegaB., GigaB., TeraB., PetaB., ExaB., ZettaB., YottaB.
BytesToDisplay = Format(inSize / IIf(LoopSize < 9, LastSize, CheckSize),
IIf(LoopSize > 1, "0.00", "0")) & " " & Choose(LoopSize, _
"bytes", "kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb")

If (inShowBytes And (LoopSize > 1)) Then _
BytesToDisplay = BytesToDisplay & (" (" & _
Format(inSize, "#,###,###,###,###,###,###,###,###") & " bytes)")
End Function
'***
 
Back
Top