Thomas Risi Softwareentwicklung

StringToClipboard

Aus einer Frage in einem Forum ...

Es soll der Inhalt einer String-Variablen in die Zwischenablage kopiert werden.

Option Explicit 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 EmptyClipboard Lib "user32.dll" () As Long Private Declare Function SetClipboardData Lib "user32.dll" ( _ ByVal wFormat As Long, _ ByVal hMem As Long) As Long Private Declare Function GlobalAlloc Lib "kernel32.dll" ( _ ByVal wFlags As Long, _ ByVal dwBytes As Long) As Long Private Declare Function GlobalLock Lib "kernel32.dll" ( _ ByVal hMem As Long) As Long Private Declare Function GlobalUnlock Lib "kernel32.dll" ( _ ByVal hMem As Long) As Long Private Declare Function GlobalFree Lib "kernel32.dll" ( _ ByVal hMem As Long) As Long Private Declare Function lstrcpy Lib "kernel32" ( _ ByVal lpStr1 As Any, _ ByVal lpStr2 As Any) As Long Private Const CF_TEXT As Long = 1& Private Const GMEM_MOVEABLE As Long = 2& Sub Test() Call StringToClipboard("Hallo ...") End Sub Private Sub StringToClipboard(s As String) Dim hMem As Long Dim hPtr As Long hMem = GlobalAlloc(GMEM_MOVEABLE, Len(s) + 1) hPtr = GlobalLock(hMem) lstrcpy hPtr, s GlobalUnlock hMem OpenClipboard 0& EmptyClipboard SetClipboardData CF_TEXT, hMem CloseClipboard GlobalFree hMem End Sub

Bewerten Sie bitte dieses Programm.
1 2 3 4 5
Weniger nützlich Sehr nützlich
Bitte teilen Sie uns mit, warum Sie das Programm so bewertet haben. (optional)