Click here to Skip to main content
15,898,373 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Visual C++ Pin
Tomasz Sowinski2-Aug-01 1:30
Tomasz Sowinski2-Aug-01 1:30 
QuestionGDI+ from June SDK CD ??? Pin
Christian Graus1-Aug-01 20:08
protectorChristian Graus1-Aug-01 20:08 
AnswerRe: GDI+ from June SDK CD ??? Pin
Michael Dunn1-Aug-01 22:47
sitebuilderMichael Dunn1-Aug-01 22:47 
Questionget the MAC-adress from a host computer? Pin
Heidyon1-Aug-01 18:18
Heidyon1-Aug-01 18:18 
AnswerRe: get the MAC-adress from a host computer? Pin
Michael A. Barnhart2-Aug-01 0:43
Michael A. Barnhart2-Aug-01 0:43 
GeneralIt might be easier if somebody just shot me Pin
Michael Martin1-Aug-01 17:47
professionalMichael Martin1-Aug-01 17:47 
GeneralRe: It might be easier if somebody just shot me Pin
Shankar Chandra Bose1-Aug-01 18:01
Shankar Chandra Bose1-Aug-01 18:01 
GeneralRe: Font Changing Pin
Derek Lakin2-Aug-01 1:30
Derek Lakin2-Aug-01 1:30 
I haven't had chance to look at checking the text extent, but I think Shanker has helped there. The following example shows printing a title in centred, bold, 16 point, Times New Roman and then some other text left-aligned, 8 point, Courier New. The example is the message handler for a Print button on a dialog.

Hopefully this should help with your font problem Smile | :)

void CPrintTestDlg::OnButtonPrint() 
{
	// Ask the user which printer they want to use
	CPrintDialog dlg (FALSE);
	if (IDOK != dlg.DoModal())
		return;

	CWaitCursor wait; // Show a busy cursor while printing

	// Get the dialog to create a printer DC for this printer
	HDC printerDC = dlg.CreatePrinterDC();

	// Create a CDC connected to this HDC
	CDC	dc;
	dc.Attach( printerDC );

	// Determine the printable area of the page
	CPoint pt( GetDeviceCaps(dc.m_hDC, HORZRES),
			   GetDeviceCaps(dc.m_hDC, VERTRES) );
	dc.DPtoLP( &pt );
	CRect rectPage( 0, 0, pt.x, pt.y );

	// Create the document information
	CString strTitle = "Document Title";
	DOCINFO docInfo;
	docInfo.cbSize = sizeof(DOCINFO);
	docInfo.lpszDocName = strTitle; 
	docInfo.lpszOutput = 0; 
	docInfo.lpszDatatype = 0;

	// Start the doc and page
	dc.StartDoc( &docInfo );
	dc.StartPage( );

	// Print out some text in our chosen font
	int currentY = 0; // Maintain our current position down the page
	// Specify a LOGFONT for the font we require
	LOGFONT* pLogFont = new LOGFONT;
	pLogFont->lfCharSet = ANSI_CHARSET;
	pLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
	pLogFont->lfEscapement = 0;
	CString strFaceName = "Times New Roman"; // Change font name here to whatever you need
	lstrcpy (pLogFont->lfFaceName, strFaceName);
	// Calculation allows us to specify the font size in points
	pLogFont->lfHeight = -MulDiv (16, GetDeviceCaps (dc.m_hDC, LOGPIXELSY), 72); // 16 point font
	pLogFont->lfItalic = FALSE;
	pLogFont->lfOrientation = 0;
	pLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
	pLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	pLogFont->lfQuality = DEFAULT_QUALITY;
	pLogFont->lfStrikeOut = FALSE;
	pLogFont->lfUnderline = TRUE;
	pLogFont->lfWeight = FW_BOLD;
	pLogFont->lfWidth = 0;

	// Create and select the font
	CFont* pFont = new CFont;
	pFont->CreateFontIndirect( pLogFont );
	CFont* pOldFont = dc.SelectObject( pFont );
	// Centre alignment
	dc.SetTextAlign( TA_CENTER );
	dc.TextOut( rectPage.Width() / 2, rectPage.top, strTitle ); // Display title line
	// Update our position down the page
	currentY += abs (pLogFont->lfHeight);

	// Change the font for the rest of the text
	dc.SelectObject (pOldFont);
	pFont->DeleteObject ();
	delete pFont;
	pFont = new CFont;
	// Update the LOGFONT
	pLogFont->lfHeight = -MulDiv (8, GetDeviceCaps (dc.m_hDC, LOGPIXELSY), 72); // 16 point font
	pLogFont->lfUnderline = FALSE;
	pLogFont->lfWeight = FW_NORMAL;
	// Change the font
	strFaceName = "Courier New";
	lstrcpy (pLogFont->lfFaceName, strFaceName);
	pFont->CreateFontIndirect( pLogFont );
	pOldFont = dc.SelectObject( pFont );
	// Add space for a blank line
	currentY += abs (pLogFont->lfHeight);
	// Change the alignment to left
	dc.SetTextAlign( TA_LEFT );
	CString strText = "Some text to output.";
	dc.TextOut (0, currentY, strText);
	
	// Print a bounding rectangle - not essential but can help when debugging
	dc.SelectObject( ::GetStockObject(NULL_BRUSH) );
	dc.Rectangle( rectPage );

	// End the page and then the doc - this will spool it to the printer
	dc.EndPage();
	dc.EndDoc();

	// And cleanup
	delete pLogFont;
	delete pFont;
	dc.Detach();
	DeleteDC( printerDC );  
}


