For Feng or anyone who knows how to change the font size on a print out 
Author Message
 For Feng or anyone who knows how to change the font size on a print out


I placed your code with mine, but the font and size didn't change.  I'm
fairly new to C & C++, I only know the bare basics, so here is my code,
maybe you can see what I'm doing wrong?  I copied most of it from books and
the internet.  It's a DLL to change the orientation of the page then print
the contents of a file.  Everything except the font change that you sent me
works.  I've tried this with three different printers, none of them changed
the font and size, but they all did give different spacing between lines.

EXPORT int CALLBACK PrintSpool(HWND hWnd, char* pDevice, char* filepath)
 FILE  *stream;
 char  textline[132];
 HANDLE  hPrinter;
 DWORD  dwNeeded, dwRet;
 HDC   hDC;
 int   i;

 // Start by opening the printer
 if (!OpenPrinter(pDevice, &hPrinter, NULL))
  return 0;

 // Step 1:
 // Allocate a buffer of the correct size.

 dwNeeded = DocumentProperties(hWnd,
  hPrinter,  // handle to our printer
  pDevice,  // Name of the printer
  NULL,   // Asking for size so
  NULL,   // these are not used.
  0);    // Zero returns buffer size.
 pDevMode = (LPDEVMODE)malloc(dwNeeded);

 // Step 2:
 // Get the default DevMode for the printer and
 // modify it for our needs.

 dwRet = DocumentProperties(hWnd,
  pDevMode,  // The address of the buffer to fill.
  NULL,   // Not using the input buffer.
  DM_OUT_BUFFER); // Have the output buffer filled.
 if (dwRet != IDOK)
  // if failure, cleanup and return failure.
  return FALSE;

 //  Make changes to the DevMode which are supported

 if (pDevMode->dmFields & DM_ORIENTATION)
  // if the printer supports paper orientation, set it
  pDevMode->dmOrientation = DMORIENT_LANDSCAPE;

 // Step 3:
 // Merge the new settings with the old.
 // This gives the driver a chance to update any private
 // portions of the DevMode structure.

 dwRet = DocumentProperties(hWnd,
  pDevMode,  // Reuse our buffer for output
  pDevMode,  // Pass the driver our changes
  DM_IN_BUFFER | // Commands to Merge our changes and
  DM_OUT_BUFFER); // write the result.

 // Done with the printer

 if (dwRet != IDOK)
  // if failure, cleanup and return failure
  return 0;

 // Create a device context for the
 // printer to which text will be output.
 hDC = CreateDC("WINSPOOL", pDevice, NULL, pDevMode);


 int pointsize = 8;

 lf.lfHeight = - GetDeviceCaps(hDC, LOGPIXELSY) * pointsize / 72;
 strcpy(lf.lfFaceName, "Courier");

 HFONT hFont = CreateFontIndirect(&lf);
 HGDIOBJ hOld = SelectObject(hDC, hFont);

 // Set up the DOCINFO structure.
 memset(&di, 0, sizeof(DOCINFO));
 di.cbSize = sizeof(DOCINFO);
 di.lpszDocName = "eSpool400 Spool File Print-out";

 // Start the printing
 // Open file to be printed
 if( (stream  = fopen(filepath, "r" )) != NULL )
  if (StartDoc(hDC, &di) != SP_ERROR)
   i = 10;
   // loop through all lines in file and
   // print each one
   while(fgets(textline, 132, stream) != NULL)
    TextOut(hDC, 10, i, textline, 132);
    fgets(textline, 132, stream);
    i = i + 70;



 SelectObject(hDC, hOld);

 // return control to the calling program
 return 1;


Troy Paulson

Sun, 08 Sep 2002 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Does someone know how to change the font weight and size

2. Changing Font Size in my Printed document

3. Changing font and font size on a printout

4. Changing the font and font size on a printout

5. Changing font & font size for CListView windows

6. Colour print outs of source code ?

7. the font size for printing

8. Problem print text in matrix and laser printer (width size of font)

9. Print Preview, Zoom and Font Size

10. How to set the font size when printing??

11. Font size & printing

12. Print Preview, Zoom and Font Size


Powered by phpBB® Forum Software