Windows or MFC, I'm not sure which.. whatever the code below represents.
I want to print text to a label printer. I'd like to center the text in
the label and increase the font size over whatever the default is. I
don't understand the RECT thing or how to calculate coordinates or use
fonts. The code below works and it's pretty simple, I'd like to stay
with this scheme if possible (I have similar code elsewhere in the app).
I copied it from MSDN, I think.
Can someone explain how to use a standard Windows font like Arial 12 and
center the text, or point me to a tutorial?
Thanks
---------------
CDC cdc;
HDC hdc;
CPrintDialog dlg(TRUE); // Windows Printer Dialog class
CString formattedpage;
if (dlg.DoModal() == IDOK)
{
// Create a printer device context (DC)
// based on the information
// selected from the Print dialog.
hdc = dlg.CreatePrinterDC();
ASSERT(hdc);
// Attach Device Context object to handle
cdc.Attach(hdc);
cdc.StartDoc("Pan Label"); // begin a new print job
}
else
{
// abort print
}
RECT rect = {0,0,0,0}; // RECT structure for page
cdc.DrawText(formattedpage,&rect,DT_CALCRECT);
cdc.StartPage();
formattedpage.Format("STUFF TO PRINT");
cdc.DrawText(formattedpage,&rect,DT_NOCLIP);
cdc.EndPage();
cdc.EndDoc();