If you need any more help let me know and I'll see what I can do.

Derek.
Generala simple question Pin
1-Aug-01 17:27
suss1-Aug-01 17:27 
GeneralRe: a simple question Pin
Matt.W.1-Aug-01 18:00
Matt.W.1-Aug-01 18:00 
GeneralXalan transform problem in VC Pin
Michael A. Barnhart1-Aug-01 17:09
Michael A. Barnhart1-Aug-01 17:09 
GeneralRe: Xalan transform problem in VC Pin
Michael A Barnhart2-Aug-01 7:51
Michael A Barnhart2-Aug-01 7:51 
GeneralSo, how good are you? ;) (C/C++) Pin
Shankar Chandra Bose1-Aug-01 16:02
Shankar Chandra Bose1-Aug-01 16:02 
GeneralRe: So, how good are you? ;) (C/C++) Pin
1-Aug-01 16:11
suss1-Aug-01 16:11 
GeneralRe: So, how good are you? ;) (C/C++) Pin
Shankar Chandra Bose1-Aug-01 16:42
Shankar Chandra Bose1-Aug-01 16:42 
GeneralRe: So, how good are you? ;) (C/C++) Pin
Michael Martin1-Aug-01 16:13
professionalMichael Martin1-Aug-01 16:13 
GeneralRe: So, how good are you? ;) (C/C++) Pin
1-Aug-01 16:19
suss1-Aug-01 16:19 
GeneralRe: So, how good are you? ;) (C/C++) Pin
Michael Martin1-Aug-01 16:44
professionalMichael Martin1-Aug-01 16:44 
GeneralRe: So, how good are you? ;) (C/C++) Pin
Mikhail Ermishkin1-Aug-01 21:42
Mikhail Ermishkin1-Aug-01 21:42 
GeneralRe: So, how good are you? ;) (C/C++) Pin
Shankar Chandra Bose1-Aug-01 16:43
Shankar Chandra Bose1-Aug-01 16:43 
GeneralOrca - Setup file Editor Pin
sankar1-Aug-01 15:22
sankar1-Aug-01 15:22 
GeneralRe: Orca - Setup file Editor Pin
Not Active1-Aug-01 17:15
mentorNot Active1-Aug-01 17:15 
Generalstoring thiscall functions in a pointer Pin
1-Aug-01 13:20
suss1-Aug-01 13:20 
GeneralRe: storing thiscall functions in a pointer Pin
Michael Dunn1-Aug-01 13:37
sitebuilderMichael Dunn1-Aug-01 13:37 
GeneralRe: storing thiscall functions in a pointer Pin
1-Aug-01 14:11
suss1-Aug-01 14:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.