Page 1 of 1

Posted: Sat Nov 18, 2006 5:31 pm
by Sparkie
In theory you should be able to accomplish your task. Without seeing your code it's difficult to see what's going wrong. Here's some streaming text that changes color at each uppercase/lowercase character. Note that nothing is selected at the time of the color change.

Code: Select all

;Streaming code credit goes to El_Choni 
Global *InPtr, InText$

Procedure EditStreamCallback(dwCookie.l, *pbBuff.l, cb.l, *pcb.Long) 
  If dwCookie = 0
    length = MemoryStringLength(*InPtr) 
    If length > cb 
      CopyMemory(*InPtr, *pbBuff, cb) 
      *InPtr + cb 
      *pcb\l = cb 
    ElseIf length < = cb 
      CopyMemory(*InPtr, *pbBuff, length) 
      *InPtr + length 
      *pcb\l = length 
    EndIf 
  EndIf 
  ProcedureReturn #S_OK 
EndProcedure 

Procedure SetColor(Gadget, Color) 
  Protected format.CHARFORMAT2, sel.CHARRANGE, sel_saved.CHARRANGE 
  format\cbSize      = SizeOf(CHARFORMAT2) 
  format\dwMask      = #CFM_COLOR 
  format\crTextColor = Color 
  SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format) 
EndProcedure 

OpenWindow(0, 0, 0, 322, 170, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
CreateGadgetList(WindowID(0)) 
EditorGadget(0, 8, 8, 306, 133, #PB_Editor_ReadOnly) 
SetActiveGadget(0) 
SetColor(0, #Blue) 
eStream.EDITSTREAM 
eStream\dwCookie = 0 
eStream\pfnCallback = @EditStreamCallback() 

Restore myData

For c = 1 To 46
  Read myChar.c
  InText$ =  Chr(myChar)
  *InPtr = @InText$
  Delay(100)
  If Asc(InText$) < 97
    SetColor(0, #Blue)
  Else
    SetColor(0, #Red)
  EndIf
  SendMessage_(GadgetID(0), #EM_STREAMIN, #SF_TEXT | #SFF_SELECTION, @eStream)
  UpdateWindow_(GadgetID(0))
Next c

Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow 

End

DataSection
myData:
Data.s "The Lazy Brown Fox ", Chr(13), "Jumped Over Fred's Head"
EndDataSection

Posted: Sun Nov 19, 2006 11:41 am
by drahneir
Yes, Sparkie, that's it. Thank you very much for your help. Now the color remains when leaving transmit. Well, that was a long birth, but finally it works. The way via streamin calback looks to me a bit complicated and I wouldn't have gone it on my own :lol: . Thanks again.

Posted: Thu Nov 23, 2006 2:44 pm
by drahneir
A final remark on this subject:
after some investigation I found out why it didn't work before. I appended new text the PureBasic way

Code: Select all

SetGadgetText(Gadget, GetGadgetText(Gadget) + NewText)
This command caused the loss of previous format settings.
Now I use the '#EM_REPLACESEL' message. It works fine and I don't need a callback function.

Posted: Thu Nov 23, 2006 3:08 pm
by srod
drahneir wrote:A final remark on this subject:
after some investigation I found out why it didn't work before. I appended new text the PureBasic way

Code: Select all

SetGadgetText(Gadget, GetGadgetText(Gadget) + NewText)
This command caused the loss of previous format settings.
Aye it would do! :)

That explains things.