'Visual basic 6.0 - Module for clipboard - Support Unicode Text
Option Explicit
Public Const CF_UNICODETEXT As Long = 13
Public Const GMEM_MOVEABLE As Long = &H2
Public Const GMEM_ZEROINIT As Long = &H40
Public Declare Function OpenClipboard Lib "user32.dll" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32.dll" () As Long
Public Declare Function GetClipboardData Lib "user32.dll" (ByVal wFormat As Long) As Long
Public Declare Function SetClipboardData Lib "user32.dll" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Public Declare Function EmptyClipboard Lib "user32.dll" () As Long
Public Declare Function IsClipboardFormatAvailable Lib "user32.dll" (ByVal wFormat As Long) As Long
Public Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyW" (ByVal lpString1 As Long, ByVal lpString2 As Long) As Long
Public Declare Function GlobalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Public Declare Function GlobalLock Lib "kernel32.dll" (ByVal hMem As Long) As Long
Public Declare Function GlobalUnlock Lib "kernel32.dll" (ByVal hMem As Long) As Long
Public Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
'Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Public Const WM_COPY As Long = &H301
Public Const WM_PASTE As Long = &H302
Public Function Get_clipboard() As String
Dim myStrPtr As Long, myLen As Long, myLock As Long, myData As String
OpenClipboard 0&
If IsClipboardFormatAvailable(CF_UNICODETEXT) = 0 Then MsgBox "Clipboard Text is not available now": Exit Function
myStrPtr = GetClipboardData(CF_UNICODETEXT)
If myStrPtr = 0 Then
MsgBox "Failed to get Clipboard Text"
Else
myLock = GlobalLock(myStrPtr)
myLen = GlobalSize(myStrPtr)
myData = String$(myLen \ 2 - 1, vbNullChar)
lstrcpy StrPtr(myData), myLock
GlobalUnlock myStrPtr
End If
CloseClipboard
Get_clipboard = myData
End Function
Public Sub Set_clipboard(s As String)
Dim myStrPtr As Long, myLen As Long, myLock As Long
OpenClipboard 0&
EmptyClipboard
myLen = LenB(s) + 2
myStrPtr = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, myLen)
myLock = GlobalLock(myStrPtr)
lstrcpy myLock, StrPtr(s)
GlobalUnlock myStrPtr
SetClipboardData CF_UNICODETEXT, myStrPtr
If IsClipboardFormatAvailable(CF_UNICODETEXT) = 0 Then MsgBox "Failed to set Clipboard Text"
CloseClipboard
End Sub
Title:
Clipboard Get and Set Method
Description:
'Visual basic 6.0 - Module for clipboard - Support Unicode Text Option Explicit Public Const CF_UNICODETEXT As Long = 13 Public Const GM...
...
Rating:
4