PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: WinFBE RichEdit  (Read 260 times)

jermy

  • Little Newbie
  • *
  • Posts: 44
WinFBE RichEdit
« on: January 12, 2020, 12:53:59 PM »

Hello people,

how can I change the text color in a RichEdit control?


Code: [Select]

With frmMain.RichEdit1
            .SelectionStart = 0
            .SelectionLength = 5
          '  .SelectionColor = RGB(0, 0, 255) ' Blue ???
End with


Maybe it's not built in yet ?, can I do it in a different way?
Logged
Josť & Paul thanks for WinFBE.

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9203
  • Windows 10
    • PlanetSquires Software
Re: WinFBE RichEdit
« Reply #1 on: January 12, 2020, 03:42:32 PM »

I have a program where I need to set the color/font of certain RTF text. Here is the generic code that I use:

rtfText( hEdit, wszText, wszFontName, nFontSize, CFE_BOLD, colors.Black )

Code: [Select]
' ========================================================================================
' rtfText
' General purpose routine to set the font, size, effect, color for text to be entered.
' ========================================================================================
function rtfText( byval hEdit as HWND, _
                  byval wszText as CWSTR, _
                  byval wszFontName as CWSTR, _
                  byval nFontSize as long, _
                  byval nFontEffect as long = 0, _
                  byval nFontColor as COLORREF = 0 _
                  ) as Long
                 
   dim hDC AS HDC
   dim lRet AS LONG
   dim cf AS CHARFORMAT2
   DIM tlf AS LOGFONTW
   
   dim stex as SETTEXTEX
   stex.flags = ST_SELECTION or ST_UNICODE

   hDC = GetDC(NULL)
   EnumFontFamiliesW( hDC, byval wszFontName, cast(FONTENUMPROCW, @RichEdit_EnumFontFamProcW), cast(LPARAM, @tlf) )
   ReleaseDC NULL, hDC

   cf.cbsize = sizeof(cf)
   cf.dwMask = CFM_FACE OR CFM_CHARSET or CFM_SIZE or _
               CFM_BOLD OR CFM_ITALIC OR CFM_UNDERLINE OR CFM_STRIKEOUT or _
               CFM_COLOR
   cf.szFaceName      = tlf.lfFaceName
   cf.bCharSet        = tlf.lfCharSet
   cf.bPitchAndFamily = tlf.lfPitchAndFamily
   cf.yHeight         = nFontSize * 20
   cf.dwEffects       = nFontEffect
   cf.crTextColor     = nFontColor
   
   SendMessage( hEdit, EM_SETCHARFORMAT, SCF_SELECTION, cast(LPARAM, @cf) )
   RichEdit_SetTextExW( hEdit, @stex, wszText )
   
   function = 0
end function
 
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

jermy

  • Little Newbie
  • *
  • Posts: 44
Re: WinFBE RichEdit
« Reply #2 on: January 13, 2020, 01:31:36 PM »

thanks Paul,

now i can move forward again.
Perhaps it is useful to add the function to WinFBE
Logged
Josť & Paul thanks for WinFBE.