Lotus Notes FAQ Visit Our Sponsor!

Can you access the Clipboard in Notes?

This function (thanks to Manfred_Doerwald@IDG.DE) calls Win32 functions to put a field in the clipboard:

This goes in (Options):

'dataformat ID for ANSI text with ending null (\0). CR(13)/ LF(10) are for end of line.
Public Const CF_TEXT =  &H001

This goes in (Declarations):

Declare Function OpenClipboard Lib "User32.dll" Alias "OpenClipboard" (Byval hWnd As Long) As Long
Declare Function EmptyClipboard Lib "User32.dll" Alias "EmptyClipboard" ( )  As Long
Declare Function SetClipboardData Lib "User32.dll" Alias "SetClipboardData" (Byval wFormat As Integer,Byval hAnsiText As Long ) As String
Declare Function GetClipboardData Lib "User32.dll" Alias "GetClipboardData" (Byval wFormat As Integer) As String
Declare Function CloseClipboard Lib "User32.dll" Alias "CloseClipboard" ( ) As Long

Declare Function MYlstrcpy Lib "Kernel32.dll" Alias "lstrcpyA" (Byval Buffer As Long, Byval COPYString As String) As Long
Declare Function GlobalAlloc Lib "Kernel32.dll"  Alias "GlobalAlloc" (Byval wFlags As Long, Byval dwBytes As Long) As Long
Declare Function GlobalLock Lib "Kernel32.dll" Alias "GlobalLock"(Byval hMem As Long) As Long
Declare Function GlobalUnlock Lib "Kernel32.dll"  Alias "GlobalUnlock" (Byval hMem As Long) As Long
Declare Function GlobalFree Lib "Kernel32.dll"  Alias "GlobalFree" (Byval hMem As Long) As Long

This goes in the Click event for a button:

Sub Click(Source As Button)
  Dim Status As Long
  Dim ptr As Long, ghand As Long,handle As Long
  Dim Text As String
  Dim workspace As New NotesUIWorkspace
  Dim Uidoc As NotesUIDocument
  Dim item As NotesItem
  Dim s As New notessession
  Dim db As NotesDatabase
  Dim col As NotesDocumentCollection
  Dim doc As notesDocument
  Set db = s.currentdatabase
  Set col = db.unprocesseddocuments
  Set doc = col.getfirstdocument
  ' Control of platform 16/32-Bit
  If Instr(s.platform,"16") Then
    Messagebox ("Wrong Windows-platform; this agent runs only under Windows NT/95")
    Exit Sub
  End If
  ' Select Notes field
  Set item = doc.GetFirstItem("xxxxxx")
  ' open clipboard
  Status =  OpenClipboard(handle)
  If Status <> 0 Then
    ' Example: reading clipboard contense
    'Text = GetClipboardData(CF_TEXT)
    'Delete clipboard contense
    Status = EmptyClipboard()
    ' for testing purpose make a textstring
    'Text =   "Manfred Doerwald"
    'get global storage for field contense
    ghand = GlobalAlloc(0,(Len(item.Values(0))+1))
    'or global storage for textstring contense
    'ghand = GlobalAlloc(0,(Len(Text)+1))
    'lock global storage
    ptr = GlobalLock(ghand)
    'copy contense of  field to global storage
    Status = MYlstrcpy(ptr,item.Values(0))
    'or copy of textstring contense
    'Status = MYlstrcpy(ptr,Text)
    'free global storage
    Status = GlobalUnlock(ghand)
    'write to clipboard
    Call SetClipboardData(CF_TEXT, ptr)
    'close clipboard
    Status = CloseClipboard()
    'free handle of global storage
    Status = GlobalFree(ghand)
    Messagebox ("Error opening the clipboard!")
    Exit Sub
  End If
End Sub

Applies to Notes Versions: 4, 4.5, 4.6, 5
Last Modified: October 5, 1998