; PB 4.xx
; Target OS Windows (x86, x64, ASCII and Unicode)
; Author: Thomas <ts-soft> Schulz
; 2009/05/08
; Memory in EditorGadget streamen
EnableExplicit
Procedure StreamMemoryIn_Callback(dwCookie, pbBuff, cb, *pcb.Integer)
Static offset = 0
If offset + cb <= MemorySize(dwCookie)
; we copy the complett buffer (pbBuff), size is cb
CopyMemory(dwCookie + offset, pbBuff, cb)
offset + cb ; offset
*pcb\i = cb
Else
If offset = MemorySize(dwCookie)
*pcb\i = 0 ; here is the finish
offset = 0 ; offset to 0 for next order
Else
; we copy the rest, smaller as pbbuff
CopyMemory(dwCookie + offset, pbBuff, MemorySize(dwCookie) - offset)
*pcb\i = MemorySize(dwCookie) - offset
offset = MemorySize(dwCookie)
EndIf
EndIf
ProcedureReturn 0
EndProcedure
Procedure Editor_StreamMemoryIn(ID, *mem, type = #SF_TEXT)
Protected StreamData.EDITSTREAM
StreamData\dwCookie = *mem
StreamData\dwError = #Null
StreamData\pfnCallback = @StreamMemoryIn_Callback()
SendMessage_(GadgetID(ID), #EM_STREAMIN, type, @StreamData)
EndProcedure
; a not so good example ;)
OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 480, "void", #PB_Window_SystemMenu)
EditorGadget(0, 0, 0, 640, 480)
Define *mem = AllocateMemory(?readme_end - ?readme_start)
If *mem
CopyMemory(?readme_start, *mem, MemorySize(*mem))
Editor_StreamMemoryIn(0, *mem)
FreeMemory(*mem)
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
DataSection
readme_start: IncludeBinary #PB_Compiler_Home + "SDK\Readme.txt" : readme_end:
EndDataSection
Last edited by ts-soft on Sat May 09, 2009 7:36 pm, edited 1 time in total.
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.
Cool use of "IncludeBinary" I'm gonna borrow that !
I'll take a peek at the gadget while I'm at it
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
After writing this, i found a snippet by freak in the codearchiv. Is much
shorter, but it copied over the end of the memory. Is this sure? Seems to
work with RTF.
My Snippet work also with text. I require this in a short HexViewer.
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.
I saw your great code
After reading this, comes the idea to stream memory in as required for my hexviewer.
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.
Have I missed the point of this program?
I expected that streaming would take place as a direct result of my scrolling the EditorGadget, but this does not happen.
By inserting this extra line within the procedure StreamMemoryIn_Callback()
> So how does streaming help?
Is the fastest way to fill a editorgadget with large text.
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.
srod wrote:You can also, with a very slight modification, stream in raw RTF format.
added to the code, thanks
you can optioal use #SF_RTF or other Types
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.