Memory StreamIn EditorGadget
Posted: Fri May 08, 2009 4:42 am
Code: Select all
; 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