AddLink

AddLink

Messagepar Stephane Maillard » 02 Août 2005 à 13:52

[syntax="ls"]Const wAPIModule = "NNOTES" ' Windows/32

Const TYPE_COMPOSITE = 1



Declare Private Function NSFItemAppend Lib wAPIModule Alias "NSFItemAppend" _

( Byval hNT As Long, Byval F As Integer, Byval N As String, Byval nN As Integer _

, Byval T As Integer, V As Any, Byval nV As Long) As Integer



Declare Private Sub CopyMem Lib "MSVCRT" Alias "memcpy" _

( P As Any, Byval S As Long, Byval N As Long)

Declare Private Sub Poke Lib "MSVCRT" Alias "memcpy" _

( P As Any, S As Any, Byval N As Long)

Declare Private Sub PokeString Lib "MSVCRT" Alias "memcpy" _

( P As Any, Byval S As String, Byval N As Long)





Class Buffer



Public Array As Variant



Private pointer As Integer



Public Sub New(bytes%)

Redim X(bytes% \ 2) As Integer

Array = X

ponter = 0

End Sub



Public Sub Put(V As Variant)

Select Case Typename(V)

Case "STRING" :

PokeString Array(pointer), V, Clng(Len(V))

pointer = pointer - Int(- Csng(Len(V) / 2))

Case "INTEGER" :

Poke Array(pointer), V, 2

pointer = pointer + 1

Case "LONG" :

Poke Array(pointer), V, 4

pointer = pointer + 2

Case "NOTESDATABASE" :

If V Is Nothing Then PokeHex String$(16, "0") Else PokeHex V.ReplicaID

Case "NOTESVIEW", "NOTESDOCUMENT" :

If V Is Nothing Then PokeHex String$(32, "0") Else PokeHex V.UniversalID

End Select

End Sub



Private Sub PokeHex(V As String)

For i% = 1 To Len(V) Step 16

Poke Array(pointer), Clng("&H" & Mid$(V, i% + 8, 8)), 4

pointer = pointer + 2

Poke Array(pointer), Clng("&H" & Mid$(V, i%, 8)), 4

pointer = pointer + 2

Next

End Sub



Public Property Get Length As Integer

Length = pointer * 2

End Property



Public Property Set Length As Integer

pointer = Length \ 2

End Property



Public Sub Dump

f% = Freefile()

Open "TEMP.DAT" For Binary Access Write As #f%

For i% = 0 To pointer - 1

Put #f%, , Array(i%)

Next

Close #f%

End Sub

End Class



Sub AddLink(doc As NotesDocument, text As String, linkdoc As NotesDocument, anchor As String, comment As String)

Const item$ = "Body"

Const itemlen% = Len(item$)



Dim hNT As Long

hNT = doc.Handle

If hNT = 0 Then Error 1234, "No document handle"



' create a memory buffer...

Dim mem As New Buffer(1024)



' add some text...

With mem

.Put Cint(&H0281) ' paragraph



.Put Cint(&HFF85) ' Text

.Put Cint(8 + Len(text)) ' length

.Put Clng(&H0A000001) ' font

.Put text

End With



' add a doclink...

If Not linkdoc Is Nothing Then

t$ = comment

If t$ = "" Then t$ = {Database '} & linkdoc.ParentDatabase.Title & {'} _

& {, View '} & linkdoc.ParentView.Name & {'} _

& {, Document '} & linkdoc.Subject(0) & {'}



t$ = t$ & Chr$(0) & linkdoc.ParentDatabase.Server & Chr$(0)

If Not anchor = "" Then t$ = t$ & anchor & Chr$(0)



With mem

.Put Cint(&HFF92) ' Link2

.Put Cint(44 + Len(t$)) ' length

.Put linkdoc.ParentDatabase

.Put linkdoc.ParentView

.Put linkdoc

.Put t$

End With

End If



' mem.Dump ' dump to file for debugging



' append the item to the note...

NSFItemAppend hNT, 0, item$, itemlen%, TYPE_COMPOSITE, mem.Array(0), mem.Length



End Sub[/syntax]
Cordialement

Stéphane Maillard
Avatar de l’utilisateur
Stephane Maillard
Lord of DominoArea
Lord of DominoArea
 
Message(s) : 8695
Inscrit(e) le : 16 Déc 2004 à 01:10
Localisation : Bretagne

Retour vers API