Memory StreamIn EditorGadget

Share your advanced PureBasic knowledge/code with the community.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Memory StreamIn EditorGadget

Post by ts-soft »

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
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.
Image
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

/OT

Cool use of "IncludeBinary" 8) 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

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.
Image
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

I also played around with this stuff once:
http://www.purebasic.fr/english/viewtopic.php?t=22443
I like logic, hence I dislike humans but love computers.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Joakim Christiansen wrote:I also played around with this stuff once:
http://www.purebasic.fr/english/viewtopic.php?t=22443
I saw your great code :D
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.
Image
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

@ ts-soft:

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()

Code: Select all

Static counter: counter+1: Debug Str(counter)+"   "+Str(offset)
I see that all the streaming occurs on program startup and none as the result of any vertical scrolling I do.

So how does streaming help? I cannot see any advantage in using it and I would welcome your feedback.
Anthony Jordan
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

> 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.
Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You can also, with a very slight modification, stream in raw RTF format.
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

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.
Image
Post Reply