trichview.support
Re: Selection of the paper source when printing |
Author |
Message |
Sergey Tkachenko |
Posted: 11/04/2004 21:17:43 TRichView uses printer settings of the application. These settings are accessible via global Printer object. Unfortunately, it does not have methods or properties for changing a paper source, but you can use WinAPI functions. Below is the sample code. I wrote it directly in the newsgroup reader, so some misprints are possible. The original of this code is in RichViewActions, PageSetupRVFrm.pas. uses Printers; type TBinName = array [0..23] of Char; TBinNames = array [0..1000] of TBinName; PBinNames = ^TBinNames; TWordArray = array [0..1000] of Word; PWordArray = ^TWordArray; procedure GetAvailablePaperSources; var ADevice, ADriver, APort: array[0..79] of Char; ADeviceMode: THandle; DevMode: PDeviceMode; BinCount: Integer; begin Printer.GetPrinter(ADevice,ADriver,APort,ADeviceMode); if ADeviceMode<>0 then begin DevMode := PDeviceMode(GlobalLock(ADeviceMode)) end else raise Exception.Create('Error initializing printer'); BinCount := DeviceCapabilities(ADevice, APort, DC_BINNAMES, nil, DevMode); GetMem(BinNames, sizeof(TBinName)*BinCount); GetMem(BinCodes, sizeof(Integer)*BinCount); try DeviceCapabilities(ADevice, APort, DC_BINNAMES, Pointer(BinNames), DevMode); DeviceCapabilities(ADevice, APort, DC_BINS, Pointer(BinCodes), DevMode); { At this point, BinNames[0..BinCount-1] contain names of paper sources, BinCodes[0..BinCount-1] contain their codes that can be used in SetPaperSource. Store them somewhere. } finally FreeMem(PaperNames); FreeMem(PaperCodes); end; GlobalUnlock(ADeviceMode); end; procedure SetPaperSource(PaperSource: Integer); var ADevice, ADriver, APort: array[0..79] of Char; ADeviceMode: THandle; DevMode: PDeviceMode; begin Printer.GetPrinter(ADevice,ADriver,APort,ADeviceMode); if ADeviceMode<>0 then begin DevMode := PDeviceMode(GlobalLock(ADeviceMode)) end else raise Exception.Create('Error initializing printer'); DevMode.dmFields := DevMode.dmFields or DM_DEFAULTSOURCE; DevMode.dmDefaultSource := PaperSource; GlobalUnlock(ADeviceMode); Printer.SetPrinter(ADevice,ADriver,APort,ADeviceMode); end; > Hi, > > I search the possibility to change the paper source on the printer. > I have in the first feed, some paper with header and in the second, I have > some blank paper. I want to print a document and select the first feed and > print a copy of this document on the paper from the second feed. > So is it possible to change the paper source? > > Thanks for your help. > Phil. |
Powered by ABC Amber Outlook Express Converter