RTF über Zwischenablage nach Word
Verfasst: 03.11.2011 16:30
Hallo,
will meine Daten über die Zwischenablage in WORD einfügen.
Das Problem ist das nach dem Image einfügen in Word nichts
mehr kommt, sprich es fehtl der Ende Text!
Kann jemand sagen an was das liegt?
Gruss ... Velindos
will meine Daten über die Zwischenablage in WORD einfügen.
Das Problem ist das nach dem Image einfügen in Word nichts
mehr kommt, sprich es fehtl der Ende Text!
Code: Alles auswählen
;- Window Constants
;
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#B_Exit
#Notiz
#Bild
#Stichwort
#Bildvorlage
#myDisplay
#MySave
EndEnumeration
Global text$
Global rtf$
Global rrtf$
RedrawPfad$="C:\Velindos\Notizblock.bmp"
ReadFile(0, RedrawPfad$)
Buffersize = Lof(0)
Buffer = AllocateMemory(Buffersize)
ReadData(0, Buffer, Buffersize)
CloseFile(0)
myDisplay = CatchImage(#myDisplay, Buffer)
;ResizeImage (#myDisplay,270,290)
Procedure.s BMP2RTF(hBmap)
Protected rtf$, bitmap.BITMAP, screenDC, hdcMF, hMF, hdc
Protected oldImage, widthTwips, heightTwips, numBytes, mem, *bytes.BYTE, *string.WORD, i, low, high
If GetObject_(hBmap, SizeOf(BITMAP), bitmap)
If bitmap\bmWidth And bitmap\bmHeight
screenDC = GetDC_(0)
;Create an EMF to hold the bitmap.
hdcMF = CreateMetaFile_(0)
If hdcMF
SetMapMode_(hdcMF, #MM_ANISOTROPIC)
SetWindowOrgEx_(hdcMF, 0, 0, 0)
SetWindowExtEx_(hdcMF, bitmap\bmWidth, bitmap\bmHeight, 0)
hdc = CreateCompatibleDC_(screenDC)
If hdc
oldImage = SelectObject_(hdc, hBmap)
BitBlt_(hdcMF, 0, 0, bitmap\bmWidth, bitmap\bmHeight, hdc, 0, 0, #SRCCOPY)
SelectObject_(hdc, oldImage)
DeleteDC_(hdc)
hMF = CloseMetaFile_(hdcMF)
If hMF
;Before creating the RTF header we need to calculate the image width/height in twips.
widthTwips = MulDiv_(bitmap\bmWidth,1440,GetDeviceCaps_(screenDC, #LOGPIXELSX))
heightTwips = MulDiv_(bitmap\bmHeight,1440,GetDeviceCaps_(screenDC, #LOGPIXELSY))
;Now the rtf header.
;rtf$ = "{\rtf1{\pict\wmetafile8\picw" + Str(bitmap\bmWidth) + "\pich" + Str(bitmap\bmHeight) + "\picwgoal" + Str(widthTwips) + "\pichgoal" + Str(heightTwips) + " "
rtf$ = "{\pict\wmetafile8\picw" + Str(bitmap\bmWidth) + "\pich" + Str(bitmap\bmHeight) + "\picwgoal" + Str(widthTwips) + "\pichgoal" + Str(heightTwips) + " "
;Add the MF bits as double-character hex.
;First retrieve the MF bits.
numBytes = GetMetaFileBitsEx_(hMF, 0, 0)
mem = AllocateMemory(numBytes*3)
If mem
If GetMetaFileBitsEx_(hMF, numBytes, mem) = numBytes
*bytes=mem : *string = mem + numBytes
For i = 0 To numBytes-1
low = (*bytes\b)&$f + '0': high = (*bytes\b)>>4&$f + '0'
If low > '9'
low + 7
EndIf
If high > '9'
high + 7
EndIf
*string\w = low<<8 + high
*string + 2
*bytes + 1
Next
rtf$ + PeekS(mem + numBytes, numBytes<<1, #PB_Ascii) + "}"
Else
rtf$ = ""
EndIf
FreeMemory(mem)
Else
rtf$ = ""
EndIf
DeleteMetaFile_(hMF)
EndIf
Else
hMF = CloseEnhMetaFile_(hdcMF)
DeleteEnhMetaFile_(hMF)
EndIf
EndIf
ReleaseDC_(0, screenDC)
EndIf
EndIf
ProcedureReturn rtf$
EndProcedure
Procedure.i CopyRichTextToClipboard(rtf.s)
Protected format.i
Protected *globalMemory
Protected *lock
Protected result.i
format = RegisterClipboardFormat_("Rich Text Format")
If Not format
ProcedureReturn #False
EndIf
If Not OpenClipboard_(#Null)
ProcedureReturn #False
Else
EmptyClipboard_()
*globalMemory = GlobalAlloc_(#GMEM_MOVEABLE | #GMEM_DDESHARE, Len(rtf) + 1)
If Not *globalMemory
ProcedureReturn #False
EndIf
*lock = GlobalLock_(*globalMemory)
If Not *lock
GlobalFree_(*globalMemory)
ProcedureReturn #False
EndIf
PokeS(*lock, rtf, -1, #PB_Ascii) ; Text in ASCII umwandeln (falls Unicode verwendet wird) und schreiben.
GlobalUnlock_(*globalMemory)
result = SetClipboardData_(format, *globalMemory)
GlobalFree_(*globalMemory)
CloseClipboard_()
ProcedureReturn result
EndIf
ProcedureReturn #False
EndProcedure
OpenWindow(#Window_0, 266, 29, 667, 708, "TXT+Image to RTF-File", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
StringGadget(#Stichwort,20,20,100,20,"lkkölkölk")
ImageGadget(#Bild,20,50,100,100,00)
EditorGadget(#Notiz,20,400,200,100)
ButtonGadget(#MySave,300,20,120,20,"Save!")
SetGadgetState(#Bild, myDisplay)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow: End
Case #PB_Event_Gadget
Select EventGadget()
;Case #B_Dateiladen: Open_Windows_1()
;Case #B_OpenDatei: OpenDatei()
Case #MySave
Debug "mysave gedrückt"
;rtf$ = BMP2RTF(ImageID(#myDisplay))
rtf$ = BMP2RTF(myDisplay)
Debug rtf$
MeinText$="Stichwort "
MeinNotiz$="Meine Notizen"
text$ = "{\rtf1"
text$ + " \f2\fs28 "
text$ + MeinText$
text$ + "\par "
text$ + "\fs20 Arial"
;text$ + "Zeilenumbruch \f1 Arial\par "
text$ + MeinNotiz$
text$ + "\par "
text$ + "\par "
text$ + rtf$ +Chr(13)
text$ + "\par "
text$ + " Das Ende."
text$ + "}"
CopyRichTextToClipboard(text$)
Case #B_Exit: End
EndSelect
EndSelect
ForEver
Gruss ... Velindos