Changing the print font (SIZE) on a MFC Dialog app.

Background info:
I have created a dialog application and in the application the user has an option to print.  I have created a button on the dialog that when double clicked, the function for printing some text info will be printed.  In the function for printing I want to change the font-Size, type, etc. but i am having problems with changing the font. The text will print out to the HP laser 4 printer,but regardless of what font type I create using CFont.Create,  the
font never changes.  

MY QUESTION:

How do I change the font in a dialog application using CFont and CDC since their is no CView class or OnDraw(CDC* pDC) function.

Thanks,

ARG1
arg1Asked:
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.

chensuCommented:
You need to select the font object into the printer DC before printing.

CFont MyFont;
MyFont.CreatePointFont(160, _T("Arial"), &PrinterDC);

CFont *pOldFont = PrinterDC.SelectObject(&MyFont);

// PrinterDC.TextOut ...

PrinterDC.SelectObject(pOldFont);
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
arg1Author Commented:
Hello Chensu,

Here is a copy of my printing code.
It will print to the default printer, but the font will not change.  Take a look and let me know what you think.  My system is a win95 box.

Thanks,

ARG1

void CTestDlg::OnDoubleclickedButton1()
{
      
      CPrintDialog dlg(FALSE);//Creates a print dialog box
            
      CFont* pOldFont;
      CFont Cfont;
      CSize pagesize;
      CDC PrintDC;// printer device context
      DOCINFO info;//structure for the descriptive name of document to be printed
      BOOL value;
      
        memset(&info,0,sizeof(info));
        info.cbSize=sizeof(info);//The size, in bytes, of the stream or byte array.
        info.lpszDocName=_T("Test Report");//document name

            // Retrieve the current printer defaults from the Windows .ini file
    // as necessary, or uses the last printer configuration set by the
   // user in Print Setup.
   CWinApp* app = AfxGetApp();
   if (!app->GetPrinterDeviceDefaults(&dlg.m_pd))
    {
    // Fails to create a printer device context for printing because
    // no printer is being installed. Bring up dialog box to alert the
    // users that they need to install a printer.  This step is optional.
    if (app->DoPrintDialog(&dlg) != IDOK)
       return ;
    }

    // Creates a printer DC from the DEVMODE and DEVNAMES structures.
    if (dlg.CreatePrinterDC() == NULL) return ;

    //value=Cfont.CreateFont(-120,0,0,0,FW_NORMAL,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,"Arial");
      //ASSERT(value);
      PrintDC.Attach(dlg.m_pd.hDC);//Obtain print device context
      
      Cfont.CreatePointFont(160,_T("Arial"),&PrintDC);
      pOldFont=PrintDC.SelectObject(&Cfont);
      
      //pagesize.cx=PrintDC.GetDeviceCaps(PHYSICALWIDTH);//RETURNS PRINTER PAGEWIDTH IN PIXELS
      //pagesize.cy=PrintDC.GetDeviceCaps(PHYSICALHEIGHT);//RETURNS PRINTER PAGE HEIGHT IN PIXELS
      PrintDC.StartDoc(&info);
      PrintDC.StartPage();
      
      PrintDC.TextOut(100,500,_T("FOOG"),4);
      
      PrintDC.EndPage();
      PrintDC.EndDoc();
      PrintDC.SelectObject(pOldFont);
      

}
0
chensuCommented:
Put SelectObject right before TextOut because StartPage resets the attributes of the DC.

PrintDC.StartPage();

pOldFont=PrintDC.SelectObject(&Cfont);
PrintDC.TextOut(100,500,_T("FOOG"),4);
PrintDC.SelectObject(pOldFont);

PrintDC.EndPage();
0
arg1Author Commented:
YOU ARE A GDI GURU,

Thanks for the insight.  I suspected the attributes, but I just did not look.  

Thanks again,

ARG1
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.