Ups ... i've made a mistake... just inserting the data but not the rtf-ansi-header of the new image (using the given one from the source code here).
Now it works really good but 2 questions i still have:
1) Is it possible to avoid resizing the images in the EditorGadget?
2) Does anyone knows in which format the wmetafile is? Something like .bmp? How to convert a jpg/bmp to this rtf-stuff? I would like to let users upload their (.jpg-)pictures and they should be send to the pb-client which should show those pictures in the EditorGadget()...
1) I don't know enough about ole/com to do this properly. I know it can be done because I have applications that do it. We did hack up a solution which was based on setting the editor gadget to read only and then intercepting mouse clicks, tabs etc. It wasn't pretty but it worked. It's in these forums somewhere.
Haven't actually run it (lack of time) but I can see that it produces the rtf string required to embed the image within an ole enabled rich edit control.
Is it crashing out or just doesn't appear to do anything?
I may look like a mule, but I'm not a complete ass.
The images (smileys) are already converted in rtf-ansi, but if you want to add new chat messages to the gadget, you can't stream... you must take the first part of the gadget (rtf-header including old messages)... put the new one in the middle and add at the end a "}" ... and then write it back to the gadget.
;**************MUST INCLUDE*****************************************************************
XIncludeFile "OLEedit.pbi"
;*******************************************************************************************
OpenWindow(0, 0, 0, 600, 400, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
EditorGadget(0, 8, 8, 500, 150)
;Set up the com interface for the editor gadget.
RichEdit_SetInterface(GadgetID(0))
;Load some .rtf content with a simple metafile.
Begin$ = "{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fcharset0 Arial;}}"
Begin$ +"{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\f0\fs20"
a$+"{\pict\wmetafile8\picwgoal903\pichgoal825 "
a$+"010009000003e402000008000601000000000400000003010800050000000b0200000000050000"
a$+"000c025e017d01040000002e0118001c000000fb021000070000000000bc020000000001020222"
a$+"53797374656d00017d010000f7a9724500ea120004ee8339706e22000c020000040000002d0100"
a$+"0004000000020101001c000000fb029cff0000000000009001000000000440001254696d657320"
a$+"4e657720526f6d616e0000000000000000000000000000000000040000002d0101000500000009"
a$+"02000000020d000000320a5700fdff01000400fdfffdff7a015b0120d92d00030000001e000700"
a$+"0000fc020000ff0000000000040000002d010200040000000601010008000000fa020500000000"
a$+"00ffffff00040000002d0103000601000024038100bb000300b1000300a80004009f0005009600"
a$+"06008d00080084000a007b000d00730010006b001300630017005b001b00540020004c00240045"
a$+"0029003f002f003800340032003a002c0040002700470022004d001d00540019005b0015006200"
a$+"11006a000e0072000b0079000800810006008a000500920003009a000300a3000200ac000300b4"
a$+"000300bd000500c5000600ce000800d6000b00de000e00e6001100ed001500f5001900fc001d00"
a$+"030122000a01270011012c00170132001d01380023013f00280145002e014c003301540037015b"
a$+"003c01630040016b004401730047017b004a0184004d018d004f01960051019f005201a8005301"
a$+"b1005401bb005401c4005401ce005301d7005201e0005101e9004f01f2004d01fa004a01030147"
a$+"010b014401130140011a013c01220137012901330130012e01370128013d01230143011d014901"
a$+"17014f01110154010a01580103015d01fc006101f5006501ed006801e6006b01de006d01d6006f"
a$+"01ce007101c5007201bd007301b4007301ac007301a30072019a00710192006f018a006d018100"
a$+"6b0179006801720065016a00610162005d015b005801540054014d004f0147004901400043013a"
a$+"003d01340037012f003001290029012400220120001a011b00130117000b01130003011000fa00"
a$+"0d00f2000a00e9000800e0000600d7000500ce000400c4000300bb00030008000000fa02000000"
a$+"00000000000000040000002d010400040000000601010007000000fc020000ffffff0000000400"
a$+"00002d01050008000000fa0200000600000000000000040000002d01060007000000fc02010000"
a$+"0000000000040000002d0107000601000025038100bb000300b1000300a80004009f0005009600"
a$+"06008d00080084000a007b000d00730010006b001300630017005b001b00540020004c00240045"
a$+"0029003f002f003800340032003a002c0040002700470022004d001d00540019005b0015006200"
a$+"11006a000e0072000b0079000800810006008a000500920003009a000300a3000200ac000300b4"
a$+"000300bd000500c5000600ce000800d6000b00de000e00e6001100ed001500f5001900fc001d00"
a$+"030122000a01270011012c00170132001d01380023013f00280145002e014c003301540037015b"
a$+"003c01630040016b004401730047017b004a0184004d018d004f01960051019f005201a8005301"
a$+"b1005401bb005401c4005401ce005301d7005201e0005101e9004f01f2004d01fa004a01030147"
a$+"010b014401130140011a013c01220137012901330130012e01370128013d01230143011d014901"
a$+"17014f01110154010a01580103015d01fc006101f5006501ed006801e6006b01de006d01d6006f"
a$+"01ce007101c5007201bd007301b4007301ac007301a30072019a00710192006f018a006d018100"
a$+"6b0179006801720065016a00610162005d015b005801540054014d004f0147004901400043013a"
a$+"003d01340037012f003001290029012400220120001a011b00130117000b01130003011000fa00"
a$+"0d00f2000a00e9000800e0000600d7000500ce000400c4000300bb000300040000002d01040004"
a$+"0000002d01050004000000f0010600040000002701ffff040000002d010000030000000000"
String$+Begin$
For I=1 To 100
String$+a$+"}"
Next
SetGadgetText(0, String$) ; Fill the gadget...Memory is now in use
SetGadgetText(0, "") ; Now i clear the gadget but the memory is still in use
Repeat
For a=1 To 50
If WindowEvent()=#PB_Event_CloseWindow
End
EndIf
Delay(2)
Next
SetGadgetText(0, String$) ; Fill the gadget...Memory is now in use
SetGadgetText(0, "") ;Memory is still in Use
Until WaitWindowEvent() = #PB_Event_CloseWindow
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
No, Macros is correct in that there is a major memory leak here. Afraid I don't really know enough about COM to get to the bottom of this. I'll keep looking though.
I may look like a mule, but I'm not a complete ass.
Procedure.l RichEdit_GetNewStorage(*pObject.RichEditOle, lplpstg)
Protected sc, lpLockBytes, t.ILockBytes
;Attempt to create a byte array object which acts as the 'foundation' for the upcoming compound file.
sc=CreateILockBytesOnHGlobal_(#Null, #True, @lpLockBytes)
If sc ;This means that the allocation failed.
ProcedureReturn sc
EndIf
;Allocation succeeded so we now attempt to create a compound file storage object.
sc=StgCreateDocfileOnILockBytes_(lpLockBytes, #STGM_SHARE_EXCLUSIVE|#STGM_READWRITE|#STGM_CREATE, 0, lplpstg)
t = lpLockBytes
t\Release()
EndProcedure
Common sense dictates that this should not work, but if the proof of the pudding is in the eating...
I'll keep looking for a better solution.
I may look like a mule, but I'm not a complete ass.