This documentation is archived and is not being maintained.


Informs the device driver that a new print job is starting and that all subsequent StartPage and EndPage calls should be spooled under the same job until an EndDoc call occurs.

int StartDoc(
   LPDOCINFO lpDocInfo 
int StartDoc(
   LPCTSTR lpszDocName 



Points to a DOCINFO structure containing the name of the document file and the name of the output file.


Pointer to a string containing the name of the document file.

If the function succeeds, the return value is greater than zero. This value is the print job identifier for the document.

If the function fails, the return value is less than or equal to zero.

This ensures that documents longer than one page will not be interspersed with other jobs.

For Windows versions 3.1 and later, this function replaces the STARTDOC printer escape. Using this function ensures that documents containing more than one page are not interspersed with other print jobs.

StartDoc should not be used inside metafiles.

This code fragment gets the default printer, opens a print job, and spools one page with "Hello, World!" on it. Because the text printed by this code isn't scaled to the printer's logical units, the output text may be in such small letters that the result is unreadable. The CDC scaling functions, such as SetMapMode, SetViewportOrg, and SetWindowExt, can be used to fix the scaling.

// get the default printer
CPrintDialog dlg(FALSE);

// is a default printer set up?
HDC hdcPrinter = dlg.GetPrinterDC();
if (hdcPrinter == NULL)
   MessageBox(_T("Buy a printer!"));
   // create a CDC and attach it to the default printer
   CDC dcPrinter;

   // call StartDoc() to begin printing
   DOCINFO docinfo;
   memset(&docinfo, 0, sizeof(docinfo));
   docinfo.cbSize = sizeof(docinfo);
   docinfo.lpszDocName = _T("CDC::StartDoc() Code Fragment");

   // if it fails, complain and exit gracefully
   if (dcPrinter.StartDoc(&docinfo) < 0)
      MessageBox(_T("Printer wouldn't initalize"));
      // start a page
      if (dcPrinter.StartPage() < 0)
         MessageBox(_T("Could not start page"));
         // actually do some printing
         CGdiObject* pOldFont = dcPrinter.SelectStockObject(SYSTEM_FONT);

         dcPrinter.TextOut(50, 50, _T("Hello World!"), 12);