Bold Courier in RichEditControl

I am trying to bold a line of courier text in a CRichEditCntl.  In essence:

CHARFORMAT2A CharFmt;
...
strcpy(CharFmt,"Courier");
CharFmt.dwMask=CFM_BOLD;
charFmt.DWEffects=CFE_BOLD;
SetCharFormat(CharFmt);
ReplaceSel("something");

It does not change to bold at all.  I also tried wWeight, but that didn't work either.

Any suggestions will be appreciated.
rickhill11Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
>> In essence:

Please post the real code.  (Often the fictional code to duplicate some bug actually has the bug removed - because one doesn't know where the bug is).
0
rickhill11Author Commented:
Per your request.  Everything works exactly as I want except that what I call the "Ruler Line" refuses my reasonable requests to print in bold.  See //ruler below


void CParseHotelFileRTFView::CreateOutput(void)
{
      CRichEditCtrl &pCREC=GetRichEditCtrl();
      PARAFORMAT2 ParaFormat;
      CHARFORMAT2A CharFormat;

      GetDocument()->SetTitle(m_csInputFile);
      pCREC.SetReadOnly();

      //Get the default format
      pCREC.GetDefaultCharFormat(CharFormat);
      CharFormat.cbSize=sizeof(CHARFORMAT);

      //Set default format
      CharFormat.yHeight=200;
      strcpy(CharFormat.szFaceName,"Courier");
      pCREC.SetDefaultCharFormat(CharFormat);


      //Set the format for the header
      CharFormat.yHeight=1500;
      strcpy(CharFormat.szFaceName,"Times New Roman");
      ParaFormat.cbSize=sizeof(PARAFORMAT);
      ParaFormat.dwMask=PFM_ALIGNMENT;
      ParaFormat.wAlignment=PFA_CENTER;
      CharFormat.dwMask=CFM_ALL|CFM_BOLD;
      SetParaFormat(ParaFormat);
      SetCharFormat(CharFormat);
      pCREC.ReplaceSel("Hotel File\n");

      //Make "Disclaimer" slightly larger
      CharFormat.yHeight=400;
      CharFormat.dwEffects=CFE_BOLD;
      ParaFormat.wAlignment=PFA_LEFT;
      SetCharFormat(CharFormat);
      SetParaFormat(ParaFormat);
      pCREC.ReplaceSel("Disclaimer: ");
      
      //Make the rest of the disclaimer statement closer to normal size
      CharFormat.yHeight=300;
      SetCharFormat(CharFormat);
      pCREC.ReplaceSel("Blah Blah Blah\n\n\n");


      //Print the ruler line, in bold
      strcpy(CharFormat.szFaceName,"Courier");
      CharFormat.dwMask=CFM_ALL|CFM_BOLD|CFM_WEIGHT;
      CharFormat.dwEffects=CFE_BOLD;
      CharFormat.wWeight=500;
      CharFormat.yHeight=200;
      SetCharFormat(CharFormat);
//ruler
//I WANT THIS NEXT LINE TO BE COURIER BOLD
      pCREC.ReplaceSel("HOTEL                ADDRESS                        PHONE\n\n");



//      pCREC.SetFont(&dfont);
      while(fgets(buffer,2000,m_fInput)){
            if(!strncmp(buffer,_T("***"),3))continue;
            if(buffer[0]=='*')break;  //no more hotels
            ParseFile(pCREC);
      }
0
rickhill11Author Commented:
So I did some more checking, and I guess that the BOLD is working.  I deliberately set bold for the header, disclaimer, and ruler, and thought that absent a SetCharFormat((), the font would return to the default format which is not bold.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

AndyAinscowFreelance programmer / ConsultantCommented:
>> the font would return to the default format which is not bold.

The documentation says: Only the attributes specified by the dwMask member of cf are changed by this function.  Which means that nothing is changed as you don't supply any parameters, the font stays as you last set it.

https://msdn.microsoft.com/en-us/library/windows/desktop/bb788026%28v=vs.85%29.aspx
You might want to get the font before you do anything so you can undo any changes at a later time.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rickhill11Author Commented:
I was correct that absent a SetCharFormat(0 statement, the format reverts to the default format.  However, It turns out that GetDefaultCharFormat() doesn't clear/set all the flags.  Somehow a BOLD flag was lurking either from my setting the flag to BOLD in individual statements, or and it not being overwritten when it reverted to default, or it was not set/cleared by GetDefaultFormat().  Either way, I was able to clear the BOLD flag with

CharFormat.dwMask=CFM_ALL;
CharFormat.dwEffect&=(!CFE_BOLD);

This made the default format return to normal.
0
AndyAinscowFreelance programmer / ConsultantCommented:
>>It turns out that GetDefaultCharFormat() doesn't clear/set all the flags   and   or it was not set/cleared by GetDefaultFormat()
They retrieve values, they do not set/change any flags.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.