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. Help!- Background color of Highlighted line in RichEditView

Help!- Background color of Highlighted line in RichEditView

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
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.
  • I Offline
    I Offline
    irshad_bukhari
    wrote on last edited by
    #1

    Hi I am new to MFC, i have written function to highlight a perticular line in richeditview class. find the routines below. But i am not able to change the background of a line (presently in black color). i am able to change the text color. I tried with CHARFORMAT2, but its not working. So plz help me out to solve this problem void CDbgView::HighlightLine(int GLineNum) { int FirstVisibleLineNum = pSCodeView->GetRichEditCtrl( ).GetFirstVisibleLine() + 1; int LastLine = FirstVisibleLineNum + pSCodeView->GetRichEditCtrl( ).GetLineCount(); int nBegin,nEnd; nBegin = pSCodeView->GetRichEditCtrl().LineIndex(GLineNum-1); End = pSCodeView->GetRichEditCtrl().LineLength(nBegin); // Select the range of charecters. CHARRANGE cr; pSCodeView->GetRichEditCtrl().GetSel(cr); cr.cpMin = nBegin; cr.cpMax = nBegin + nEnd; pSCodeView->GetRichEditCtrl().SetSel(cr); //Change the Bk Color of the line selected /*CHARFORMAT2 cf; pSCodeView->GetRichEditCtrl().GetSelectionCharFormat(cf); cf.cbSize = 84; CHARFORMAT2* pcf = &cf; pSCodeView->SendMessage(EM_SETCHARFORMAT,(WPARAM) SCF_ALL,(LPARAM) pcf); cf.dwMask = CFM_SIZE | CFM_BACKCOLOR ; cf.dwEffects = CFE_PROTECTED | CFM_COLOR | CFM_BACKCOLOR; cf.crBackColor = RGB(0,0,255); pSCodeView->GetRichEditCtrl().SetSelectionCharFormat(cf); */ pSCodeView->UpdateWindow( ); } Thanks Irshad

    G 1 Reply Last reply
    0
    • I irshad_bukhari

      Hi I am new to MFC, i have written function to highlight a perticular line in richeditview class. find the routines below. But i am not able to change the background of a line (presently in black color). i am able to change the text color. I tried with CHARFORMAT2, but its not working. So plz help me out to solve this problem void CDbgView::HighlightLine(int GLineNum) { int FirstVisibleLineNum = pSCodeView->GetRichEditCtrl( ).GetFirstVisibleLine() + 1; int LastLine = FirstVisibleLineNum + pSCodeView->GetRichEditCtrl( ).GetLineCount(); int nBegin,nEnd; nBegin = pSCodeView->GetRichEditCtrl().LineIndex(GLineNum-1); End = pSCodeView->GetRichEditCtrl().LineLength(nBegin); // Select the range of charecters. CHARRANGE cr; pSCodeView->GetRichEditCtrl().GetSel(cr); cr.cpMin = nBegin; cr.cpMax = nBegin + nEnd; pSCodeView->GetRichEditCtrl().SetSel(cr); //Change the Bk Color of the line selected /*CHARFORMAT2 cf; pSCodeView->GetRichEditCtrl().GetSelectionCharFormat(cf); cf.cbSize = 84; CHARFORMAT2* pcf = &cf; pSCodeView->SendMessage(EM_SETCHARFORMAT,(WPARAM) SCF_ALL,(LPARAM) pcf); cf.dwMask = CFM_SIZE | CFM_BACKCOLOR ; cf.dwEffects = CFE_PROTECTED | CFM_COLOR | CFM_BACKCOLOR; cf.crBackColor = RGB(0,0,255); pSCodeView->GetRichEditCtrl().SetSelectionCharFormat(cf); */ pSCodeView->UpdateWindow( ); } Thanks Irshad

      G Offline
      G Offline
      GermanGeorge
      wrote on last edited by
      #2

      i do it this way: void MyClass::SetBold(void) { CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_BOLD; DWORD dwSelMask = GetSelectionCharFormat(cf); if( (cf.dwMask & CFM_BOLD) & (dwSelMask & CFM_BOLD) ) { cf.dwEffects ^= CFE_BOLD; } else { cf.dwEffects |= CFE_BOLD; } cf.dwMask = CFM_BOLD; SetSelectionCharFormat(cf); }

      I 1 Reply Last reply
      0
      • G GermanGeorge

        i do it this way: void MyClass::SetBold(void) { CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_BOLD; DWORD dwSelMask = GetSelectionCharFormat(cf); if( (cf.dwMask & CFM_BOLD) & (dwSelMask & CFM_BOLD) ) { cf.dwEffects ^= CFE_BOLD; } else { cf.dwEffects |= CFE_BOLD; } cf.dwMask = CFM_BOLD; SetSelectionCharFormat(cf); }

        I Offline
        I Offline
        irshad_bukhari
        wrote on last edited by
        #3

        thanks for reply...but i want to change the background color of hightlighted line...presently it is black... so i tried to use CHARFORMAT2...but i am not able set the size attribute & i am not able send a massage for CHARFORMAT2 regards, Irshad

        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