Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using a selection

Using a selection

Scheduled Pinned Locked Moved C / C++ / MFC
c++
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    Hi. What MFC control should I use in order to put a text in such a way that some text should have different background color, and most important, there will be several selection in this text, all of them with the same background color ... I have tried with CRichEditView, and I could set a text color for several selection, but not color for background, only for text:

    SetWindowText(\_T("Havecreatedonecomboclasstogetthecomboboxhandleandlistboxhandlevalue"));
    
    CHARFORMAT cf;
    cf.cbSize = sizeof(cf);
    cf.dwMask = CFM\_BOLD | CFM\_COLOR;
    cf.dwEffects = CFE\_BOLD | ~CFE\_AUTOCOLOR;
    
    cf.crTextColor = RGB(0, 255, 0);
    GetRichEditCtrl().SetSel(2, 5);
    GetRichEditCtrl().SetSelectionCharFormat(cf);
    
    cf.crTextColor = RGB(250, 55, 33);
    GetRichEditCtrl().SetSel(10, 18);
    GetRichEditCtrl().SetSelectionCharFormat(cf);
    
    cf.crTextColor = RGB(250, 55, 33);
    GetRichEditCtrl().SetSel(10, 18);
    GetRichEditCtrl().SetSelectionCharFormat(cf);
    
    GetRichEditCtrl().SetSel(-1, -1);
    
    GetRichEditCtrl().SetReadOnly();
    
    V 1 Reply Last reply
    0
    • _ _Flaviu

      Hi. What MFC control should I use in order to put a text in such a way that some text should have different background color, and most important, there will be several selection in this text, all of them with the same background color ... I have tried with CRichEditView, and I could set a text color for several selection, but not color for background, only for text:

      SetWindowText(\_T("Havecreatedonecomboclasstogetthecomboboxhandleandlistboxhandlevalue"));
      
      CHARFORMAT cf;
      cf.cbSize = sizeof(cf);
      cf.dwMask = CFM\_BOLD | CFM\_COLOR;
      cf.dwEffects = CFE\_BOLD | ~CFE\_AUTOCOLOR;
      
      cf.crTextColor = RGB(0, 255, 0);
      GetRichEditCtrl().SetSel(2, 5);
      GetRichEditCtrl().SetSelectionCharFormat(cf);
      
      cf.crTextColor = RGB(250, 55, 33);
      GetRichEditCtrl().SetSel(10, 18);
      GetRichEditCtrl().SetSelectionCharFormat(cf);
      
      cf.crTextColor = RGB(250, 55, 33);
      GetRichEditCtrl().SetSel(10, 18);
      GetRichEditCtrl().SetSelectionCharFormat(cf);
      
      GetRichEditCtrl().SetSel(-1, -1);
      
      GetRichEditCtrl().SetReadOnly();
      
      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Did you try using [CHARFORMAT2W | Microsoft Docs](https://docs.microsoft.com/en-us/windows/desktop/api/richedit/ns-richedit-charformat2w)?

      _ 1 Reply Last reply
      0
      • V Victor Nijegorodov

        Did you try using [CHARFORMAT2W | Microsoft Docs](https://docs.microsoft.com/en-us/windows/desktop/api/richedit/ns-richedit-charformat2w)?

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        Yes, it goes. Here is the code, in case that everyone need it:

        CHARFORMAT2 cf;
        cf.cbSize = sizeof(cf);
        cf.dwMask = CFM\_BACKCOLOR | CFE\_AUTOCOLOR;
        cf.dwEffects = CFE\_PROTECTED;
        cf.crTextColor = RGB(64, 255, 33);
        cf.crBackColor = RGB(240, 64, 64);
        GetRichEditCtrl().SetSel(18, 28);
        GetRichEditCtrl().SetSelectionCharFormat(cf);
        
        GetRichEditCtrl().SetSel(-1, -1);
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups