HDC far pascal zResetDC(HDC pp1, LPSTR pp2) { HDC r; SaveRegs(); /* ** Log IN Parameters (No Create/Destroy Checking Yet!) */ LogIn( (LPSTR)"APICALL:ResetDC HDC+LPDEVMODE+", pp1, pp2 ); /* ** Call the API! */ RestoreRegs(); GrovelDS(); r = ResetDC(pp1,pp2); UnGrovelDS(); SaveRegs(); /* ** Log Return Code & OUT Parameters (No Create/Destroy Checking Yet!) */ LogOut( (LPSTR)"APIRET:ResetDC HDC+++", r, (short)0, (short)0 ); RestoreRegs(); return( r ); }
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; }
/***************************************************************************** * Select a fixed font into the printer DC. Since the DC is scaled for rows * and columns, we set the font size to 1x1 always. * This function returns a handle to the previous selected font. *****************************************************************************/ static void SetOrient( int or ) { dm = (DEVMODE*)GlobalLock( pd.hDevMode ); dm->dmOrientation = orient = or; dm->dmFields |= DM_ORIENTATION; ResetDC( pd.hDC, dm ); GlobalUnlock( dm ); }
/***************************************************************************\ * GetFont() * * Entry: Handle to a window * Exit: selects the font for WINMETER and gets its dimensions * Also sets the variables in the gr structure, to avoid later * calculations \***************************************************************************/ void GetFont( HWND hwnd) // handle to the window { HDC hdc; TEXTMETRIC tm; hdc = GetDC (hwnd); SetupDC(hdc); SelectObject(hdc, WINMETER_FONT); GetTextMetrics (hdc, &tm); g.cxChar = tm.tmAveCharWidth; // set cxCaps according to whether font is fixed or no - see Petzold g.cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * g.cxChar / 2; g.cyChar = tm.tmHeight + tm.tmExternalLeading; g.dyBar = g.cyChar / BAR_SPACING_RATIO; ResetDC(hdc); ReleaseDC (hwnd, hdc); return; }
void Fl_Gdi::set_page(int page) { DEVMODE * mode = (DEVMODE *) GlobalLock(mode_); if(page) { ResetDC(gc_,mode); SetMapMode(gc_, MM_ANISOTROPIC); SetTextAlign(gc_, TA_BASELINE|TA_LEFT); SetBkMode(gc_, TRANSPARENT); StartPage(gc_); ix = GetDeviceCaps(gc_, LOGPIXELSX); iy = GetDeviceCaps(gc_, LOGPIXELSY); ox = GetDeviceCaps(gc_, PHYSICALOFFSETX); oy = GetDeviceCaps(gc_, PHYSICALOFFSETY); } GlobalUnlock(mode_); SetViewportOrgEx(gc_,VOx = (int)(ix * lm_ /72 - ox), VOy =(int)( iy *tm_ /72 - oy),0); //setting origin to the upper left corner inside margins SetViewportExtEx(gc_, VEx = (int)(ix * pw_ / 72), (int)(VEy = iy * ph_ / 72),0); SetWindowExtEx(gc_, WEx = (int) pw_, WEy = (int)ph_,0); //72 pixels per inch mapping SetWindowOrgEx(gc_, WOx = 0, WOy = 0,0); }
void CPrinterInfo::GetDeviceInfo(HGLOBAL hDevMode, HDC in_hDC) { // Ignore the incoming DC since we may not be able to change it via ResetDC. in_hDC = NULL; /* // I don't trust these printer drivers. // I know for sure that some drivers are bad; there may be more than what // I know (from another program). // We will use an INI file mechanism to try and detect and skip over the // bad ones. Unfortunately, this assumes that a bad one will cause a GP // fault... */ if (!GetProfileInt(ENTRY_BadDC, FALSE)) { /* // We set the INI file setting now. If this fails for any reason // (particularly for a GP fault), then it will be set forever as "bad". */ WriteProfileInt(ENTRY_BadDC, TRUE); #ifndef WIN32 LPFNDEVCAPS DeviceCapabilities = NULL; CString csDriverName = m_csDriverName + ".DRV"; UINT uSEM = ::SetErrorMode(SEM_NOOPENFILEERRORBOX); HINSTANCE hDriver = ::LoadLibrary((LPSTR)(LPCSTR)csDriverName); ::SetErrorMode(uSEM); if ((UINT)hDriver >= 32) { DeviceCapabilities = (LPFNDEVCAPS)GetProcAddress(hDriver, "DeviceCapabilities"); } #endif if (DeviceCapabilities != NULL) { /* // Read the number of copies setting. */ m_Record.m_nCopies = (int)DeviceCapabilities((LPSTR)(LPCSTR)m_csPrinterName, (LPSTR)(LPCSTR)m_csOutputName, DC_COPIES, NULL, NULL); TRACE1("Supports %d copies\n", m_Record.m_nCopies); /* // Read the landscape orientation setting. */ m_Record.m_nOrientation = (int)DeviceCapabilities((LPSTR)(LPCSTR)m_csPrinterName, (LPSTR)(LPCSTR)m_csOutputName, (WORD)DC_ORIENTATION, NULL, NULL); TRACE1("Orientation is %d degrees\n", m_Record.m_nOrientation); /* // Read the number of bins. */ int nBins = (int)DeviceCapabilities((LPSTR)(LPCSTR)m_csPrinterName, (LPSTR)(LPCSTR)m_csOutputName, (WORD)DC_BINS, NULL, NULL); if (nBins > 0 && nBins < 32768/sizeof(WORD)) { /* Read the bins. */ WORD* pBins = new WORD[nBins]; if (pBins != NULL) { DeviceCapabilities((LPSTR)(LPCSTR)m_csPrinterName, (LPSTR)(LPCSTR)m_csOutputName, (WORD)DC_BINS, (LPSTR)pBins, NULL); // Assume FALSE until found. m_Record.m_nTractor = 0; for (int i = 0; i < nBins; i++) { if (pBins[i] == DMBIN_TRACTOR) { // We found it. m_Record.m_nTractor = 1; break; } } delete [] pBins; } } } #ifndef WIN32 if ((UINT)hDriver >= 32) { ::FreeLibrary(hDriver); } #endif WriteProfileInt(ENTRY_BadDC, FALSE, FALSE); } /* // Compute the desired orientation (as it is stored in the DevMode structure */ SHORT desired_orientation = m_nOrientationType == PORTRAIT ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE; HDC hDC = NULL; /* If we have no DC, create one now. */ CPrintDialog pd(TRUE); AfxGetApp()->GetPrinterDeviceDefaults(&pd.m_pd); hDevMode = pd.m_pd.hDevMode; LPDEVMODE dm = NULL; DWORD dwOrgFields; int nOrgOrientation; if (hDevMode != NULL) { dm = (LPDEVMODE)::GlobalLock(pd.m_pd.hDevMode); if (dm != NULL) { dwOrgFields = dm->dmFields; nOrgOrientation = dm->dmOrientation; dm->dmFields |= DM_ORIENTATION; dm->dmOrientation = desired_orientation; } } if (pd.m_pd.hDevNames != NULL) { HDC dc_save = pd.m_pd.hDC; hDC = pd.CreatePrinterDC(); pd.m_pd.hDC = dc_save; } /* // Now update the paper info. */ /* Lock the dev mode structure if we have one. */ SHORT orientation = DMORIENT_PORTRAIT; /* In case we fail. */ int paper_source = DMBIN_AUTO; /* In case we fail. */ if (dm != NULL) { if (dm->dmFields & DM_ORIENTATION) { orientation = dm->dmOrientation; ASSERT(orientation == desired_orientation); } if (dm->dmFields & DM_DEFAULTSOURCE) { paper_source = dm->dmDefaultSource; } } // Save the paper size from the DEVMODE structure: DMPAPER_LETTER, ... if (dm != NULL) { m_nDevModePaperSize = dm->dmPaperSize; } else { m_nDevModePaperSize = DMPAPER_LETTER; } /* Set the paper type. */ m_nPaperType = paper_source == DMBIN_TRACTOR ? PAPER_TYPE_CONTINUOUS : PAPER_TYPE_CUT_SHEET; int nPaperXUnit, nPaperYUnit; int nPaperWidth, nPaperHeight; int nPrintableWidth, nPrintableHeight; int nLeftOffset, nTopOffset; if (hDC == NULL) { /* Some stupid defaults. (8 1/2" by 11"). */ nPaperXUnit = 1000; nPaperYUnit = 1000; nPaperWidth = 8500; nPaperHeight = 11000; nPrintableWidth = 8000; nPrintableHeight = 10500; nLeftOffset = 250; nTopOffset = 250; m_nDefaultPostScriptType = 0; // Assume no. } else { /* Lock the DevMode structure! */ #if 0 LPDEVMODE dm; if (hDevMode != NULL && (dm = (LPDEVMODE)GlobalLock(hDevMode)) != NULL) { /* Well, we have it now... */ // if (!(dm->dmFields & DM_ORIENTATION) // || dm->dmOrientation != desired_orientation) { /* // Orientation is not set or not what we want. // Force it to be what we want. */ dm->dmFields |= DM_ORIENTATION; dm->dmOrientation = desired_orientation; orientation = desired_orientation; ResetDC(hDC, dm); } GlobalUnlock(hDevMode); } #endif m_Record.m_nNumColors = GetDeviceCaps(hDC, NUMCOLORS); m_Record.m_nRasterCaps = GetDeviceCaps(hDC, RASTERCAPS); m_Record.m_nBitsPixel = GetDeviceCaps(hDC, BITSPIXEL); m_Record.m_nPlanes = GetDeviceCaps(hDC, PLANES); /* Get the device specifications. */ nPaperXUnit = GetDeviceCaps(hDC, LOGPIXELSX); nPaperYUnit = GetDeviceCaps(hDC, LOGPIXELSY); nPrintableWidth = GetDeviceCaps(hDC, HORZRES); nPrintableHeight = GetDeviceCaps(hDC, VERTRES); POINT p; if (::Escape(hDC, GETPHYSPAGESIZE, NULL, NULL, &p) > 0) { nPaperWidth = p.x; nPaperHeight = p.y; } else { nPaperWidth = nPrintableWidth; nPaperHeight = nPrintableHeight; } if (::Escape(hDC, GETPRINTINGOFFSET, NULL, NULL, &p) > 0) { nLeftOffset = p.x; nTopOffset = p.y; od("Printing offset: %d, %d\r\n", p); } else { nLeftOffset = (nPaperWidth - nPrintableWidth)/2; nTopOffset = (nPaperHeight - nPrintableHeight)/2; } od("PhysPageSize: %d, %d; ", nPaperWidth, nPaperHeight); od("w:%d, h:%d, xres:%d, yres:%d\r\n", nPrintableWidth, nPrintableHeight, nPaperXUnit, nPaperYUnit); // Determine the PostScript type at this time since we have a DC. m_nDefaultPostScriptType = DeterminePostScriptType(hDC); // Delete the DC if we created it. if (hDC != in_hDC) { DeleteDC(hDC); } if (orientation == DMORIENT_LANDSCAPE) { /* Device orientation is landscape. Reverse everything. */ int tmp; tmp = nPrintableWidth; nPrintableWidth = nPrintableHeight; nPrintableHeight = tmp; tmp = nPaperWidth; nPaperWidth = nPaperHeight; nPaperHeight = tmp; tmp = nPaperXUnit; nPaperXUnit = nPaperYUnit; nPaperYUnit = tmp; // Pull in our orientation setting NOW m_Record.m_nOrientation = GetProfileInt(ENTRY_Orientation, m_Record.m_nOrientation); int nOrientation = m_Record.m_nOrientation; if (nOrientation == -1) { nOrientation = 90; // Assume m_Record.m_nTractor = GetProfileInt(ENTRY_Tractor, m_Record.m_nTractor); if (m_Record.m_nTractor == 1 || paper_source == DMBIN_TRACTOR) { m_Record.m_nTractor = 1; nOrientation = 270; } } if (nOrientation == 90) { int nNewTop = nPaperHeight - (nLeftOffset + nPrintableHeight); nLeftOffset = nTopOffset; nTopOffset = nNewTop; } else { ASSERT(nOrientation == 270); int nNewLeft = nPaperWidth - (nTopOffset + nPrintableWidth); nTopOffset = nLeftOffset; nLeftOffset = nNewLeft; } } /* // Tractor paper is fine, but if we can't print on the full page, it // will have to be cut sheet. */ #if 0 if (m_nPaperType == PAPER_TYPE_CONTINUOUS && nPrintableHeight != nPaperHeight) { m_nPaperType = PAPER_TYPE_CUT_SHEET; } #else if (nPrintableHeight == nPaperHeight) { m_nPaperType = PAPER_TYPE_CONTINUOUS; } else { m_nPaperType = PAPER_TYPE_CUT_SHEET; } #endif } /* // Store the values we computed in the member variables. */ CFixed lXUnits = MakeFixed(nPaperXUnit); CFixed lYUnits = MakeFixed(nPaperYUnit); m_PaperSize.x = DivFixed(MakeFixed(nPaperWidth), lXUnits); m_PaperSize.y = DivFixed(MakeFixed(nPaperHeight), lYUnits); m_PrintableSize.x = DivFixed(MakeFixed(nPrintableWidth), lXUnits); m_PrintableSize.y = DivFixed(MakeFixed(nPrintableHeight), lYUnits); m_PhysicalMargins.Left = DivFixed(MakeFixed(nLeftOffset), lXUnits); m_PhysicalMargins.Top = DivFixed(MakeFixed(nTopOffset), lYUnits); m_PhysicalMargins.Right = m_PaperSize.x - (m_PrintableSize.x + m_PhysicalMargins.Left); m_PhysicalMargins.Bottom = m_PaperSize.y - (m_PrintableSize.y + m_PhysicalMargins.Top); if (dm != NULL) { ASSERT(hDevMode != NULL); dm->dmFields = dwOrgFields; dm->dmOrientation = nOrgOrientation; ::GlobalUnlock(hDevMode); } }
void sys_print_begin (void) { static HDC InfoHDC; static float xsize, ysize; static RECT rcl; static int lHeight, lWidth; static int rc; static DOCINFO di = {sizeof (DOCINFO), "NRaD Printing", NULL}; static char szPrinter[80]; static char *szDevice, *szDriver, *szOutput; static PRINTDLG printDlg; static LPDEVMODE deviceMode; /* Setup the system pallete */ //rc = sys_setup_palette (); /* Select a default brush */ graphics.hBrush = CreateSolidBrush (RGB (0, 0, 0)); /* Select a default pen */ graphics.hPen = CreatePen (PS_SOLID, 1, RGB (0,0,0)); /* Get the name of the default printer from the windows profile */ memset (&printDlg, 0, sizeof (PRINTDLG)); printDlg.lStructSize = sizeof (PRINTDLG); printDlg.Flags = PD_RETURNDC | PD_RETURNDEFAULT; printDlg.hwndOwner = 0; PrintDlg (&printDlg); /* Store the handle to the printers device context in the graphics handle DC */ graphics.hdc = printDlg.hDC; if (graphics.hdc == NULL) { /* If we cant open the default printer display a message and return */ sys_error_message ("E","A handle to the printer device could not be obtained"); } /* Call StartDoc to start printing system */ StartDoc (graphics.hdc, &di); /* Set printer to the requested orientation */ deviceMode = (DEVMODE *) GlobalLock (printDlg.hDevMode); if (graphics.landscape) { deviceMode->dmOrientation = DMORIENT_LANDSCAPE; } else { deviceMode->dmOrientation = DMORIENT_PORTRAIT; } ResetDC (printDlg.hDC, deviceMode); GlobalUnlock (printDlg.hDevMode); StartPage (graphics.hdc); /* Get the physical extents for the selected printer in printer units */ lHeight = GetDeviceCaps (graphics.hdc, VERTRES); lWidth = GetDeviceCaps (graphics.hdc, HORZRES); graphics.extent[0] = (float) lWidth; graphics.extent[1] = (float) lHeight; /* Set size of paper to 8.5 x 11 inches */ xsize = 11.0F; ysize = 8.5F; /* Plotter units per inch */ graphics.units[0] = graphics.extent[0] / xsize; graphics.units[1] = graphics.extent[1] / ysize; // Debug printing //printf ("graphics.units = %f, %f, extent = %f, %f, xsize = %f, ysize = %f\n", // graphics.units[0], graphics.units[1], graphics.extent[0], graphics.extent[1], // xsize, ysize); //fflush (stdout); return; }
/* before the device is opened */ int win_pr2_put_params(gx_device * pdev, gs_param_list * plist) { int ecode = 0, code; int old_bpp = pdev->color_info.depth; int bpp = old_bpp; bool tumble = wdev->tumble; bool nocancel = wdev->nocancel; int queryuser = 0; bool old_duplex = wdev->Duplex; bool old_tumble = wdev->tumble; int old_orient = wdev->user_orient; int old_color = wdev->user_color; int old_paper = wdev->user_paper; int old_mx_dpi = wdev->max_dpi; if (wdev->Duplex_set < 0) { wdev->Duplex_set = 0; wdev->Duplex = false; wdev->tumble = false; } win_pr2_copy_check(wdev); code = win_pr2_read_user_settings(wdev, plist); switch (code = param_read_int(plist, "BitsPerPixel", &bpp)) { case 0: if (pdev->is_open) { if (wdev->selected_bpp == bpp) { break; } ecode = gs_error_rangecheck; } else { /* change dev->color_info is valid before device is opened */ win_pr2_set_bpp(pdev, bpp); break; } goto bppe; default: ecode = code; bppe:param_signal_error(plist, "BitsPerPixel", ecode); case 1: break; } switch (code = param_read_bool(plist, "NoCancel", &nocancel)) { case 0: if (pdev->is_open) { if (wdev->nocancel == nocancel) { break; } ecode = gs_error_rangecheck; } else { wdev->nocancel = nocancel; break; } goto nocancele; default: ecode = code; nocancele:param_signal_error(plist, "NoCancel", ecode); case 1: break; } switch (code = param_read_bool(plist, "Tumble", &tumble)) { case 0: wdev->tumble = tumble; break; default: ecode = code; param_signal_error(plist, "Tumble", ecode); case 1: break; } switch (code = param_read_int(plist, "QueryUser", &queryuser)) { case 0: if ((queryuser > 0) && (queryuser < 4)) { win_pr2_print_setup_interaction(wdev, queryuser); } break; default: ecode = code; param_signal_error(plist, "QueryUser", ecode); case 1: break; } if (ecode >= 0) ecode = gdev_prn_put_params(pdev, plist); if (wdev->win32_hdevmode && wdev->hdcprn) { if ( (old_duplex != wdev->Duplex) || (old_tumble != wdev->tumble) || (old_orient != wdev->user_orient) || (old_color != wdev->user_color) || (old_paper != wdev->user_paper) || (old_mx_dpi != wdev->max_dpi) ) { LPDEVMODE pdevmode = GlobalLock(wdev->win32_hdevmode); if (pdevmode) { win_pr2_update_win(wdev, pdevmode); ResetDC(wdev->hdcprn, pdevmode); GlobalUnlock(pdevmode); } } } return ecode; }
VOID vTestResetDC(HWND hwnd, HDC hdcDisp, RECT *prcl) { PRINTDLG pd; HDC hdc; CHAR achBuf[80]; INT i; LPDEVMODE lpDevMode; LPDEVMODE pdmPortrait = NULL; LPDEVMODE pdmLandscape = NULL; LPDEVNAMES lpDevNames; DOCINFO di; di.cbSize = sizeof(di); di.lpszDocName = NULL; di.lpszOutput = NULL; di.lpszDatatype = NULL; di.fwType = 0; memset(&pd,0,sizeof(pd)); pd.lStructSize = sizeof(pd); pd.hwndOwner = hwnd; pd.hDevMode = NULL; pd.hDevNames = NULL; pd.hDC = NULL; pd.Flags = PD_RETURNDC | PD_PAGENUMS; pd.nCopies = 1; pd.nFromPage = 1; pd.nToPage = 1; pd.nMinPage = 1; pd.nMaxPage = 1; if(!pd.hDevNames) /* Retrieve default printer if none selected. */ { pd.Flags = PD_RETURNDEFAULT|PD_PRINTSETUP; if (!PrintDlg(&pd)) return; } if (!pd.hDevNames) { DbgPrint("bad hDevNames\n"); return; } lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames); if (pd.hDevMode) { lpDevMode = (LPDEVMODE)GlobalLock(pd.hDevMode); pdmPortrait = (LPDEVMODE)LocalAlloc(LMEM_FIXED,lpDevMode->dmSize + lpDevMode->dmDriverExtra); memcpy(pdmPortrait,lpDevMode,lpDevMode->dmSize + lpDevMode->dmDriverExtra); pdmPortrait->dmOrientation = DMORIENT_PORTRAIT; pdmLandscape = (LPDEVMODE)LocalAlloc(LMEM_FIXED,lpDevMode->dmSize + lpDevMode->dmDriverExtra); memcpy(pdmLandscape,lpDevMode,lpDevMode->dmSize + lpDevMode->dmDriverExtra); pdmLandscape->dmOrientation = DMORIENT_LANDSCAPE; GlobalUnlock(lpDevMode); GlobalFree(pd.hDevMode); } else { DbgPrint("null pdev, reset DC won't work\n"); } /* For pre 3.0 Drivers,hDevMode will be null from Commdlg so lpDevMode * will be NULL after GlobalLock() */ hdc = CreateDC((LPSTR)lpDevNames+lpDevNames->wDriverOffset, (LPSTR)lpDevNames+lpDevNames->wDeviceOffset, (LPSTR)lpDevNames+lpDevNames->wOutputOffset, pdmPortrait); GlobalUnlock(pd.hDevNames); GlobalFree(pd.hDevNames); DbgPrint("ResetDC test, hdc = %lx \n", hdc); if (hdc == NULL) { DbgPrint("couldn't create DC\n"); return; } // DOC 1 di.lpszDocName = "Document1"; StartDoc(hdc,&di); ResetDC(hdc,pdmLandscape); vPageOut(hdc,1,1,"landscape"); ResetDC(hdc,pdmPortrait); vPageOut(hdc,2,1,"portrait"); ResetDC(hdc,pdmLandscape); vPageOut(hdc,3,1,"landscape"); ResetDC(hdc,pdmPortrait); vPageOut(hdc,4,1,"portrait"); EndDoc(hdc); #if 1 // DOC 2 ResetDC(hdc,pdmLandscape); di.lpszDocName = "Document2"; StartDoc(hdc,&di); vPageOut(hdc,1,2,"landscape"); ResetDC(hdc,pdmPortrait); // prepare for Doc 3 EndDoc(hdc); // DOC 3 di.lpszDocName = "Document3"; StartDoc(hdc,&di); vPageOut(hdc,1,3,"portrait"); ResetDC(hdc,pdmLandscape); ResetDC(hdc,pdmPortrait); ResetDC(hdc,pdmLandscape); vPageOut(hdc,2,3,"landscape"); EndDoc(hdc); #endif DeleteDC(hdc); return; }
void setAttributes(const char *printer, const int pdcID, AttributesUnion attributes) { HDC pdc = printerDCs[pdcID]; if (pdc != NULL) { DEVMODE *pDevMode = NULL; HANDLE hPrinter; if (OpenPrinter((LPTSTR)printer, &hPrinter, NULL) != 0) { int size = DocumentProperties(NULL, hPrinter, NULL, pDevMode, NULL, 0); pDevMode = (DEVMODE *)malloc(size); if (DocumentProperties(NULL, hPrinter, NULL, pDevMode, NULL, DM_OUT_BUFFER) == IDOK) { pDevMode->dmFields = 0; if (attributes.fields.PaperID > 0) { pDevMode->dmPaperSize = (short)attributes.fields.PaperID; pDevMode->dmFields |= DM_PAPERSIZE; } if (attributes.fields.Copies > 0) { pDevMode->dmCopies = (short)attributes.fields.Copies; pDevMode->dmFields |= DM_COPIES; } if (attributes.fields.Collate > 0) { if (attributes.fields.Collate == 1) { pDevMode->dmCollate = DMCOLLATE_TRUE; } else { pDevMode->dmCollate = DMCOLLATE_FALSE; } pDevMode->dmFields |= DM_COLLATE; } if (attributes.fields.Sides > 0) { pDevMode->dmDuplex = (short)attributes.fields.Sides; pDevMode->dmFields |= DM_DUPLEX; } if (attributes.fields.Chromaticity > 0) { if (attributes.fields.Chromaticity == 1) { pDevMode->dmColor = DMCOLOR_MONOCHROME; } else { pDevMode->dmColor = DMCOLOR_COLOR; } pDevMode->dmFields |= DM_COLOR; } if (attributes.fields.Orientation > 0) { if (attributes.fields.Orientation == 2) { pDevMode->dmOrientation = DMORIENT_LANDSCAPE; } else { pDevMode->dmOrientation = DMORIENT_PORTRAIT; } pDevMode->dmFields |= DM_ORIENTATION; } if (attributes.fields.XResolution > 0) { pDevMode->dmPrintQuality = (short)attributes.fields.XResolution; pDevMode->dmFields |= DM_PRINTQUALITY; } if (attributes.fields.YResolution > 0) { pDevMode->dmYResolution = (short)attributes.fields.YResolution; pDevMode->dmFields |= DM_YRESOLUTION; } if (pDevMode->dmFields != 0) { #ifdef PRINTING_DEBUG printf("Setting up print attributes.\n"); #endif /* PRINTING_DEBUG */ ResetDC(pdc, pDevMode); } } ClosePrinter(hPrinter); } } }