It is currently Wed Oct 21, 2020 3:09 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Aug 31, 2020 3:19 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
Hello
I found this code on forum:
Code:
#RICHEDIT = #WS_CHILD|#WS_VISIBLE|#WS_VSCROLL|#ES_MULTILINE|#ES_AUTOVSCROLL|#ES_NOHIDESEL
#SCF_ALL = 4
#SCF_SELECTION = $0001
#SCF_WORD = $0002
#MainWindow = 1
#WINDOW_PARAMETERS = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget

If OpenWindow(0, 100, 200, 500, 500, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)

  If LoadLibrary_("RICHED20.DLL")
    RichClass.s = "RichEdit20A"
  Else
    If LoadLibrary_("RICHED32.DLL")
      RichClass.s = "RichEdit"
    Else
      MessageRequester("Error", "RichEdit Windows library not present.", 0)
      End
    EndIf
  EndIf
  hWnd = CreateWindowEx_(#WS_EX_CLIENTEDGE, "riched32.dll", "This will With SetWindowText.", 1412518084 , 10, 10, 300, 300, 1, 100, 0, 0)
  ;hRichEdit = CreateWindowEx(_ext,"richedit20a",_etext,_eflag,_ex,_ey,_ew,_eh,_ehwnd,_cID,0,NULL)
  If hWnd <> 0
    ShowWindow_(hWnd, #SW_HIDE) ; hide our changes to the user
    SetWindowText_(hWnd, "Hi everybody!")
    BGR = 0
    SendMessage_(hWnd, #EM_SETBKGNDCOLOR, 0, BGR) ; BGR value = black
    cf.CHARFORMAT
    cf\cbSize = SizeOf(CHARFORMAT)
    Red = 0
    Green = 255
    Blue = 0
    BGR = (Blue*65536)|(Green*256)|Red
    cf\crTextColor = BGR ; BGR value = green
    FontFace.s = "Courier New"
    For t = 0 To Len(FontFace)
      cf\szFaceName[t] = Asc(Mid(FontFace, t+1, 1))
    Next t
    cf\dwMask =#CFM_COLOR|#CFM_FACE
    SendMessage_(hWnd, #EM_SETCHARFORMAT, #SCF_ALL, @cf)
    ShowWindow_(hWnd, #SW_SHOW) ; now show
    SetForegroundWindow_(1)
    EndIf
   
     Repeat
        Event = WaitWindowEvent()
       
        If Event = #WM_CLOSE  ; If the user has pressed on the close button
           Quit = 1
       EndIf

      Until Quit = 1
 
   
 EndIf
 
 


;End


But mather what i change i cennot get that richedit control is visible
any help ?


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Aug 31, 2020 3:56 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 766
Location: Linz, Austria
Code:
hWnd = CreateWindowEx_(#WS_EX_CLIENTEDGE, RichClass, "This will With SetWindowText.", #WS_CHILD|#WS_VISIBLE , 10, 10, 300, 300, WindowID(0), 100, GetModuleHandle_(0), 0)

_________________
Et cetera is my worst enemy


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Aug 31, 2020 5:53 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
thanks chi
but still is not visible ...i am really confused now..

Code:
#RICHEDIT = #WS_CHILD|#WS_VISIBLE|#WS_VSCROLL|#ES_MULTILINE|#ES_AUTOVSCROLL|#ES_NOHIDESEL
#SCF_ALL = 4
#SCF_SELECTION = $0001
#SCF_WORD = $0002
#MainWindow = 1
#WINDOW_PARAMETERS = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget

OpenWindow(0, 100, 200, 600, 500, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)

  If LoadLibrary_("RICHED20.DLL")
    RichClass.s = "RichEdit20A"
  Else
    If LoadLibrary_("RICHED32.DLL")
      RichClass.s = "RichEdit"
    Else
      MessageRequester("Error", "RichEdit Windows library not present.", 0)
      End
    EndIf
  EndIf
  hWnd = CreateWindowEx_(#WS_EX_CLIENTEDGE, "riched32.dll", "rich test", #WS_CHILD|#WS_VISIBLE, 10, 10, 300, 300, WindowID(0), 100, GetModuleHandle_(0), 0)
  ;hRichEdit = CreateWindowEx(_ext,"richedit20a",_etext,_eflag,_ex,_ey,_ew,_eh,_ehwnd,_cID,0,NULL)1412518084
  If hWnd
   ; ShowWindow_(hWnd, #SW_HIDE) ; hide our changes to the user
    SetWindowText_(hWnd, "Hi everybody!")
    BGR = 0
    SendMessage_(hWnd, #EM_SETBKGNDCOLOR, 0, BGR) ; BGR value = black
    cf.CHARFORMAT
    cf\cbSize = SizeOf(CHARFORMAT)
    Red = 0
    Green = 255
    Blue = 0
    BGR = (Blue*65536)|(Green*256)|Red
    cf\crTextColor = BGR ; BGR value = green
    FontFace.s = "Courier New"
    For t = 0 To Len(FontFace)
      cf\szFaceName[t] = Asc(Mid(FontFace, t+1, 1))
    Next t
    cf\dwMask =#CFM_COLOR|#CFM_FACE
    SendMessage_(hWnd, #EM_SETCHARFORMAT, #SCF_ALL, @cf)
    ShowWindow_(hWnd, #SW_SHOW) ; now show
   
    EndIf
   
     Repeat
        Event = WaitWindowEvent()
       
        If Event = #WM_CLOSE  ; If the user has pressed on the close button
           Quit = 1
       EndIf

      Until Quit = 1
 
   
 
 
 


;End


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Aug 31, 2020 6:01 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
I add messagebox
and get message that rich edit gadget or control is not created ,is that proper way?
Code:
#RICHEDIT = #WS_CHILD|#WS_VISIBLE|#WS_VSCROLL|#ES_MULTILINE|#ES_AUTOVSCROLL|#ES_NOHIDESEL
#SCF_ALL = 4
#SCF_SELECTION = $0001
#SCF_WORD = $0002
#MainWindow = 1
#WINDOW_PARAMETERS = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget

OpenWindow(0, 100, 200, 600, 500, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)

 
   LoadLibrary_("RICHED32.DLL")
 
  hRich.l = CreateWindowEx_(#WS_EX_CLIENTEDGE, "riched32.dll", "rich test", #WS_CHILD|#WS_VISIBLE, 10, 10, 300, 300, WindowID(0), 100, GetModuleHandle_(0), 0)
  ;hRichEdit = CreateWindowEx(_ext,"richedit20a",_etext,_eflag,_ex,_ey,_ew,_eh,_ehwnd,_cID,0,NULL)1412518084
  If hRich <> 0
   ShowWindow_(hRich, #SW_HIDE) ; hide our changes to the user
    SetWindowText_(hRich, "Hi everybody!")
    BGR = 0
    SendMessage_(hRich, #EM_SETBKGNDCOLOR, 0, BGR) ; BGR value = black
    cf.CHARFORMAT
    cf\cbSize = SizeOf(CHARFORMAT)
    Red = 0
    Green = 255
    Blue = 0
    BGR = (Blue*65536)|(Green*256)|Red
    cf\crTextColor = BGR ; BGR value = green
    FontFace.s = "Courier New"
    For t = 0 To Len(FontFace)
      cf\szFaceName[t] = Asc(Mid(FontFace, t+1, 1))
    Next t
    cf\dwMask =#CFM_COLOR|#CFM_FACE
    SendMessage_(hRich, #EM_SETCHARFORMAT, #SCF_ALL, @cf)
    ShowWindow_(hRich, #SW_SHOW) ; now show
  Else
    MessageRequester("Information", "RichEdit is not created", 0)
   
    EndIf
   
     Repeat
        Event = WaitWindowEvent()
       
        If Event = #WM_CLOSE  ; If the user has pressed on the close button
           Quit = 1
       EndIf

      Until Quit = 1
 

;End


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Aug 31, 2020 6:42 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 766
Location: Linz, Austria
The second parameter of CreateWindowEx should be the ClassName!

_________________
Et cetera is my worst enemy


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Aug 31, 2020 7:04 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2681
Location: Germany
Why such an effort with CreateWindowEx?
The EditorGadget from PB is a RICHEDIT

Update
Code:
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  hWnd = EditorGadget(0, 8, 8, 306, 133)
  SetGadgetText(0, "I Like Purebasic!")
 
  Class.s = Space(512)
  GetClassName_(GadgetID(0), @Class, 512)
  Debug Class
 
  SendMessage_(hWnd, #EM_SETBKGNDCOLOR, 0, $000000)
 
  cf.CHARFORMAT
  cf\cbSize = SizeOf(CHARFORMAT)
 
  Red = 0
  Green = 255
  Blue = 0
  cf\crTextColor = RGB(red, Green, Blue)
 
  FontFace.s = "Courier New"
  PokeS(@cf\szFaceName, FontFace, 32)
 
  cf\dwMask =#CFM_COLOR|#CFM_FACE
  SendMessage_(hWnd, #EM_SETCHARFORMAT, #SCF_ALL, @cf)
 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Aug 31, 2020 8:10 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 09, 2011 9:36 am
Posts: 535
you could do something like this too :

Code:
Dim h.s(10)
h(0) = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033"  ;<<--- Code 1033 = Default Language = English USA
h(0) + "{\fonttbl{\f1\fnil\fcharset0 Arial;}{\f2\fnil\fcharset0 Consolas;}{\f3\fnil\fcharset0 Courier New;}"  ;<<--- Font Names Table
h(0) + "{\f4\fnil\fcharset0 Tahoma;}{\f5\fnil\fcharset0 Trebuchet MS;}{\f6\fnil\fcharset0 Verdana;}}"         ;<<--- Font Names Table
h(0) + "{\colortbl ;\red0\green0\blue180;\red0\green0\blue0;\red0\green90\blue0;"    ;<<--- Font Color Table
h(0) + "\red255\green255\blue0;\red240\green240\blue240;\red242\green246\blue252;\red0\green0\blue80;}"  ;<<--- Font Color Table
h(0) + "\viewkind4\uc1\pard"
h(0) + "\f6\fs18\b\cf1"  ;<<--- f6= Verdana   fs18= which is really FontSize= 9   \b = turn-on Bold text    \cf1 = use Colors= ;\red0\green0\blue180; = Blue RGB(0,0,180)
h(0)+"\par  I Like Purebasic !"

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 8, 8, 306, 133)
  ClearGadgetItems(0) : AddGadgetItem(0,-1,h(0)) ;<<--- the minus -1 trick sets cursor at very end of Help text
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf



 

_________________
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Aug 31, 2020 8:46 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2681
Location: Germany
Its some time old ...
Code:
;-TOP

; *****************************************************************************
; AddTextRTF by mk-soft, v1.05, 27.03.2018

CompilerIf #PB_Compiler_Version < 550
  Procedure Ascii(Text.s)
    Protected *mem = AllocateMemory(StringByteLength(Text, #PB_Ascii) + 1)
    If *mem
      PokeS(*mem, Text, -1, #PB_Ascii)
    EndIf
    ProcedureReturn *mem
  EndProcedure
  Procedure UTF8(Text.s)
    Protected *mem = AllocateMemory(StringByteLength(Text, #PB_UTF8) + 1)
    If *mem
      PokeS(*mem, Text, -1, #PB_UTF8)
    EndIf
    ProcedureReturn *mem
  EndProcedure
CompilerEndIf

Procedure AddTextRTF(Gadget, Text.s , NewLine=#False)
  If Left(Text, 5) <> "{\rtf"
    Text = "{\rtf " + Text + "}"
  EndIf
  If NewLine
    Text = Left(Text, Len(text) - 1) + "\line}"
  EndIf
  CompilerIf #PB_Compiler_Unicode
    Protected hEdit = GadgetID(Gadget)
    Protected ndx = GetWindowTextLength_(hEdit)
    Protected *szBuffer = Ascii(Text)
    SendMessage_(hEdit, #EM_SETSEL, ndx, ndx)
    SendMessage_(hEdit, #EM_REPLACESEL, 0, *szBuffer)
    FreeMemory(*szBuffer)
  CompilerElse
    AddGadgetItem(Gadget, -1 , Text)
  CompilerEndIf
EndProcedure

; *****************************************************************************

If OpenWindow(0, 0, 0, 540, 260, "PB 5.70 LTS Richedit Unicode EditorGadget", #PB_Window_SystemMenu |  #PB_Window_ScreenCentered)
  EditorGadget(0, 5, 5, 530, 250)
 
  Global Notiz$
  Global a$ = ""
 
  a$ + "{\rtf1\ansi\ansicpg1252\deff0\deflang1031\deflangfe1031{\fonttbl{\f0\fswiss\fprq2\fcharset0 Verdana;}{\f1\fswiss\fprq2\fcharset0 Segoe WP SemiLight;}}"
  a$ + "{\colortbl ;\red0\green128\blue128;\red51\green51\blue51;}"
  a$ + "{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\nowidctlpar\cf1\f0\fs20 So kennen wir den \'84Riverdale\ldblquote -Star gar nicht. \cf2\f1 (was so viel wie \'84Baumwollburg\ldblquote  bedeutet)\cf1\f0\par"
  a$ + "\cf1\ul\b\i\fs28 APPNAME é à ç è ê @ €"
  a$ + "}"
 
  AddTextRTF(0, a$)
 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Aug 31, 2020 9:30 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
thanks
Quote:
Why such an effort with CreateWindowEx?

yes mk-soft ,i don't know that is such a problematic
your Debug window show richedit20A class hmm that nigh be a problem
but i am not sure...
anyway work fine...


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Aug 31, 2020 9:41 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2681
Location: Germany
No Problem ...

On PB with Unicode Mode is the Class 'RichEdit20W' and with PB ASCII Mode is the Class 'RichEdit20A'

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Tue Sep 01, 2020 1:07 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1034
mk-soft, how would I apply a font (and/or style) or color just to the selected text in an EditorGadget?


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Tue Sep 01, 2020 8:58 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4963
Location: Germany
Ups ... mixed Scintilla with RichText


Last edited by infratec on Tue Sep 01, 2020 8:59 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Tue Sep 01, 2020 8:59 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 24, 2012 10:19 am
Posts: 196
From Freak, Hroudtwolf and srod, somewhere in this forum:

Code:
;Some useful functions for formatting text and paragraphs within EditorGadgets.
;By Freak.
;Additions by Hroudtwolf and srod.


;Future proof!
CompilerIf Defined(ENM_LINK, #PB_Constant)
CompilerElse
  #ENM_LINK = $04000000
CompilerEndIf
CompilerIf Defined(CFM_LINK, #PB_Constant)
CompilerElse
  #CFM_LINK = $00000020
CompilerEndIf
CompilerIf Defined(CFE_LINK, #PB_Constant)
CompilerElse
  #CFE_LINK = $0020
CompilerEndIf
CompilerIf Defined(CFE_SUBSCRIPT, #PB_Constant)
CompilerElse
  #CFE_SUBSCRIPT = $00010000
CompilerEndIf
CompilerIf Defined(CFE_SUPERSCRIPT, #PB_Constant)
CompilerElse
  #CFE_SUPERSCRIPT = $00020000
CompilerEndIf
CompilerIf Defined(CFM_SUBSCRIPT, #PB_Constant)
CompilerElse
  #CFM_SUBSCRIPT = #CFE_SUBSCRIPT | #CFE_SUPERSCRIPT
  #CFM_SUPERSCRIPT=#CFM_SUBSCRIPT
CompilerEndIf
CompilerIf Defined(CFM_BACKCOLOR, #PB_Constant)
CompilerElse
  #CFM_BACKCOLOR =$4000000
CompilerEndIf


;-Declares.
Declare Editor_BackColor(Gadget, Color.l)
Declare Editor_Color(Gadget, Color.l)
Declare Editor_Font(Gadget, FontName.s)
Declare Editor_FontSize(Gadget, Fontsize.l)
Declare Editor_Format(Gadget, flags, alternate=0)
Declare Editor_Select(Gadget, LineStart.l, CharStart.l, LineEnd.l, CharEnd.l)   
Declare Editor_Bulleted(Gadget)
Declare Editor_JustifyParagraph(Gadget, justify)
Declare Editor_CopyText(gadget)
Declare Editor_CutText(gadget)
Declare Editor_InsertText(gadget,Text$)
Declare Editor_PasteText(gadget)
Declare.l Editor_LoadRTF(gadget, filename.s, replaceall=0)
Declare.l StreamFileInCallback(dwCookie, pbBuff, cb, pcb)
Declare.l Editor_SaveRTF(gadget, filename.s)
Declare.l StreamFileOutCallback(dwCookie, pbBuff, cb, pcb)


;-----------------------------------------------Character formatting.
Procedure Editor_BackColor(Gadget, Color.l)
  format.CHARFORMAT2
  format\cbSize = SizeOf(CHARFORMAT2)
  format\dwMask = #CFM_BACKCOLOR
  format\crBackColor = Color
  SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
EndProcedure

; Set the Text color for the Selection
; in RGB format
Procedure Editor_Color(Gadget, Color.l)
  format.CHARFORMAT2
  format\cbSize = SizeOf(CHARFORMAT2)
  format\dwMask = #CFM_COLOR
  format\crTextColor = Color
  SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
EndProcedure

; Set Font for the Selection
; You must specify a font name, the font doesn't need
; to be loaded
Procedure Editor_Font(Gadget, FontName.s)
  format.CHARFORMAT2
  format\cbSize = SizeOf(CHARFORMAT2)
  format\dwMask = #CFM_FACE
  PokeS(@format\szFaceName, FontName)
  SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
EndProcedure

; Set Font Size for the Selection
; in pt
Procedure Editor_FontSize(Gadget, Fontsize.l)
  format.CHARFORMAT2
  format\cbSize = SizeOf(CHARFORMAT2)
  format\dwMask = #CFM_SIZE
  format\yHeight = FontSize*20
  SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
EndProcedure

; Set Format of the Selection. This can be a combination of
; the following values:
; #CFE_BOLD
; #CFE_ITALIC
; #CFE_UNDERLINE
; #CFE_STRIKEOUT
; #CFE_LINK
; #CFE_SUBSCRIPT
; #CFE_SUPERSCRIPT
;If the optional parameter 'alternate' is non-zero then the formatting attributes specified in
;'flags' will be xored with those already present within the first character of the selection.
;This has the effect of removing individual attributes if already present.
;E.g. specifying #CFE_BOLD on an already bold selection, will remove the bold formatting etc.
Procedure Editor_Format(Gadget, flags, alternate=0)
  format.CHARFORMAT2
  format\cbSize = SizeOf(CHARFORMAT2)
  If alternate
    SendMessage_(GadgetID(Gadget), #EM_GETCHARFORMAT, 1, @format)
    flags=format\dwEffects!flags
  EndIf
  format\dwMask = #CFM_ITALIC|#CFM_BOLD|#CFM_STRIKEOUT|#CFM_UNDERLINE|#CFM_LINK|#CFM_SUBSCRIPT|#CFM_SUPERSCRIPT
  format\dwEffects = flags
  SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
EndProcedure

; Selects Text inside an EditorGadget
; Line numbers range from 0 to CountGadgetItems(#Gadget)-1
; Char numbers range from 1 to the length of a line
; Set Line numbers to -1 to indicate the last line, and Char
; numbers to -1 to indicate the end of a line
; selecting from 0,1 to -1, -1 selects all.
Procedure Editor_Select(Gadget, LineStart.l, CharStart.l, LineEnd.l, CharEnd.l)   
  sel.CHARRANGE
  sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, LineStart, 0) + CharStart - 1
 
  If LineEnd = -1
    LineEnd = SendMessage_(GadgetID(Gadget), #EM_GETLINECOUNT, 0, 0)-1
  EndIf
  sel\cpMax = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, LineEnd, 0)
 
  If CharEnd = -1
    sel\cpMax + SendMessage_(GadgetID(Gadget), #EM_LINELENGTH, sel\cpMax, 0)
  Else
    sel\cpMax + CharEnd - 1
  EndIf
  SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel)
EndProcedure


;-----------------------------------------------Paragraph formatting.
Procedure Editor_Bulleted(Gadget)
  format.PARAFORMAT
  format\cbSize = SizeOf(PARAFORMAT)
  format\dwMask = #PFM_NUMBERING   
  format\wnumbering = #PFN_BULLET
  SendMessage_(GadgetID(Gadget), #EM_SETPARAFORMAT, 0, @format)
EndProcedure

;Set paragraph justification.
;Can be one of the following values:
; #PFA_LEFT   
; #PFA_RIGHT   
; #PFA_CENTER   
Procedure Editor_JustifyParagraph(Gadget, justify)
  format.PARAFORMAT
  format\cbSize = SizeOf(PARAFORMAT)
  format\dwMask = #PFM_ALIGNMENT
  format\wAlignment = justify
  SendMessage_(GadgetID(Gadget), #EM_SETPARAFORMAT, 0, @format)
EndProcedure


;-----------------------------------------------Clipboard.
Procedure  Editor_CopyText(gadget)
  SendMessage_(GadgetID(gadget), #WM_COPY,0,0)   
EndProcedure

Procedure  Editor_CutText(gadget)
  SendMessage_(GadgetID(gadget), #WM_CUT,0,0)   
EndProcedure

Procedure Editor_InsertText(gadget,Text$)
  ProcedureReturn SendMessage_(GadgetID(gadget),#EM_REPLACESEL,0,Text$)
EndProcedure

Procedure  Editor_PasteText(gadget)
  SendMessage_(GadgetID(gadget), #WM_PASTE,0,0)   
EndProcedure


;-----------------------------------------------Streaming.

;***********************************************************************************************
;The following procedure loads an rtf file into an editor gadget.
;Returns zero if no error encountered.
;***********************************************************************************************
;The optional parameter 'replaceall' can be set to #SFF_SELECTION to replace the current selection only.
Procedure.l Editor_LoadRTF(gadget, filename.s, replaceall=0)
  Protected edstr.EDITSTREAM
  edstr\dwCookie = ReadFile(#PB_Any, filename)
  If edstr\dwCookie
    edstr\dwError = 0
    edstr\pfnCallback = @StreamFileInCallback()
    SendMessage_(GadgetID(gadget), #EM_STREAMIN, #SF_RTF|replaceall, edstr)
    CloseFile(edstr\dwCookie)
    ProcedureReturn edstr\dwError
  Else
    ProcedureReturn 1
  EndIf
EndProcedure
;The following is called repeatedly by Windows to stream data into an editor gadget from an external file.
Procedure.l StreamFileInCallback(dwCookie, pbBuff, cb, pcb)
  Protected result, length
  result=0
  length=ReadData(dwCookie, pbBuff, cb)
  PokeL(pcb, length)
  If length = 0
    result = 1
  EndIf
  ProcedureReturn result
EndProcedure


;***********************************************************************************************
;The following procedure saves the rtf content of an editor gadget to an external file.
;Returns zero if no error encountered.
;***********************************************************************************************
Procedure.l Editor_SaveRTF(gadget, filename.s)
  Protected edstr.EDITSTREAM
  edstr\dwCookie = CreateFile(#PB_Any, filename)
  If edstr\dwCookie
    edstr\dwError = 0
    edstr\pfnCallback = @StreamFileOutCallback()
    SendMessage_(GadgetID(gadget), #EM_STREAMOUT, #SF_RTF, edstr)
    CloseFile(edstr\dwCookie)
    ProcedureReturn edstr\dwError
  Else
    ProcedureReturn 1
  EndIf
EndProcedure
;The following is called repeatedly by Windows to stream data from an editor gadget to an external file.
Procedure.l StreamFileOutCallback(dwCookie, pbBuff, cb, pcb)
  Protected result, length
  result=0
  WriteData(dwCookie, pbBuff, cb)
  PokeL(pcb, cb)
  If cb = 0
    result = 1
  EndIf
  ProcedureReturn result
EndProcedure

; -------------------------------------------------------------
; Source Example:


#Editor = 1

If OpenWindow(0, 0, 0, 600, 500, "",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ;   If CreateGadgetList(WindowID(0))
 
  EditorGadget(#Editor, 10, 10, 580, 480)
  AddGadgetItem(#Editor, 0, "This is a blue, bold and underlined big text")     
  AddGadgetItem(#Editor, 1, "Times new Roman, background red, striked out and italic")   
  AddGadgetItem(#Editor, 2, "LINK")   
  AddGadgetItem(#Editor, 3, "This issubscript")
  AddGadgetItem(#Editor, 4, "This issuperscript")
  AddGadgetItem(#Editor, 5, "Bulleted 1")
  AddGadgetItem(#Editor, 6, "Bulleted 2")
 
  ;The following line temporarily hides the selection whilst we format the text,
  SendMessage_(GadgetID(#Editor),#EM_HIDESELECTION,1,0)
 
  Editor_Select(#Editor, 0, 1, 0, -1)  ; select line 1
  Editor_Color(#Editor, RGB(0,0,255))
  Editor_FontSize(#Editor, 28)
  Editor_Format(#Editor, #CFE_BOLD|#CFE_ITALIC)
  ;      Editor_Format(#Editor, #CFE_ITALIC,1)
 
 
  Editor_Select(#Editor, 1, 1, 1, -1)  ; select line 2
  Editor_Font(#Editor, "Times New Roman")
  Editor_Format(#Editor, #CFE_ITALIC|#CFE_STRIKEOUT)
  Editor_Backcolor(#Editor, #Red)
  Editor_JustifyParagraph(#Editor,#PFA_CENTER)
 
  Editor_Select(#Editor, 2, 1, 2, -1)  ; select line 2
  Editor_Format(#Editor, #CFE_LINK)
  ;      Editor_Format(#Editor, #CFE_LINK,1)
 
  Editor_Select(#Editor, 3, 8, 3, -1)
  Editor_Format(#Editor, #CFE_SUBSCRIPT|#CFE_BOLD)
 
  Editor_Select(#Editor, 4, 8, 4, -1)
  Editor_Format(#Editor, #CFE_SUPERSCRIPT|#CFE_BOLD)
 
  Editor_Select(#Editor, 5, 1, 6, -1)
  Editor_Bulleted(#Editor)
 
  Editor_Select(#Editor, 0, 0, 0, 0)   ; select nothing again
 
  SendMessage_(GadgetID(#Editor),#EM_HIDESELECTION,0,0)
 
  ;Uncomment the following to save the contents of the editor gadget in rich text format.
  ;Editor_SaveRTF(#Editor, "c:\test.rtf")
 
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
  ;   EndIf
EndIf

End


M.


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Tue Sep 01, 2020 7:52 pm 
Offline
User
User
User avatar

Joined: Wed Nov 18, 2009 11:18 pm
Posts: 49
I see in procedure is used different type of CHARFORMAT structure
called CHARFORMAT2
what is a difference?
Is here anyone who have code for both structure ?
what is a value of constant CFM_COLOR ?
and what is constant SCF_ALL ?


Top
 Profile  
Reply with quote  
 Post subject: Re: RichEdit not visible(syntax coloring) ?
PostPosted: Mon Sep 07, 2020 4:27 pm 
Offline
User
User

Joined: Tue Dec 31, 2013 9:18 pm
Posts: 21
There are several issues with the posted code, some are trivial others are major.

1. The constants #MainWindow and #WINDOW_PARAMETERS have not been used. They could be incorporated into the OpenWindow() instruction as follows:

Code:
If OpenWindow(#MainWindow, 100, 200, 500, 500, "PureBasic Window", #WINDOW_PARAMETERS)


2. The following line assumes that the loaded library is "riched32.dll"; however, the loaded library could have been "RICHED20.DLL"; if so, then the code that sets up hWnd will fail:

Code:
hWnd = CreateWindowEx_(#WS_EX_CLIENTEDGE, "riched32.dll", "This will With SetWindowText.", 1412518084 , 10, 10, 300, 300, 1, 100, 0, 0)


Replace this line with:

Code:
hWnd = CreateWindowEx_(#WS_EX_CLIENTEDGE,RichClass,"This will With SetWindowText.",#RICHEDIT, 10, 10, 400, 400, WindowID(#MainWindow), 0, GetModuleHandle_(0), 0)


This incorporates the constant #RICHEDIT that was not used in the original code.

3. The code does not try to load the latest rich text control that is available in Windows 10 in the library "MSFTEDIT.dll". Change the section that loads the library to:

Code:
  If  LoadLibrary_("MSFTEDIT.dll")
    RichClass.s = "RichEdit50W"
  ElseIf LoadLibrary_("RICHED20.DLL")
    RichClass.s = "RichEdit20A"
  ElseIf LoadLibrary_("RICHED32.DLL")
    RichClass.s = "RichEdit"
  Else
    MessageRequester("Error", "RichEdit Windows library not present.", 0)
    End
  EndIf
 


This will try to load the latest dll with the rich text control; if this is not found it tries to load the next version etc.

4. There is not a close button in the code:

Code:
If Event = #WM_CLOSE  ; If the user has pressed on the close button


Replace the Repeat loop with:
Code:
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Quit=#True
      EndSelect
    Until Quit=#True


Here is a corrected version of the posted code:

Code:
#RICHEDIT = #WS_CHILD|#WS_VISIBLE|#WS_VSCROLL|#ES_MULTILINE|#ES_AUTOVSCROLL|#ES_NOHIDESEL
#SCF_ALL = 4
#SCF_SELECTION = $0001
#SCF_WORD = $0002
#MainWindow = 1
#WINDOW_PARAMETERS = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget
;#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget
If OpenWindow(#MainWindow, 100, 200, 500, 500, "PureBasic Window", #WINDOW_PARAMETERS)
 
  If  LoadLibrary_("MSFTEDIT.dll")
    RichClass.s = "RichEdit50W"
  ElseIf LoadLibrary_("RICHED20.DLL")
    RichClass.s = "RichEdit20A"
  ElseIf LoadLibrary_("RICHED32.DLL")
    RichClass.s = "RichEdit"
  Else
    MessageRequester("Error", "RichEdit Windows library not present.", 0)
    End
  EndIf
 
  Debug RichClass ;See which class loaded
 
  hWnd = CreateWindowEx_(#WS_EX_CLIENTEDGE,RichClass,"This will With SetWindowText.",#RICHEDIT, 10, 10, 400, 400, WindowID(#MainWindow), 0, GetModuleHandle_(0), 0)
 
  If hWnd <> 0
    ShowWindow_(hWnd, #SW_HIDE) ; hide our changes to the user
    SetWindowText_(hWnd, "Hi everybody!")
    BGR = 0
    SendMessage_(hWnd, #EM_SETBKGNDCOLOR, 0, BGR) ; BGR value = black
    cf.CHARFORMAT
    cf\cbSize = SizeOf(CHARFORMAT)
    Red = 0
    Green = 255
    Blue = 0
    BGR = (Blue*65536)|(Green*256)|Red
    cf\crTextColor = BGR ; BGR value = green
    FontFace.s = "Courier New"
    For t = 0 To Len(FontFace)
      cf\szFaceName[t] = Asc(Mid(FontFace, t+1, 1))
    Next t
    cf\dwMask =#CFM_COLOR|#CFM_FACE
    SendMessage_(hWnd, #EM_SETCHARFORMAT, #SCF_ALL, @cf)
    ShowWindow_(hWnd, #SW_SHOW) ; now show
    SetForegroundWindow_(1)
  EndIf
 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit=#True
    EndSelect
  Until Quit=#True
 
EndIf
End


mk-soft wrote:
Why such an effort with CreateWindowEx?
The EditorGadget from PB is a RICHEDIT


As far as I can tell, the EditorGadget in PB does not seem to use the library "MSFTEDIT.dll" that is available in Windows 10. Consequently some of the latest functions for the rich text control are not available in PB (Of course, this does not matter if the latest functions are not needed for an application). Fortunately PB is very adaptable so the latest library can be loaded using CreateWindowEx.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 37 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye