CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Posts
    2

    Printing problem: Changing font ??

    I want to send a line of text to the printer, and have made the function found below.
    and the text is send to the printer, but with the same font no mater what I put into
    CreateFont(). I think that it is the same font as notepad in windows uses. But I need
    to change the font and I need to change the size of the font, What will I have to do this ?
    What am I missing here ?

    Hope someone can help me !



    void MyClass::PrintLine()
    {

    CPrintDialog pd(FALSE);
    DOCINFO di;

    memset(&di, 0, sizeof(DOCINFO));
    di.cbSize = sizeof(DOCINFO);
    di.lpszDocName = "Title";


    pd.GetDefaults();


    DEVMODE *dm = pd.GetDevMode();


    CDC dc;
    if(! dc.CreateDC(pd.GetDriverName(), pd.GetDeviceName(),
    pd.GetPortName(), dm))
    {
    AfxMessageBox(_T("Can't create DC "));

    }


    dc.StartDoc(&di);

    CFont *oldfont;

    CFont xFont;

    dc.SetMapMode(MM_TEXT);
    xFont.CreateFont(8, //height
    0, // width
    0, // escapement
    0, //orientation
    400, //weight
    FALSE, //italic
    FALSE, //underline
    0, //strikeout
    ANSI_CHARSET,
    OUT_DEVICE_PRECIS,
    CLIP_DEFAULT_PRECIS,
    DEFAULT_QUALITY,
    DEFAULT_PITCH,
    _T("Courier New"));

    oldfont=dc.SelectObject(&xFont);

    TEXTMETRIC tm;
    dc.GetTextMetrics(&tm);

    int Height= tm.tmHeight + tm.tmExternalLeading;

    CPrintInfo Info;
    int w = dc.GetDeviceCaps(HORZRES);
    int h = dc.GetDeviceCaps(VERTRES);
    Info.m_rectDraw.SetRect(0,0, w, h);


    OnBeginPrinting(&dc, &Info);


    dc.StartPage();

    dc.TextOut(0, Height*2, "This is a printer test...");

    dc.SelectObject(oldfont);

    dc.EndPage();
    dc.EndDoc();
    dc.DeleteDC();


    }



    Thanks for your help !

    Thomas





  2. #2
    Guest

    Re: Printing problem: Changing font ??

    You must select the font after dc.StartPage()

    HIH.

    Bill.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured