delphi 獲取印表機狀態,如缺紙等問題
uses
Printers,WinSpool;
type
TPrinterInfo = record
SeverName: PChar;
PrinterName: PChar;
ShareName: PChar;
PortName: PChar;
DriverName: PChar;
Comment: PChar;
Location: PChar;
DeviceMode: PDeviceModeW;
SepFile: PChar;
PrintProcessor: PChar;
DataType: PChar;
Parameters: PChar;
SecurityDescriptor: PSecurityDescriptor;
Attributes: Cardinal;
DefaultPriority: Cardinal;
StartTime: Cardinal;
UntilTime: Cardinal;
Status: Cardinal;
Jobs: Cardinal;
AveragePPM: Cardinal;
end;
function GetCurrentPrinterHandle: THandle;
var
Device, Driver, Port: array[0..255] of char;
hDeviceMode: THandle;
begin
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
if not OpenPrinter(@Device, Result, nil) then
RaiseLastWin32Error;
end;
function GetCurrentPrinterInformation: TPrinterInfo;
var
hPrinter: THandle;
pInfo: PPrinterInfo2;
bytesNeeded: DWORD;
begin
hPrinter := GetCurrentPrinterHandle;
try
Winspool.GetPrinter(hPrinter, 2, Nil, 0, @bytesNeeded);
pInfo := AllocMem(bytesNeeded);
try
Winspool.GetPrinter(hPrinter, 2, pInfo, bytesNeeded, @bytesNeeded);
Result.SeverName := pInfo^.pServerName;
Result.PrinterName := pInfo^.pPrinterName;
Result.ShareName := pInfo^.pShareName;
Result.PortName := pInfo^.pPortName;
Result.DriverName := pInfo^.pDriverName;
Result.Comment := pInfo^.pComment;
Result.Location := pInfo^.pLocation;
Result.DeviceMode := pInfo^.pDevMode;
Result.SepFile := pInfo^.pSepFile;
Result.PrintProcessor := pInfo^.pPrintProcessor;
Result.DataType := pInfo^.pDatatype;
Result.Parameters := pInfo^.pParameters;
Result.SecurityDescriptor := pInfo^.pSecurityDescriptor;
Result.Attributes := pInfo^.Attributes;
Result.DefaultPriority := pInfo^.DefaultPriority;
Result.StartTime := pInfo^.StartTime;
Result.UntilTime := pInfo^.UntilTime;
Result.Status := pInfo^.Status;
Result.Jobs := pInfo^.cJobs;
Result.AveragePPM := pInfo^.AveragePPM;
finally
FreeMem(pInfo);
end;
finally
ClosePrinter(hPrinter);
end;
end;
function GetDefaultPrinter(DefaultPrinter: PChar; var I: Integer): BOOL; stdcall;
external winspl name 'GetDefaultPrinterW';
procedure TForm3.cbb1Change(Sender: TObject);
var
PrinterInfo: TPrinterInfo;
begin
PrinterInfo := GetCurrentPrinterInformation;
memo1.Clear;
with memo1.Lines do
begin
Add('GENERAL INFORMATION');
Add('');
Add('ServerName: ' + PrinterInfo.SeverName);
Add('PrinterName: ' + PrinterInfo.PrinterName);
Add('ShareName: ' + PrinterInfo.ShareName);
Add('PortName: ' + PrinterInfo.PortName);
Add('DriverName: ' + PrinterInfo.DriverName);
Add('Comment: ' + PrinterInfo.Comment);
Add('Location: ' + PrinterInfo.Location);
Add('SepFile: ' + PrinterInfo.SepFile);
Add('PrintProcessor: ' + PrinterInfo.PrintProcessor);
Add('DataType: ' + PrinterInfo.DataType);
Add('Parameters: ' + PrinterInfo.Parameters);
Add('Attributes: ' + IntToStr(PrinterInfo.Attributes));
Add('DefaultPriority: ' + IntToStr(PrinterInfo.DefaultPriority));
Add('StartTime: ' + IntToStr(PrinterInfo.StartTime));
Add('UntilTime: ' + IntToStr(PrinterInfo.UntilTime));
Add('Status: ' + '0x' + IntToHex(PrinterInfo.Status,8));
Add('Jobs: ' + IntToStr(PrinterInfo.Jobs));
Add('AveragePPM: ' + IntToStr(PrinterInfo.AveragePPM));
Add('');
Add('DEVICEMODE INFORMATION');
Add('');
Add('DeviceName: ' + PrinterInfo.DeviceMode.dmDeviceName);
Add('SpecVersion: ' + IntToStr(PrinterInfo.DeviceMode.dmSpecVersion));
Add('DriverVersion: ' + IntToStr(PrinterInfo.DeviceMode.dmDriverVersion));
Add('Size: ' + IntToStr(PrinterInfo.DeviceMode.dmSize));
Add('DriverExtra: ' + IntToStr(PrinterInfo.DeviceMode.dmDriverExtra));
Add('Fields: ' + IntToStr(PrinterInfo.DeviceMode.dmFields));
Add('Orientation: ' + IntToStr(PrinterInfo.DeviceMode.dmOrientation));
Add('PaperSize: ' + IntToStr(PrinterInfo.DeviceMode.dmPaperSize));
Add('PaperLength: ' + IntToStr(PrinterInfo.DeviceMode.dmPaperLength));
Add('PaperWidth: ' + IntToStr(PrinterInfo.DeviceMode.dmPaperWidth));
Add('Scale: ' + IntToStr(PrinterInfo.DeviceMode.dmScale));
Add('Copies: ' + IntToStr(PrinterInfo.DeviceMode.dmCopies));
Add('DefaultSource: ' + IntToStr(PrinterInfo.DeviceMode.dmDefaultSource));
Add('PrintQuality: ' + IntToStr(PrinterInfo.DeviceMode.dmPrintQuality));
Add('Color: ' + IntToStr(PrinterInfo.DeviceMode.dmColor));
Add('Duplex: ' + IntToStr(PrinterInfo.DeviceMode.dmDuplex));
Add('YResolution: ' + IntToStr(PrinterInfo.DeviceMode.dmYResolution));
Add('TTOption: ' + IntToStr(PrinterInfo.DeviceMode.dmTTOption));
Add('Collate: ' + IntToStr(PrinterInfo.DeviceMode.dmCollate));
Add('LogPixels: ' + IntToStr(PrinterInfo.DeviceMode.dmLogPixels));
Add('BitsPerPel: ' + IntToStr(PrinterInfo.DeviceMode.dmBitsPerPel));
Add('PelsWidth: ' + IntToStr(PrinterInfo.DeviceMode.dmPelsWidth));
Add('PelsHeight: ' + IntToStr(PrinterInfo.DeviceMode.dmPelsHeight));
Add('DisplayFlags: ' + IntToStr(PrinterInfo.DeviceMode.dmDisplayFlags));
Add('DisplayFrequency: ' + IntToStr(PrinterInfo.DeviceMode.dmDisplayFrequency));
Add('ICMMethod: ' + IntToStr(PrinterInfo.DeviceMode.dmICMMethod));
Add('ICMintent: ' + IntToStr(PrinterInfo.DeviceMode.dmICMIntent));
Add('MediaType: ' + IntToStr(PrinterInfo.DeviceMode.dmMediaType));
Add('DitherType: ' + IntToStr(PrinterInfo.DeviceMode.dmDitherType));
Add('ICCManufacturer: ' + IntToStr(PrinterInfo.DeviceMode.dmICCManufacturer));
Add('ICCModel: ' + IntToStr(PrinterInfo.DeviceMode.dmICCModel));
Add('PanningWidth: ' + IntToStr(PrinterInfo.DeviceMode.dmPanningWidth));
Add('PanningHeight: ' + IntToStr(PrinterInfo.DeviceMode.dmPanningHeight));
end;
end;
procedure TForm3.FormShow(Sender: TObject);
begin
cbb1.Items.Assign(Printer.Printers);
cbb1.ItemIndex := 0;
cbb1.OnChange(nil);
end
status 狀態碼含義:
Printer status value/code |
Description |
---|---|
PRINTER_STATUS_BUSY 0x00000200 |
The printer is busy. |
PRINTER_STATUS_DOOR_OPEN 0x00400000 |
The printer door is open. |
PRINTER_STATUS_ERROR 0x00000002 |
The printer is in an error state. |
PRINTER_STATUS_INITIALIZING 0x00008000 |
The printer is initializing. |
PRINTER_STATUS_IO_ACTIVE 0x00000100 |
The printer is in an active input or output state. |
PRINTER_STATUS_MANUAL_FEED 0x00000020 |
The printer is in a manual feed state. |
PRINTER_STATUS_NOT_AVAILABLE 0x00001000 |
The printer is not available for printing. |
PRINTER_STATUS_NO_TONER 0x00040000 |
The printer is out of toner. |
PRINTER_STATUS_OFFLINE 0x00000080 |
The printer is offline. |
PRINTER_STATUS_OUTPUT_BIN_FULL 0x00000800 |
The printer's output bin is full. |
PRINTER_STATUS_OUT_OF_MEMORY 0x00200000 |
The printer has run out of memory. |
PRINTER_STATUS_PAGE_PUNT 0x00080000 |
The printer cannot print the current page. |
PRINTER_STATUS_PAPER_JAM 0x00000008 |
Paper is stuck in the printer. |
PRINTER_STATUS_PAPER_OUT 0x00000010 |
The printer is out of paper. |
PRINTER_STATUS_PAPER_PROBLEM 0x00000040 |
The printer has an unspecified paper problem. |
PRINTER_STATUS_PAUSED 0x00000001 |
The printer is paused. |
PRINTER_STATUS_PENDING_DELETION 0x00000004 |
The printer is being deleted as a result of a client's call to RpcDeletePrinter. No new jobs can be submitted on existing printer objects for that printer. |
PRINTER_STATUS_POWER_SAVE 0x01000000 |
The printer is in power-save mode.<182> |
PRINTER_STATUS_PRINTING 0x00000400 |
The printer is printing. |
PRINTER_STATUS_PROCESSING 0x00004000 |
The printer is processing a print job. |
PRINTER_STATUS_SERVER_OFFLINE 0x02000000 |
The printer is offline.<183> |
PRINTER_STATUS_SERVER_UNKNOWN 0x00800000 |
The printer status is unknown.<184> |
PRINTER_STATUS_TONER_LOW 0x00020000 |
The printer is low on toner. |
PRINTER_STATUS_USER_INTERVENTION 0x00100000 |
The printer has an error that requires the user to do something. |
PRINTER_STATUS_WAITING 0x00002000 |
The printer is waiting. |
PRINTER_STATUS_WARMING_UP 0x00010000 |
The printer is warming up. |
相關文章
- Android獲取狀態列高度Android
- created mounted 動態獲取資料渲染後,獲取DOM問題
- 獲取Mysql的狀態、變數MySql變數
- 印表機吸不進去紙怎麼辦 印表機不進紙的解決方法
- Spring狀態機(FSM),讓訂單狀態流轉如絲般順滑Spring
- 印表機提示列印錯誤怎麼解決 印表機狀態錯誤的方法
- [Android Framework]獲取U盤 SD 狀態AndroidFramework
- 獲取ChoiceGroup多選狀態下的值
- 印表機狀態錯誤怎麼解決 印表機一直顯示錯誤不能列印
- 印表機拒絕訪問是什麼問題 win10共享印表機拒絕訪問Win10
- TSC 243pro印表機偏移問題
- mysql odbc delphi連線問題MySql
- 微信小程式直播狀態介面如何獲取微信小程式
- 在聯網狀態下,有很多應用無法聯網問題,如360安全衛士, Smartscreen篩選器無法訪問, 部分網頁無法訪問等問題的解決方法網頁
- w10系統共享印表機怎麼開許可權_w10系統共享印表機訪問許可權如何獲取訪問許可權
- 均分紙牌問題
- SpringMVC的資料獲取問題SpringMVC
- 獲取上個月的問題
- win10印表機離線怎麼處理 win10取消印表機離線狀態怎麼操作Win10
- Android APP如何獲取裝置網線插拔的狀態AndroidAPP
- dom元素操作獲取等
- 狀態機
- DELPHI四捨五入問題解決
- 直播平臺原始碼,快速獲取當前狀態列高度原始碼
- 針式印表機怎麼設定紙張大小 針式列印紙張規格尺寸
- OC WKWebView 狀態列空白,頁面顯示不能佔滿,以及播放音樂等問題WebView
- Win10系統下印表機出現離線狀態的解除方法Win10
- Linux c程式中獲取shell指令碼輸出(如獲取system命令輸出)LinuxC程式指令碼
- 前端狀態管理與有限狀態機前端
- Delphi 技術的優缺點與應用
- Spark流式狀態管理(updateStateByKey、mapWithState等)Spark
- victoriaMetrics無法獲取抓取target的問題
- 如何獲取Vivo系統的懸浮窗許可權狀態
- React Native 跳轉到 APP 推送頁面並獲取推送狀態React NativeAPP
- Android 監聽鍵盤狀態變化,並獲取鍵盤高度Android
- Flutter: PageView/TabBarView等控制元件儲存狀態的問題解決方案 | 掘金技術徵文FlutterViewtabBar控制元件
- 有限狀態機
- 印表機狀態錯誤是怎麼回事 win7win10電腦顯示列印狀態錯誤怎麼解決Win7Win10