Esempio n. 1
0
void Print(HWND hWnd)
{
	PRINTDLG PrintDialog;
	memset(&PrintDialog, 0, sizeof(PRINTDLG));
	PrintDialog.lStructSize = sizeof(PRINTDLG);
	PrintDialog.hwndOwner = hWnd;
	PrintDialog.hDevMode = NULL;
	PrintDialog.hDevNames = NULL;
	PrintDialog.nCopies = 1;
	PrintDialog.Flags = PD_RETURNDC;
	PrintDialog.nMinPage = 1;
	PrintDialog.nMaxPage = 0xFFFF;
	PrintDlg(&PrintDialog);
	DOCINFO docInfo;
	docInfo.cbSize = sizeof(docInfo);
	docInfo.lpszDocName = L"Printing";
	docInfo.lpszOutput = 0;
	docInfo.lpszDatatype = 0;
	docInfo.fwType = 0;
	StartDoc(PrintDialog.hDC, &docInfo); 
	RECT printRect;
	GetClientRect(hWnd, &printRect);
	StretchBlt(PrintDialog.hDC, 0, 0, scrhor*4, scrvert*4, hdc1, scrhor/3, scrvert/3, scrhor/3*2,scrvert/3*2, SRCCOPY);
	EndDoc(PrintDialog.hDC);
}
Esempio n. 2
0
Fl_Gdi::Fl_Gdi(HDC gc, DEVMODE * mode):Fl_Printer(),gc_(gc),mode_(mode),delete_mode_(0)
{
    static DOCINFO DocInfo = { sizeof(DOCINFO), "FLTK Document", NULL,0 };// declare DocInfo for use and set the name of the print job as 'Name Of Document'
    DEVMODE  *mod  = (DEVMODE *)GlobalLock(mode_);
    int orientation_ = 0;
    if(mod->dmOrientation==DMORIENT_LANDSCAPE)
        orientation_ = 1;
    int paper;
    if(mod->dmFields & DM_PAPERSIZE) {
        paper = gdipaper(mod);

        if(mod->dmOrientation == DMORIENT_PORTRAIT) {
            pw_ = Fl_Printer::page_formats[paper][0];
            ph_ = Fl_Printer::page_formats[paper][1];
        } else {
            pw_ = Fl_Printer::page_formats[paper][1];
            ph_ = Fl_Printer::page_formats[paper][0];
        }
    }



    ResetDC(gc_,mod);
    GlobalUnlock(mode_);
    SetMapMode(gc_, MM_ANISOTROPIC);
    SetTextAlign(gc_, TA_BASELINE|TA_LEFT);
    SetBkMode(gc_, TRANSPARENT);
    StartDoc(gc_, &DocInfo);
    ix = GetDeviceCaps(gc_, LOGPIXELSX);
    iy = GetDeviceCaps(gc_, LOGPIXELSY);
    ox = GetDeviceCaps(gc_, PHYSICALOFFSETX);
    oy = GetDeviceCaps(gc_, PHYSICALOFFSETY);

    nPages=0;
}
Esempio n. 3
0
int Print::start_print(HWND ohwnd,HINSTANCE hThis) {

    hdc = GetDC(ohwnd);
    memDC = CreateCompatibleDC(hdc);

    print_init(&printdlg, ohwnd, hThis);
    if(!PrintDlg(&printdlg)) return 0;

    docinfo.cbSize = sizeof(DOCINFO);
    docinfo.lpszDocName = "Printing bitmaps";
    docinfo.lpszOutput = NULL;
    docinfo.lpszDatatype = NULL;
    docinfo.fwType = 0;

    if(!(GetDeviceCaps(printdlg.hDC, RASTERCAPS)
	 & (RC_BITBLT | RC_STRETCHBLT|RC_BITMAP64 |
	    RC_DI_BITMAP| RC_DIBTODEV |RC_PALETTE |RC_SCALING |RC_STRETCHBLT|RC_STRETCHDIB))) {
	/*
	  MessageBox(ohwnd, "Cannot Print Raster Images",
	  "Error", MB_OK);
	*/
	return NULL;
    }

    StartDoc(printdlg.hDC, &docinfo);
    //##	begin	zhoubin	000406
    printer_mem_dc = CreateCompatibleDC(printdlg.hDC);
    //##	end		zhoubin	000406

    return 1;
}
Esempio n. 4
0
Bool
apc_prn_begin_doc( Handle self, const char* docName)
{
   LPPRINTER_INFO_2 ppi = &sys s. prn. ppi;
   DOCINFO doc;
   doc. cbSize = sizeof( DOCINFO);
   doc. lpszDocName = docName;
   doc. lpszOutput = nil;
   doc. lpszDatatype = nil;
   doc. fwType = 0;

   objCheck false;
   if ( !( sys ps = CreateDC( ppi-> pDriverName, ppi-> pPrinterName, ppi-> pPortName, ppi-> pDevMode)))
      apiErrRet;

   if ( StartDoc( sys ps, &doc) <= 0) {
      apiPrnErr;
      DeleteDC( sys ps);
      sys ps = nil;
      return false;
   }
   if ( StartPage( sys ps) <= 0) {
      apiPrnErr;
      DeleteDC( sys ps);
      sys ps = nil;
      return false;
   }

   hwnd_enter_paint( self);
   if (( sys pal = palette_create( self))) {
      SelectPalette( sys ps, sys pal, 0);
      RealizePalette( sys ps);
   }
   return true;
}
Esempio n. 5
0
void MacPrinterCanvas::start(float scale) {
	static char szMsg[] = "NEURON";
	scale_ = scale;
	if (!get()) {
		return;
	}
	//if (!Escape(hdc, STARTDOC, sizeof szMsg-1, szMsg, NULL)) {
		//DebugMessage("STARTDOC failed\n");
	//	abort();
	//}
	DOCINFO di;
  di.cbSize      = sizeof(DOCINFO);
  di.lpszDocName = "NEURON";
  di.lpszOutput  = NULL;
	
	StartDoc(hdc, &di);
	StartPage(hdc);
//	SetMapMode(hdc, MM_TWIPS);
	int a = GetMapMode(hdc);
	SIZE b; GetViewportExtEx(hdc, &b);
	POINT c; GetViewportOrgEx(hdc, &c);
	XFORM d; GetWorldTransform(hdc, &d);
	if (a < -10) { return; }
	damage_all();
	RECT r;
	//SetRectRgn(&r, 0, 0, hres_/2, vres_/2);
	r.left = 0; r.top=0; r.right = hres_; r.bottom=vres_;
	beginPaint(hdc, r);
	//SelectClipRgn(hdc, NULL);

	//d.eM11 = d.eM22 *= 2.;	
	//SetWorldTransform(hdc, &d);
}
Esempio n. 6
0
void startPrint(HWND hWnd, char *dirpath, char *filename, char* maptitle)
{
    char *pdfDriver = "Win2PDF";

    pdfDC = CreateDC("WINSPOOL", pdfDriver, NULL, NULL);
    if (!pdfDC) {
        error_stop("cannot open PDF driver: ", pdfDriver);
    }

    int horzres = GetDeviceCaps(pdfDC, HORZRES);
    int vertres = GetDeviceCaps(pdfDC, VERTRES);

    // Let's find the aspect ratio of the page
    double aspectRatio = (double) vertres / (double)horzres;

    pageWidth = DESIRED_PAGE_WIDTH;
    pageHeight = (int)((double)DESIRED_PAGE_WIDTH * aspectRatio);

    SetMapMode(pdfDC, MM_ISOTROPIC);
    SetViewportExtEx(pdfDC, horzres, vertres, NULL);
    SetWindowExtEx(pdfDC, pageWidth, pageHeight, NULL);

    DOCINFO docInfo = {0};
    docInfo.cbSize = sizeof(docInfo);

    char fullpath[MAX_PATH] = {0};
    strcpy_s(fullpath, sizeof(fullpath), dirpath);
    strcat_s(fullpath, sizeof(fullpath), filename);

    docInfo.lpszDocName = filename;
    docInfo.lpszOutput = fullpath;

    StartDoc(pdfDC, &docInfo);
    StartPage(pdfDC);
}
Esempio n. 7
0
main ()
{
	PRINTDLG	pd;
	DOCINFO		di;
	char*		szMessage;

	memset (&pd, 0, sizeof(PRINTDLG));
	memset (&di, 0, sizeof(DOCINFO));

	di.cbSize = sizeof(DOCINFO);
	di.lpszDocName = "Test";

	pd.lStructSize = sizeof(PRINTDLG);
	pd.Flags = PD_PAGENUMS | PD_RETURNDC;
	pd.nFromPage = 1;
	pd.nToPage = 1;
	pd.nMinPage = 1;
	pd.nMaxPage = 1;

	szMessage = 0;

	if (PrintDlg (&pd))
	{
		if (pd.hDC)
		{
			if (StartDoc (pd.hDC, &di) != SP_ERROR)
			{
				StartPage (pd.hDC);

				TextOut (pd.hDC, 0, 0, "Hello, printer!", 15);

				EndPage (pd.hDC);

				EndDoc (pd.hDC);

				szMessage = "Printed.";
			}
			else
			{
				szMessage = "Could not start document.";
			}
		}
		else
		{
			szMessage = "Could not create device context.";
		}
	}
	else
	{
		szMessage = "Canceled or printer could not be setup.";
	}

	if (szMessage)
	{
		MessageBox (NULL, szMessage, "Print Test", MB_OK);
	}

	return 0;
}
Esempio n. 8
0
int CDC::StartDoc(LPCTSTR lpszDocName)
{
	DOCINFO di;
	memset(&di, 0, sizeof(DOCINFO));
	di.cbSize = sizeof(DOCINFO);
	di.lpszDocName = lpszDocName;
	return StartDoc(&di);
}
Esempio n. 9
0
int PrintBox ( void )
{
	// Gain HWND if can
	hwnd = NULL;
	if ( g_pGlob )
		hwnd = g_pGlob->hWnd;

	// Initialize PRINTDLG
	ZeroMemory(&pd, sizeof(PRINTDLG));
	pd.lStructSize = sizeof(PRINTDLG);
	pd.hwndOwner   = hwnd;
	pd.hDevMode    = NULL;      // Don't forget to free or store hDevMode.
	pd.hDevNames   = NULL;      // Don't forget to free or store hDevNames.
	pd.Flags       = PD_ALLPAGES | PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC | PD_HIDEPRINTTOFILE | PD_NOPAGENUMS; 
	pd.nCopies     = 1;
	pd.nFromPage   = 0; 
	pd.nToPage     = 0; 
	pd.nMinPage    = 1; 
	pd.nMaxPage    = 1; 

	// Print Setup
	if (PrintDlg(&pd)==TRUE)
	{
		// Free unused data
		if (pd.hDevMode) GlobalFree (pd.hDevMode);
		if (pd.hDevNames) GlobalFree (pd.hDevNames); 

		// Prepare Document
		di.cbSize = sizeof(DOCINFO); 
		di.lpszDocName = "Printing Document"; 
		di.lpszDatatype = (LPTSTR) NULL; 
		di.lpszOutput = (LPTSTR) NULL; 
		di.fwType = 0; 

		// Begin a print job by calling the StartDoc function. 
		int nError = StartDoc(pd.hDC, &di); 
		if (nError == SP_ERROR) 
		{
			DeleteDC(pd.hDC); 
			pd.hDC = NULL;
			return 0;
		}
		
		// Inform the driver that the application is about to begin 
		nError = StartPage(pd.hDC); 
		if (nError <= 0) 
		{
			DeleteDC(pd.hDC); 
			pd.hDC = NULL;
			return 0;
		}
	}
	else
		return 0;

	// success - begin sending text
	return 1;
}
Esempio n. 10
0
void CComPrint::PrintBmp(UINT nBmpId)
{
	char szPrinter[200] = "";
	char *pszDevice = NULL;
	char *pszDriver = NULL;
	char *pszOutput = NULL;

	HDC hdcPrint = NULL; // 定义一个设备环境句柄

	static DOCINFO di={sizeof(DOCINFO),"printer",NULL};

	// 得到设备字符串存入数组szPrinter中
	GetProfileString("windows","device",",,,",szPrinter,80); 

	// 将设备字符串分解
	if( (NULL != (pszDevice = strtok(szPrinter,","))) && 
		(NULL != (pszDriver = strtok(NULL,","))) &&
		(NULL != (pszOutput = strtok(NULL,","))))
	{
		// 创建一个打印机设备句柄
		if((hdcPrint = CreateDC(pszDriver,pszDevice, pszOutput, NULL)) != 0)
		{ 
			if (StartDoc(hdcPrint, &di) > 0)	//开始执行一个打印作业 
			{ 
				StartPage(hdcPrint);			//打印机走纸,开始打印 
				SaveDC(hdcPrint);				//保存打印机设备句柄

				#pragma warning(disable:4312)

				// 输出图片
				HBITMAP hBitmap=::LoadBitmap(AfxGetInstanceHandle(),(LPCTSTR)nBmpId);
				BITMAP bitmap;
				::GetObject(hBitmap,sizeof(BITMAP),&bitmap);

				#pragma warning(default:4312)

				HDC dcMem;
				dcMem=::CreateCompatibleDC(hdcPrint);
				HBITMAP hOldBmp=(HBITMAP)::SelectObject(dcMem,hBitmap);

				int nVertCenterPos = ::GetDeviceCaps(hdcPrint, VERTRES) / 2;
				::StretchBlt(hdcPrint,1,50,400,bitmap.bmHeight,dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);

				::SelectObject(dcMem,hOldBmp);
				::DeleteDC(dcMem);
				::DeleteObject(hBitmap);

				RestoreDC(hdcPrint,-1); //恢复打印机设备句柄 
				EndPage(hdcPrint); //打印机停纸,停止打印 
				EndDoc(hdcPrint); //结束一个打印作业 
			} 

			// 用API函数DeleteDC销毁一个打印机设备句柄 
			DeleteDC(hdcPrint);
		}
	}
}
Esempio n. 11
0
//////////////////
// Do printer STARTDOC function.
// 
int WPPrinter::startDoc(LPCSTR name, LPCSTR output)
{ 
	DOCINFO docinfo;
	docinfo.cbSize = sizeof(DOCINFO);
	docinfo.lpszDocName = name;
	docinfo.lpszOutput = output;
	docinfo.lpszDatatype = NULL;
	docinfo.fwType = 0;
	return StartDoc(hdc, &docinfo);
}
Esempio n. 12
0
int startDoc(int hdc)
			// err code: >0:no error, <=0: user cancelled file dialog
{
	static DOCINFO docInfo = { sizeof (DOCINFO), "Clean", NULL, NULL, 0 } ;

	//rMessageBox(NULL, MB_APPLMODAL, "in startDoc", "");
	bUserAbort = FALSE ;

	return StartDoc((HDC) hdc, &docInfo);
}
Esempio n. 13
0
void SimplePrint(int nPages)
{
	TCHAR temp[MAX_PATH];

	DWORD size = MAX_PATH;
	GetDefaultPrinter(temp, & size); // default printer name

	HDC hDC = CreateDC(NULL, temp, NULL, NULL); // DC with default setting
	
	if ( hDC )
	{
		nCall_AbortProc = 0;
		SetAbortProc(hDC, SimpleAbortProc);

		DOCINFO docinfo;
		docinfo.cbSize       = sizeof(docinfo);
		docinfo.lpszDocName  = _T("SimplePrint");
		docinfo.lpszOutput   = NULL; 
		docinfo.lpszDatatype = _T("EMF");
		docinfo.fwType		 = 0; 

		if ( StartDoc(hDC, & docinfo) > 0 )
		{
			for (int p=0; p<nPages; p++) // one page at a time
				if ( StartPage(hDC) <= 0 )
					break;
				else
				{
					int width  = GetDeviceCaps(hDC, HORZRES);
					int height = GetDeviceCaps(hDC, VERTRES);
					int dpix   = GetDeviceCaps(hDC, LOGPIXELSX);
					int dpiy   = GetDeviceCaps(hDC, LOGPIXELSY);
			
					wsprintf(temp, _T("Page %d of %d"), p+1, nPages);
					SetTextAlign(hDC, TA_TOP | TA_RIGHT );
					TextOut(hDC, width, 0, temp, _tcslen(temp));

					Rectangle(hDC, 0, 0, dpix, dpiy);
					Rectangle(hDC, width, height, width-dpix, height-dpiy);
				
					if ( EndPage(hDC)<0 )
						break;
				}
			
			EndDoc(hDC);
		}

		DeleteDC(hDC);
	}

	wsprintf(temp, "AbortProc called %d times", nCall_AbortProc);
	MessageBox(NULL, temp, "SimlePrint", MB_OK);	
}
Esempio n. 14
0
void Editor::print(){

	static const int MARG=720;	//1440=1 inch

	CPrintDialog dlg(false);
	int e=dlg.DoModal();if( e==IDCANCEL ) return;

	HDC hdc=dlg.GetPrinterDC();
	if( !hdc ){
		MessageBox( "Error printing" );
		return;
	}

	int hr=GetDeviceCaps(hdc,HORZRES),vr=GetDeviceCaps(hdc,VERTRES);
	int px=GetDeviceCaps(hdc,LOGPIXELSX),py=GetDeviceCaps(hdc,LOGPIXELSY);

	SetMapMode(hdc,MM_TEXT);

	FORMATRANGE fr={0};
	fr.hdc=fr.hdcTarget=hdc;
	fr.rcPage.left=fr.rcPage.top=0;
	fr.rcPage.right=(hr/px)*1440;
	fr.rcPage.bottom=(vr/py)*1440;

	//margins
	fr.rc.left=fr.rcPage.left+MARG;
	fr.rc.top=fr.rcPage.top+MARG;
	fr.rc.right=fr.rcPage.right-MARG;
	fr.rc.bottom=fr.rcPage.bottom-MARG;

	char buff[MAX_PATH];
	strcpy( buff,name.c_str() );

	DOCINFO di={sizeof(di)};
	di.lpszDocName=buff;

	getSel();
	int start=selStart,end=selEnd;
	if( start==end ){ start=0;end=editCtrl.GetTextLength(); }

	StartDoc(hdc,&di);
	while( start<end ){
		StartPage(hdc);
		fr.chrg.cpMin=start;
		fr.chrg.cpMax=end;
		start=editCtrl.FormatRange(&fr,true);
		EndPage(hdc);
	}
	EndDoc(hdc);

	editCtrl.FormatRange(0,false);
	DeleteDC(hdc);
}
Esempio n. 15
0
/*****************************************************************************
 * Start document
 * Done on first write to the spooler
*****************************************************************************/
static void StartDocument( void )
{
   char docname[255];
   DOCINFO di;
   DOC_INFO_1 di1;

   strcpy( docname, (DEFCHAR*)CURRENT_FILE->fpath );
   strcat( docname, (DEFCHAR*)CURRENT_FILE->fname );
   if (defaultprinter)
   {
      memset( &di, 0, sizeof ( DOCINFO ) );
      di.cbSize = sizeof( DOCINFO );
      di.lpszDocName = docname;
   }
   else
   {
      memset( &di1, 0, sizeof ( DOC_INFO_1 ) );
      di1.pDocName = docname;
   }

   if ( pd.hDC )
   {
      // If there`s still an open document, we have to close it first
      if ( documentON )
         EndDocument();

      // Re-calculate page extent in characters
      dwCharExtent = MAKELONG(
         ( ( GetDeviceCaps( pd.hDC, HORZRES ) / GetDeviceCaps( pd.hDC, LOGPIXELSX ) ) * LOWORD( dwCPI ) ),
         ( ( GetDeviceCaps( pd.hDC, VERTRES ) / GetDeviceCaps( pd.hDC, LOGPIXELSY ) ) * HIWORD( dwCPI ) ) );

      // Open a new document and start at its first page
      if (defaultprinter)
      {
         StartDoc( pd.hDC, &di );
         StartPage( pd.hDC );
      }
      else
      {
         StartDocPrinter( hPrinter, 1, (LPBYTE)&di1 );
         StartPagePrinter( hPrinter );
      }
      row = column = page = 0;
      PageHeader( page+1 );
      hOldFont = SetFont( );
      PrepareDC( );
      documentON = TRUE;
   }
}
Esempio n. 16
0
int startDocument(const int pdcID, const char *jname, const char *fname) {
    HDC pdc = printerDCs[pdcID];
    if (pdc != NULL) {
        DOCINFO info;
        info.cbSize = sizeof(DOCINFO);
        
        info.lpszDocName = jname;
        info.lpszDatatype = NULL;
        info.lpszOutput = fname;
        info.fwType = 0;
        if (StartDoc(pdc, &info) > 0) {
            return JNI_TRUE;
        }
    }
    return JNI_FALSE;
}
Esempio n. 17
0
GPrintDC::GPrintDC(void *Handle, const char *PrintJobName, const char *PrinterName)
{
	d = new GPrintDCPrivate;
	hDC = (HDC) Handle;

	SetAbortProc(hDC, LgiAbortProc);
	
	// Start document
	if (hDC)
	{
		DOCINFO Info;

		ZeroObj(Info);
		Info.cbSize = sizeof(DOCINFO); 
		Info.lpszDocName = PrintJobName ? PrintJobName : "Lgi Print Job";
		
		if (PrinterName &&
			stristr(PrinterName, "XPS"))
		{
			GFile::Path p(LSP_USER_DOCUMENTS);
			GString FileName;
			FileName.Printf("%s.xps", PrintJobName);
			p += FileName;
			if (FileExists(p.GetFull()))
			{
				for (unsigned i=1; i<1000; i++)
				{
					p.Parent();
					FileName.Printf("%s%i.xps", PrintJobName, i);
					p += FileName;
					if (!FileExists(p.GetFull()))
						break;
				}
			}
			
			Info.lpszOutput = d->OutputFileName = p.GetFull();
		}

		d->DocOpen = StartDoc(hDC, &Info) > 0;
		if (!d->DocOpen)
		{
			DeleteDC(hDC);
			hDC = 0;
		}
	}
}
Esempio n. 18
0
//
// Asks user which printer to use, then creates
// background printing thread.
//
void PrintText(HWND hwndParent, char *pszText)
{
    ThreadPrintInfo *pInfo;
    HANDLE hThread;
    DWORD dwThreadId;
    int result;
    DOCINFO docInfo;

    PRINTDLG dlgPrint;

    // Put up Common Dialog for Printing and get hDC.
    memset(&dlgPrint, 0, sizeof(PRINTDLG));
    dlgPrint.lStructSize = sizeof(PRINTDLG);
    dlgPrint.hwndOwner = hwndParent;
    dlgPrint.Flags = PD_ALLPAGES | PD_USEDEVMODECOPIES
           | PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC;
    dlgPrint.hInstance = hInst;
    if (!PrintDlg(&dlgPrint))
        return;

    // Initialize Printer device
    docInfo.cbSize = sizeof(DOCINFO);
    docInfo.lpszDocName = "Background Printing Example";
    docInfo.lpszOutput = NULL;
    docInfo.lpszDatatype = NULL;
    docInfo.fwType = 0;
    result = StartDoc(dlgPrint.hDC, &docInfo);
    result = StartPage(dlgPrint.hDC);

    pInfo = HeapAlloc(GetProcessHeap(),
                      HEAP_ZERO_MEMORY,
                      sizeof(ThreadPrintInfo));
    pInfo->hDlg = hwndParent;
    pInfo->hWndParent = hwndParent;
    pInfo->hDc = dlgPrint.hDC;
    pInfo->bPrint = TRUE;
    strcpy(pInfo->szText, pszText);

    MTVERIFY( hThread = CreateThread(NULL, 0,
        BackgroundPrintThread, (LPVOID)pInfo,
        0, &dwThreadId ));

	// keep track of all background printing threads
    gPrintJobs[gNumPrinting++] = hThread;
}
Esempio n. 19
0
wBool_t wPrintDocStart( const char * title, int fpageCount, int * copiesP )
{
	printStatus = FALSE;
	pageCount = fpageCount;
	pageNumber = 0;
	print_d.hDc = mswGetPrinterDC();
	if (print_d.hDc == (HDC)0) {
		return FALSE;
	}
		printStatus = TRUE;
		docInfo.cbSize = sizeof docInfo;
		docInfo.lpszDocName = title;
		docInfo.lpszOutput = NULL;
		lpAbortDlg = MakeProcInstance( (FARPROC)mswAbortDlg, mswHInst );
		lpAbortProc = MakeProcInstance( (FARPROC)mswAbortProc, mswHInst );
		SetAbortProc( print_d.hDc, (ABORTPROC)lpAbortProc );
		if (StartDoc( print_d.hDc, &docInfo ) < 0) {
			MessageBox( mswHWnd, "Unable to start print job",
						NULL, MB_OK|MB_ICONHAND );
			FreeProcInstance( lpAbortDlg );
			FreeProcInstance( lpAbortProc );
			DeleteDC( print_d.hDc );
			return FALSE;
		}
		printAbort = FALSE;
		hAbortDlgWnd = CreateDialog( mswHInst, "MswAbortDlg", mswHWnd,
						(DLGPROC)lpAbortDlg );
		/*SetDlgItemText( hAbortDlgWnd, IDM_PRINTAPP, title );*/
		SetWindowText( hAbortDlgWnd, title );
		ShowWindow( hAbortDlgWnd, SW_NORMAL );
		UpdateWindow( hAbortDlgWnd );
		EnableWindow( mswHWnd, FALSE );
		if (copiesP)
			*copiesP = printDlg.nCopies;
		if (printDlg.nCopies>1)
			pageCount *= printDlg.nCopies;
		if ( (GetDeviceCaps( printDlg.hDC, RASTERCAPS ) & RC_PALETTE) ) {
			newPrintPalette = mswCreatePalette();
			oldPrintPalette = SelectPalette( printDlg.hDC, newPrintPalette, 0 );
			RealizePalette( printDlg.hDC );
		}
		return TRUE;
}
Esempio n. 20
0
void CComPrint::WinPrint(CString csText)
{
	char szPrinter[200] = "";
	char *pszDevice = NULL;
	char *pszDriver = NULL;
	char *pszOutput = NULL;

	HDC hdcPrint = NULL; // 定义一个设备环境句柄

	static DOCINFO di={sizeof(DOCINFO),"printer",NULL};

	// 得到设备字符串存入数组szPrinter中
	GetProfileString("windows","device",",,,",szPrinter,80); 

	// 将设备字符串分解
	if( (NULL != (pszDevice = strtok(szPrinter,","))) && 
		(NULL != (pszDriver = strtok(NULL,","))) &&
		(NULL != (pszOutput = strtok(NULL,","))))
	{
		// 创建一个打印机设备句柄
		if((hdcPrint = CreateDC(pszDriver,pszDevice, pszOutput, NULL)) != 0)
		{ 
			if (StartDoc(hdcPrint, &di) > 0)	//开始执行一个打印作业 
			{ 
				StartPage(hdcPrint);			//打印机走纸,开始打印 
				SaveDC(hdcPrint);				//保存打印机设备句柄

				// 输出文字
				CRect rcText(0,0,0,0);
				::DrawText(hdcPrint, csText, csText.GetLength(), &rcText, DT_CALCRECT);	// 计算大小
				::DrawText(hdcPrint, csText, csText.GetLength(), &rcText, DT_WORDBREAK);

				RestoreDC(hdcPrint,-1);			//恢复打印机设备句柄 
				EndPage(hdcPrint);				//打印机停纸,停止打印 
				EndDoc(hdcPrint);				//结束一个打印作业 
			} 

			// 用API函数DeleteDC销毁一个打印机设备句柄 
			DeleteDC(hdcPrint);
		}
	}
}
Esempio n. 21
0
bool CPrinterDC::Start(const char* pszTitle)
{
	DOCINFO DocInfo;

	ASSERT(pszTitle);
	ASSERT(m_hDC);
	
	// Initialise.
	DocInfo.cbSize      = sizeof(DOCINFO);
	DocInfo.lpszDocName = pszTitle;
	DocInfo.lpszOutput  = NULL;
	
	m_iLastError = StartDoc(m_hDC, &DocInfo);

	// Error occurred?
	if (m_iLastError == SP_ERROR)
		return FALSE;
	
	return TRUE;
}
Esempio n. 22
0
static int
winprint_start (struct winprint_data *wd, Tcl_Interp *interp, PRINTDLG *pd,
		const struct print_text_options *pto, int *cancelled)
{
  DOCINFO di;

  *cancelled = 0;

  wd->aborted = 0;

  /* We have no way to pass information to the abort function, so we
     need to use a global variable.  */
  abort_wd = wd;
  if (! SetAbortProc (pd->hDC, abort_function))
    {
      windows_error (interp, "SetAbortFunc");
      return TCL_ERROR;
    }

  di.cbSize = sizeof (DOCINFO);
  di.lpszDocName = pto->name;
  di.lpszOutput = NULL;
  di.lpszDatatype = NULL;
  di.fwType = 0;

  if (StartDoc (pd->hDC, &di) <= 0)
    {
      if (GetLastError () == ERROR_CANCELLED)
	*cancelled = 1;
      else
	{
	  windows_error (interp, "StartDoc");
	  return TCL_ERROR;
	}
    }

  return TCL_OK;
}
Esempio n. 23
0
void print_mswin(const char *file_name)
{
    HDC     hDC;
    DOCINFO di;
    short int width, height;

    HWND hWndParent = HWND_DESKTOP; /* would be better to be a real window */

    /* Need a printer DC to print to. */
    hDC = get_printer_dc(&width, &height);

    /* Did you get a good DC?, Cancel will return NULL also, so what to do? */
    if (!hDC) {
        return;
    }

    /* You always have to use an AbortProc(). */
    if (SetAbortProc(hDC, abort_proc) == SP_ERROR) {
        MessageBox(NULL, "Error setting up AbortProc",
                   "Error", MB_APPLMODAL | MB_OK);
        return;
    }

    /* Init the DOCINFO and start the document. */
    init_doc_struct(&di, "MyDoc");
    StartDoc(hDC, &di);

    /* Print one page. */
    StartPage(hDC);
    print_file(file_name, hDC, width, height);
    EndPage(hDC);

    /* Indicate end of document. */
    EndDoc(hDC);

    /* Clean up */
    DeleteDC(hDC);
}
Esempio n. 24
0
void Printer::Print(Window *Obj)
{
	if (PrintDialog(Obj,PD_RETURNDC))
	{
		RECT Client;
		GetClientRect(Obj->hWnd,&Client);

		SetMapMode(pd.hDC, MM_ANISOTROPIC);
		SetWindowExtEx(pd.hDC, Client.right, Client.bottom,NULL);
		SetViewportExtEx(pd.hDC, GetDeviceCaps(pd.hDC,HORZRES),GetDeviceCaps(pd.hDC,VERTRES),NULL);

		DOCINFO dInfo={sizeof(DOCINFO),"Test-Doc",NULL};
		StartDoc(pd.hDC,&dInfo);
		StartPage(pd.hDC);

		Obj->Paint(pd.hDC,FALSE,Client);

		EndPage(pd.hDC);
		EndDoc(pd.hDC);

		DeleteDC(pd.hDC);
	}
}
Esempio n. 25
0
BOOL PrintMyPage (HWND hwnd)
{
     static DOCINFO di = { sizeof (DOCINFO), TEXT ("Print2: Printing") } ;
     BOOL           bSuccess = TRUE ;
     HDC            hdcPrn ;
     short          xPage, yPage ;
     
     if (NULL == (hdcPrn = GetPrinterDC ()))
          return FALSE ;
     
     xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
     yPage = GetDeviceCaps (hdcPrn, VERTRES) ;
     
     EnableWindow (hwnd, FALSE) ;
     
     SetAbortProc (hdcPrn, AbortProc) ;
     
     if (StartDoc (hdcPrn, &di) > 0)
     {
          if (StartPage (hdcPrn) > 0)
          {
               PageGDICalls (hdcPrn, xPage, yPage) ;
               
               if (EndPage (hdcPrn) > 0)
                    EndDoc (hdcPrn) ;
               else
                    bSuccess = FALSE ;
          }
     }
     else
          bSuccess = FALSE ;
     
     EnableWindow (hwnd, TRUE) ;
     DeleteDC (hdcPrn) ;
     return bSuccess ;
}
Esempio n. 26
0
/* GetWindowLong(hwnd, 4) must be available for use */
void WDPROC
DumpPrinter(HWND hwnd, LPSTR szAppName, LPSTR szFileName)
{
	HDC printer;
	PRINTDLG pd;
	/* FIXME: share these with CopyPrint */
	static DEVNAMES * pDevNames = NULL;
	static DEVMODE * pDevMode = NULL;
	LPCTSTR szDriver, szDevice, szOutput;
	GP_PRINT pr;
	DOCINFO di;
	char *buf;
	WORD *bufcount;
	int count;
	FILE *f;
	long lsize;
	long ldone;
	char pcdone[10];

	if ((f = fopen(szFileName, "rb")) == NULL)
		return;
	fseek(f, 0L, SEEK_END);
	lsize = ftell(f);
	if (lsize <= 0)
		lsize = 1;
	fseek(f, 0L, SEEK_SET);
	ldone = 0;

	/* Print Setup Dialog */

	/* See http://support.microsoft.com/kb/240082 */
	memset(&pd, 0, sizeof(pd));
	pd.lStructSize = sizeof(pd);
	pd.hwndOwner = hwnd;
	pd.Flags = PD_PRINTSETUP;
	pd.hDevNames = pDevNames;
	pd.hDevMode = pDevMode;

	if (PrintDlg(&pd)) {
		pDevNames = (DEVNAMES *) GlobalLock(pd.hDevNames);
		pDevMode = (DEVMODE *) GlobalLock(pd.hDevMode);

		szDriver = (LPCTSTR)pDevNames + pDevNames->wDriverOffset;
		szDevice = (LPCTSTR)pDevNames + pDevNames->wDeviceOffset;
		szOutput = (LPCTSTR)pDevNames + pDevNames->wOutputOffset;

		printer = CreateDC(szDriver, szDevice, szOutput, pDevMode);

		GlobalUnlock(pd.hDevMode);
		GlobalUnlock(pd.hDevNames);

		/* We no longer free these structures, but preserve them for the next time
		GlobalFree(pd.hDevMode);
		GlobalFree(pd.hDevNames);
		*/

		if (printer == NULL)
			return;	/* abort */

		pr.hdcPrn = printer;
		SetWindowLongPtr(hwnd, 4, (LONG_PTR)((GP_LPPRINT)&pr));
		PrintRegister((GP_LPPRINT)&pr);
		if ((buf = malloc(4096 + 2)) != NULL) {
			bufcount = (WORD *)buf;
			EnableWindow(hwnd,FALSE);
			pr.bUserAbort = FALSE;
			pr.hDlgPrint = CreateDialogParam(hdllInstance, "CancelDlgBox",
							 hwnd, PrintDlgProc, (LPARAM)szAppName);
			SetAbortProc(printer, PrintAbortProc);

			memset(&di, 0, sizeof(DOCINFO));
			di.cbSize = sizeof(DOCINFO);
			di.lpszDocName = szAppName;
			if (StartDoc(printer, &di) > 0) {
				while (pr.hDlgPrint && !pr.bUserAbort &&
					   (count = fread(buf + 2, 1, 4096, f)) != 0 ) {
					int ret;
					*bufcount = count;
					ret = Escape(printer, PASSTHROUGH, count + 2, (LPSTR)buf, NULL);
					ldone += count;
					if (ret != SP_ERROR) {
						sprintf(pcdone, "%d%% done", (int)(ldone * 100 / lsize));
						SetWindowText(GetDlgItem(pr.hDlgPrint, CANCEL_PCDONE), pcdone);
					} else {
						SetWindowText(GetDlgItem(pr.hDlgPrint, CANCEL_PCDONE), "Passthrough Error!");
					}
					if (pr.bUserAbort)
						AbortDoc(printer);
					else
						EndDoc(printer);
				}
				if (!pr.bUserAbort) {
					EnableWindow(hwnd, TRUE);
					DestroyWindow(pr.hDlgPrint);
				}
				free(buf);
			}
		}
		DeleteDC(printer);
		SetWindowLong(hwnd, 4, 0L);
		PrintUnregister((GP_LPPRINT)&pr);
	}

	fclose(f);
}
Esempio n. 27
0
int fb_PrinterOpen( DEV_LPT_INFO *devInfo, int iPort, const char *pszDevice )
{
    int result = fb_ErrorSetNum( FB_RTERROR_OK );
    const DEV_PRINTER_EMU_MODE *pFoundEmu = NULL;
    DWORD dwJob = 0;
    BOOL fResult;
    HANDLE hPrinter = NULL;
    HDC hDc = NULL;

		char *printer_name = NULL;
		char *doc_title = NULL;

		DEV_LPT_PROTOCOL *lpt_proto;
		if ( !fb_DevLptParseProtocol( &lpt_proto, pszDevice, strlen(pszDevice), TRUE ) )
		{
			if( lpt_proto!=NULL )
				free(lpt_proto);
      return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL );
		}

    /* Allow only valid emulation modes */
    if( *lpt_proto->emu!=0 ) {
        int i;
        for( i=0;
             i!=sizeof(aEmulationModes)/sizeof(aEmulationModes[0]);
             ++i )
        {
            const DEV_PRINTER_EMU_MODE *pEmu = aEmulationModes + i;
            if( strcasecmp( lpt_proto->emu, pEmu->pszId )==0 ) {
                pFoundEmu = pEmu;
                break;
            }
        }
        if( !pFoundEmu )
				{
					if( lpt_proto!=NULL )
						free(lpt_proto);
          return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL );
				}
    }

    if( iPort==0 ) {
      /* LPT:[PrinterName] */
			if( *lpt_proto->name )
			{
        printer_name = strdup( lpt_proto->name );
			} else {
				printer_name = GetDefaultPrinterName();
			}

    } else {
        /* LPTx: */
        FB_LIST dev_printer_devs;
        DEV_PRINTER_DEVICE* node;

        fb_hListDevInit( &dev_printer_devs );
        fb_hPrinterBuildList( &dev_printer_devs );

        /* Find printer attached to specified device */
        node = fb_hListDevFindDevice( &dev_printer_devs, lpt_proto->proto );
        if( node!=NULL ) {
            printer_name = strdup( node->printer_name );
        }

        fb_hListDevClear( &dev_printer_devs );
    }

    if( printer_name == NULL ) {
        result = fb_ErrorSetNum( FB_RTERROR_FILENOTFOUND );
    } else {
        if( *lpt_proto->emu!= '\0' ) {
            /* When EMULATION is used, we have to use the DC instead of
             * the PRINTER directly */
            hDc = CreateDCA( "WINSPOOL",
                             printer_name,
                             NULL,
                             NULL );
            fResult = hDc!=NULL;
        } else {
            /* User PRINTER directly */
            fResult = OpenPrinter(printer_name, &hPrinter, NULL);
        }
        if( !fResult ) {
            result = fb_ErrorSetNum( FB_RTERROR_FILENOTFOUND );
        }
    }

    if( lpt_proto->title && *lpt_proto->title ) {
			doc_title = strdup( lpt_proto->title );
		} else {
      doc_title = strdup( "FreeBASIC document" );
		}

    if( result==FB_RTERROR_OK ) {
        if( *lpt_proto->emu!= '\0' ) {
            int iJob;
            DOCINFO docInfo;
            memset( &docInfo, 0, sizeof(DOCINFO) );
            docInfo.cbSize = sizeof(DOCINFO);
            docInfo.lpszDocName = doc_title;
            iJob = StartDoc( hDc, &docInfo );
            if( iJob <= 0 ) {
                result = fb_ErrorSetNum( FB_RTERROR_FILEIO );
            } else {
                dwJob = (DWORD) iJob;
            }
        } else {
            DOC_INFO_1 DocInfo;
            DocInfo.pDocName = doc_title;
            DocInfo.pOutputFile = NULL;
            DocInfo.pDatatype = TEXT("RAW");

            dwJob = StartDocPrinter( hPrinter, 1, (BYTE*) &DocInfo );
            if( dwJob==0 ) {
                result = fb_ErrorSetNum( FB_RTERROR_FILEIO );
            }
        }
    }

    if( result==FB_RTERROR_OK ) {
        W32_PRINTER_INFO *pInfo = calloc( 1, sizeof(W32_PRINTER_INFO) );
        if( pInfo==NULL ) {
            result = fb_ErrorSetNum( FB_RTERROR_OUTOFMEM );
        } else {
            devInfo->driver_opaque = pInfo;
            pInfo->hPrinter = hPrinter;
            pInfo->dwJob = dwJob;
            pInfo->hDc = hDc;
            if( hDc!=NULL ) {
                LOGFONT lf;

                pInfo->Emu.dwFullSizeX = GetDeviceCaps( hDc, PHYSICALWIDTH );
                pInfo->Emu.dwFullSizeY = GetDeviceCaps( hDc, PHYSICALHEIGHT );
                pInfo->Emu.dwSizeX = GetDeviceCaps( hDc, HORZRES );
                pInfo->Emu.dwSizeY = GetDeviceCaps( hDc, VERTRES );
                pInfo->Emu.dwOffsetX = GetDeviceCaps( hDc, PHYSICALOFFSETX );
                pInfo->Emu.dwOffsetY = GetDeviceCaps( hDc, PHYSICALOFFSETY );
                pInfo->Emu.dwDPI_X = GetDeviceCaps( hDc, LOGPIXELSX );
                pInfo->Emu.dwDPI_Y = GetDeviceCaps( hDc, LOGPIXELSY );
#if 0
                pInfo->Emu.dwCurrentX = pInfo->Emu.dwOffsetX;
                pInfo->Emu.dwCurrentY = pInfo->Emu.dwOffsetY;
#else
                pInfo->Emu.dwCurrentX = 0;
                pInfo->Emu.dwCurrentY = 0;
#endif
                pInfo->Emu.clFore = RGB(0,0,0);
                pInfo->Emu.clBack = RGB(255,255,255);

                /* Start in 12 CPI monospace mode */
                EmuBuild_LOGFONT( &lf, pInfo, 12 );

                /* Should never fail - except when some default fonts were
                 * removed by hand (which is very unlikely) */
                pInfo->Emu.hFont = CreateFontIndirect( &lf );
                DBG_ASSERT( pInfo->Emu.hFont!=NULL );

                /* Register PRINT function */
                pInfo->Emu.pfnPrint = pFoundEmu->pfnPrint;

                /* Should not be necessary because this is the default */
                SetTextAlign( hDc, TA_TOP | TA_LEFT | TA_NOUPDATECP );

                EmuUpdateInfo( pInfo );
            }
        }
    }

    if( result!=FB_RTERROR_OK ) {
        if( dwJob!=0 ) {
            if( *lpt_proto->emu != '\0' ) {
                EndDoc( hDc );
            } else {
                EndDocPrinter( hPrinter );
            }
        }
        if( hPrinter!=NULL ) {
            ClosePrinter( hPrinter );
        }
        if( hDc!=NULL ) {
            DeleteDC( hDc );
        }
    }

    if( printer_name!=NULL )
        free( printer_name );
    if( doc_title!=NULL )
        free( doc_title );
		if( lpt_proto!=NULL )
			free(lpt_proto);

    return result;
}
Esempio n. 28
0
printer newprinter(double width, double height, const char *name)
{
    DOCINFO docinfo;
    printer obj;
    HDC hDC;
    double dd,AL;
    int ww,hh,x0,y0;

    if(strlen(name)) {
	OSVERSIONINFO verinfo;
	verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(&verinfo);
	switch(verinfo.dwPlatformId) {
	case VER_PLATFORM_WIN32_NT:
	    hDC = CreateDC("WINSPOOL", name, NULL, NULL);
	default:
	    hDC = CreateDC(NULL, name, NULL, NULL);
	}
    } else hDC = chooseprinter();
    if ( !hDC ) return NULL;
    obj = new_object(PrinterObject, (HANDLE) hDC, get_printer_base());
    if ( !obj ) {
	R_ShowMessage(_("Insufficient memory for new printer"));
	DeleteDC(hDC);
	return NULL;
    }
    if ((width == 0.0) && (height == 0.0)) {
	ww = GetDeviceCaps(hDC, HORZRES);
	hh = GetDeviceCaps(hDC, VERTRES);
    }
    else {
	if (width < 0.1) width = 0.1;
	if (height < 0.1) height = 0.1;
	dd =  GetDeviceCaps(hDC, HORZSIZE) / width;
	AL = (dd < 1.0) ? dd : 1.0;
	dd = GetDeviceCaps(hDC, VERTSIZE) / height;
	AL = (dd < AL) ? dd : AL;
	ww = (AL * width) * GetDeviceCaps(hDC, LOGPIXELSX) / 25.4;
	hh = (AL * height) * GetDeviceCaps(hDC, LOGPIXELSY) / 25.4;
    }
    x0 = (GetDeviceCaps(hDC, HORZRES) - ww) / 2;
    y0 = (GetDeviceCaps(hDC, VERTRES) - hh) / 2;
    obj->rect = rect(x0, y0, ww, hh);
    obj->depth = GetDeviceCaps(hDC, BITSPIXEL)* GetDeviceCaps(hDC, PLANES);
    obj->die = private_delprinter;
    obj->drawstate = copydrawstate();
    obj->drawstate->dest = obj;

    docinfo.cbSize = sizeof(DOCINFO);	/* set this size... */
    docinfo.lpszDocName = "GraphAppPrintJob";
    docinfo.lpszOutput = 0;		/* no file output... */
    docinfo.lpszDatatype = 0;
    docinfo.fwType = 0;

    if (StartDoc(hDC, &docinfo) <= 0) {
	R_ShowMessage(_("Unable to start the print job"));
	del(obj);
	return NULL;
    }

    StartPage(hDC);
    return obj;
}
Esempio n. 29
0
/**
** Higher-level interface: Windows  print it  (-m emp)
**/
int to_emp(const GEN_PAR * pg, const OUT_PAR * po)
{
	DEVMODE *dev;
	PRINTDLG pd;
	DOCINFO di = { 0 };

	int xpix, ypix;		//DPI

	int yprinter, xprinter, err;
	// Initialize PRINTDLG
	ZeroMemory(&pd, sizeof(PRINTDLG));
	pd.lStructSize = sizeof(PRINTDLG);
	pd.hwndOwner = NULL;
	pd.hDevMode = NULL;	// Don't forget to free or store hDevMode
	pd.hDevNames = NULL;	// Don't forget to free or store hDevNames
	pd.Flags = PD_RETURNDEFAULT;	// gives default printer
	pd.nCopies = 1;
	pd.nFromPage = 0xFFFF;
	pd.nToPage = 0xFFFF;
	pd.nMinPage = 1;
	pd.nMaxPage = 0xFFFF;

	PrintDlg(&pd);		// first call to fill devmode struct from default printer

	dev = GlobalLock(pd.hDevMode);

	//Auto orient paper
	if (fabs(po->xmax - po->xmin) < fabs(po->ymax - po->ymin))
		dev->dmOrientation = DMORIENT_PORTRAIT;
	else
		dev->dmOrientation = DMORIENT_LANDSCAPE;
	GlobalUnlock(pd.hDevMode);
	pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;

	// now check which printer he wants
	if (PrintDlg(&pd) != TRUE)
		return 0;

	Eprintf("\n\n- Printing it -\n");
	GlobalFree(pd.hDevMode);
	GlobalFree(pd.hDevNames);

	xprinter = GetDeviceCaps(pd.hDC, HORZRES);	// papper width in pixels
	yprinter = GetDeviceCaps(pd.hDC, VERTRES);	// height in pixels
	xpix = GetDeviceCaps(pd.hDC, LOGPIXELSX);	// DPI x to be checked
	ypix = GetDeviceCaps(pd.hDC, LOGPIXELSY);	// DPI y
	// the following code is an attempt to compensate for printers with different
	// X and y resolution ( Not tested !!!)
	if (xpix < ypix) {
		xprinter = (int) (xprinter * ((float) xpix) / ypix);
	} else if (xpix > ypix) {
		yprinter = (int) (yprinter * ((float) ypix) / xpix);
	}
	SetScale(pd.hDC, yprinter, xprinter, po);

	di.cbSize = sizeof(DOCINFO);
	di.lpszDocName = "HPGL File";

	// Begin a print job by calling the StartDoc function.
	StartDoc(pd.hDC, &di);

	// Inform the driver that the application is about to begin
	// sending data.
	StartPage(pd.hDC);

	err = plotit(pd.hDC, pg, po);
	EndPage(pd.hDC);
	EndDoc(pd.hDC);

	DeleteDC(pd.hDC);
	if (!pg->quiet) {
		Eprintf("\nlines=%d moves=%d", lines, moves);
		Eprintf("\n");
	}
	return err;
}
Esempio n. 30
0
VOID DIALOG_FilePrint(VOID)
{
    DOCINFO di;
    PRINTDLG printer;
    SIZE szMetric;
    int cWidthPels, cHeightPels, border;
    int xLeft, yTop, pagecount, dopage, copycount;
    unsigned int i;
    LOGFONT hdrFont;
    HFONT font, old_font=0;
    DWORD size;
    LPTSTR pTemp;
    static const TCHAR times_new_roman[] = _T("Times New Roman");

    /* Get a small font and print some header info on each page */
    ZeroMemory(&hdrFont, sizeof(hdrFont));
    hdrFont.lfHeight = 100;
    hdrFont.lfWeight = FW_BOLD;
    hdrFont.lfCharSet = ANSI_CHARSET;
    hdrFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
    hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    hdrFont.lfQuality = PROOF_QUALITY;
    hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
    _tcscpy(hdrFont.lfFaceName, times_new_roman);

    font = CreateFontIndirect(&hdrFont);

    /* Get Current Settings */
    ZeroMemory(&printer, sizeof(printer));
    printer.lStructSize = sizeof(printer);
    printer.hwndOwner = Globals.hMainWnd;
    printer.hInstance = Globals.hInstance;

    /* Set some default flags */
    printer.Flags = PD_RETURNDC | PD_SELECTION;

    /* Disable the selection radio button if there is no text selected */
    if (!GetSelectionTextLength(Globals.hEdit))
    {
        printer.Flags = printer.Flags | PD_NOSELECTION;
    }

    printer.nFromPage = 0;
    printer.nMinPage = 1;
    /* we really need to calculate number of pages to set nMaxPage and nToPage */
    printer.nToPage = 0;
    printer.nMaxPage = (WORD)-1;

    /* Let commdlg manage copy settings */
    printer.nCopies = (WORD)PD_USEDEVMODECOPIES;

    printer.hDevMode = Globals.hDevMode;
    printer.hDevNames = Globals.hDevNames;

    if (!PrintDlg(&printer))
    {
        DeleteObject(font);
        return;
    }

    Globals.hDevMode = printer.hDevMode;
    Globals.hDevNames = printer.hDevNames;

    assert(printer.hDC != 0);

    /* initialize DOCINFO */
    di.cbSize = sizeof(DOCINFO);
    di.lpszDocName = Globals.szFileTitle;
    di.lpszOutput = NULL;
    di.lpszDatatype = NULL;
    di.fwType = 0;

    if (StartDoc(printer.hDC, &di) <= 0)
    {
        DeleteObject(font);
        return;
    }

    /* Get the page dimensions in pixels. */
    cWidthPels = GetDeviceCaps(printer.hDC, HORZRES);
    cHeightPels = GetDeviceCaps(printer.hDC, VERTRES);

    /* Get the file text */
    if (printer.Flags & PD_SELECTION)
    {
        size = GetSelectionTextLength(Globals.hEdit) + 1;
    }
    else
    {
        size = GetWindowTextLength(Globals.hEdit) + 1;
    }

    pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(TCHAR));
    if (!pTemp)
    {
        EndDoc(printer.hDC);
        DeleteObject(font);
        ShowLastError();
        return;
    }

    if (printer.Flags & PD_SELECTION)
    {
        size = GetSelectionText(Globals.hEdit, pTemp, size);
    }
    else
    {
        size = GetWindowText(Globals.hEdit, pTemp, size);
    }

    border = 150;
    for (copycount=1; copycount <= printer.nCopies; copycount++) {
        i = 0;
        pagecount = 1;
        do {
            static const TCHAR letterM[] = _T("M");

            if (pagecount >= printer.nFromPage &&
    /*          ((printer.Flags & PD_PAGENUMS) == 0 ||  pagecount <= printer.nToPage))*/
            pagecount <= printer.nToPage)
                dopage = 1;
            else
                dopage = 0;

            old_font = SelectObject(printer.hDC, font);
            GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);

            if (dopage) {
                if (StartPage(printer.hDC) <= 0) {
                    SelectObject(printer.hDC, old_font);
                    EndDoc(printer.hDC);
                    DeleteDC(printer.hDC);
                    HeapFree(GetProcessHeap(), 0, pTemp);
                    DeleteObject(font);
                    AlertPrintError();
                    return;
                }
                /* Write a rectangle and header at the top of each page */
                Rectangle(printer.hDC, border, border, cWidthPels-border, border+szMetric.cy*2);
                /* I don't know what's up with this TextOut command. This comes out
                kind of mangled.
                */
                TextOut(printer.hDC,
                        border * 2,
                        border + szMetric.cy / 2,
                        Globals.szFileTitle,
                        lstrlen(Globals.szFileTitle));
            }

            /* The starting point for the main text */
            xLeft = border * 2;
            yTop = border + szMetric.cy * 4;

            SelectObject(printer.hDC, old_font);
            GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);

            /* Since outputting strings is giving me problems, output the main
             * text one character at a time. */
            do {
                if (pTemp[i] == '\n') {
                    xLeft = border * 2;
                    yTop += szMetric.cy;
                }
                else if (pTemp[i] != '\r') {
                    if (dopage)
                        TextOut(printer.hDC, xLeft, yTop, &pTemp[i], 1);
                    xLeft += szMetric.cx;
                }
            } while (i++ < size && yTop < (cHeightPels - border * 2));

            if (dopage)
                EndPage(printer.hDC);
            pagecount++;
        } while (i < size);
    }

    if (old_font != 0)
        SelectObject(printer.hDC, old_font);
    EndDoc(printer.hDC);
    DeleteDC(printer.hDC);
    HeapFree(GetProcessHeap(), 0, pTemp);
    DeleteObject(font);
}