線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3074
推到 Plurk!
推到 Facebook!

有辦法判斷列表機的種類嗎??

答題得分者是:william
jzchen
一般會員


發表:8
回覆:21
積分:5
註冊:2002-06-01

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-01-06 17:24:49 IP:61.30.xxx.xxx 未訂閱
請問各為前輩... 有辦法去判斷列表機的是屬於點陣式,噴墨還是雷射嗎?? 因為最近遇到一個問題必須去區分列表機的種類...    謝謝各為前輩 < >< >
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-01-06 17:45:30 IP:147.8.xxx.xxx 未訂閱
引言: 請問各為前輩... 有辦法去判斷列表機的是屬於點陣式,噴墨還是雷射嗎?? 因為最近遇到一個問題必須去區分列表機的種類... 謝謝各為前輩 < >< >
I don't think there is anyway to tell.... Try the api: GetDeviceCaps and CreateIC. Usually the laser printer has higher dpi with aspect ratio 1:1 (e.g. 300x300, 600x600, 1200x1200)... Perhaps you could let the end user decide the type?
jzchen
一般會員


發表:8
回覆:21
積分:5
註冊:2002-06-01

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-01-06 19:55:34 IP:61.30.xxx.xxx 未訂閱
Sorry ....william 前輩.... 我不知道怎麼用這兩個api.... 我看了好久只知其一不知其二....所以try不出來 可否麻煩你在說明詳細點.... CreateIC( LPCTSTR lpszDriver,// pointer to string specifying driver name LPCTSTR lpszDevice,// pointer to string specifying device name LPCTSTR lpszOutput,// pointer to string specifying port or file name CONST DEVMODE *lpdvmInit // pointer to optional initialization data ); GetDeviceCaps( HDC hdc, // device-context handle int nIndex // index of capability to query ); 謝謝前輩....
banson1716
高階會員


發表:55
回覆:182
積分:167
註冊:2002-04-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-01-07 07:11:12 IP:61.223.xxx.xxx 未訂閱
//取得印表機的各訊息 unit PrnUnit; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, WinSpool, StdCtrls, ComCtrls, ExtCtrls; type TForm1 = class(TForm) Button4: TButton; PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; TabSheet3: TTabSheet; TabSheet4: TTabSheet; Memo1: TMemo; Memo2: TMemo; Memo3: TMemo; Memo4: TMemo; Button1: TButton; TabSheet5: TTabSheet; Panel1: TPanel; procedure GetInfo1; procedure GetInfo2; procedure GetInfo5; procedure GetDrvInfo; procedure PageControl1Change(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1 : TForm1; hGlobal : THandle; implementation {$R *.DFM} function GetPrinterName : String; var Buffer : Array[0..255] of Char; S : String; begin GetProfileString('windows', 'device', ',,,', buffer, 256); S := StrPas(Buffer); Result :=Copy(S, 1, Pos(',', S)-1); end; procedure TForm1.GetInfo1; var PI1 : PPrinterInfo1; dwNeeded : DWORD; dwCopied : DWORD; begin Memo1.Lines.Clear; EnumPrinters(PRINTER_ENUM_LOCAL, '', 1, PI1, 0, DWNEEDED, DWCOPIED); hGlobal := GlobalAlloc(GHND, DWNEEDED); PI1 := PPrinterInfo1(GlobalLock(hGlobal)); EnumPrinters(PRINTER_ENUM_LOCAL, '', 1, PI1, DWNEEDED, DWNEEDED, DWCOPIED); with Memo1.Lines, PI1^ do begin Add('Description = ' pDescription); Add('Name = ' pName); Add('Comment = ' pComment); end; // 昢碭搿儰?櫡?譔 GlobalUnlock(hGlobal); GlobalFree(hGlobal); end; procedure TForm1.GetInfo2; var PI2 : PPrinterInfo2; dwNeeded : DWORD; dwCopied : DWORD; begin Memo2.Lines.Clear; EnumPrinters(PRINTER_ENUM_LOCAL, '', 2, PI2, 0, DWNEEDED, DWCOPIED); hGlobal := GlobalAlloc(GHND, DWNEEDED); PI2 := PPrinterInfo2(GlobalLock(hGlobal)); EnumPrinters(PRINTER_ENUM_LOCAL, '', 2, PI2, DWNEEDED, DWNEEDED, DWCOPIED); with Memo2.Lines, PI2^ do begin If Assigned(pServerName) Then Add('Server Name = ' pServerName); If Assigned(pPrinterName) Then Add('Printer Name = ' pPrinterName); If Assigned(pShareName) Then Add('Share Name = ' pShareName); If Assigned(pPortName) Then Add('Port Name = ' pPortName); If Assigned(pDriverName) Then Add('Driver Name = ' pDriverName); // If Assigned(pComment) Then Add('Comment = ' pComment); // If Assigned(pLocation) Then Add('Location = ' pLocation); // If Assigned(pSepFile) Then Add('SepFile = ' pSepFile); If Assigned(pPrintProcessor) Then Add('Print Processor = ' pPrintProcessor); If Assigned(pDatatype) Then Add('Data Type = ' pDatatype); // If Assigned(pParameters) Then Add('Parameters = ' pParameters); with pDevMode^ do begin Case dmOrientation of 1 : Add('dmOrientation = DMORIENT_PORTRAIT'); 2 : Add('dmOrientation = DMORIENT_LANDSCAPE'); end; end; end; GlobalUnlock(hGlobal); GlobalFree(hGlobal); end; procedure TForm1.GetInfo5; var PI5 : PPrinterInfo5; dwNeeded : DWORD; dwCopied : DWORD; begin Memo3.Lines.Clear; EnumPrinters(PRINTER_ENUM_LOCAL, '', 5, PI5, 0, DWNEEDED, DWCOPIED); hGlobal := GlobalAlloc(GHND, DWNEEDED); PI5 := PPrinterInfo5(GlobalLock(hGlobal)); EnumPrinters(PRINTER_ENUM_LOCAL, '', 5, PI5, DWNEEDED, DWNEEDED, DWCOPIED); with Memo3.Lines, PI5^ do begin Add('Printer Name = ' pPrinterName); Add('Port Name = ' pPortName); Add('DeviceNotSelectedTimeout = ' IntToStr(DeviceNotSelectedTimeout) ' ms.'); Add('TransmissionRetryTimeout = ' IntToStr(TransmissionRetryTimeout) ' ms.'); end; GlobalUnlock(hGlobal); GlobalFree(hGlobal); end; procedure TForm1.GetDrvInfo; var DI : PDriverInfo3; dwNeeded : DWORD; dwCopied : DWORD; begin Memo4.Lines.Clear; EnumPrinterDrivers(Nil, Nil, 3, DI, 0, dwNeeded, dwCopied); hGlobal := GlobalAlloc(GHND, DWNEEDED); DI := PDriverInfo3(GlobalLock(hGlobal)); EnumPrinterDrivers(Nil, Nil, 3, DI, dwNeeded, dwNeeded, dwCopied); With Memo4.Lines, DI^ do begin Add('Driver Name = ' pName); Add('Environment = ' pEnvironment); Add('Driver Path = ' pDriverPath); Add('Data File = ' pDataFile); Add('Config File = ' pConfigFile); end; GlobalUnlock(hGlobal); GlobalFree(hGlobal); end; procedure TForm1.PageControl1Change(Sender: TObject); begin Case PageControl1.ActivePage.PageIndex of 0 : GetInfo1; 1 : GetInfo2; 2 : GetInfo5; 3 : GetDrvInfo; end; end; procedure TForm1.Button4Click(Sender: TObject); var hPrinter : THandle; PD : TPrinterDefaults; begin {'SAMSUNG SI-630A ColorArt'} OpenPrinter(PChar(GetPrinterName), hPrinter, @PD); PrinterProperties(Handle, hPrinter); ClosePrinter(hPrinter); end; procedure TForm1.Button1Click(Sender: TObject); begin Close; end; end. // 取得目前預設的印表機名稱 unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} Function GetDefaultPrinterName : String; var iSize : Integer; sIniFile, sSection, sKeyName : PChar; begin iSize := 256; sIniFile := 'win.ini'; sSection := 'windows'; sKeyName := 'device'; SetLength(Result,iSize); GetPrivateProfileString(sSection,sKeyName,nil,PChar(Result), iSize,sIniFile); Result := Copy(Result, 0, Pos(',',Result)-1);end;procedure TForm1.Button1Click(Sender: TObject); begin caption:=GetDefaultPrinterName; end; end.
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-01-07 10:02:48 IP:147.8.xxx.xxx 未訂閱
banson1716 has provided an excellent example of getting priners' information. Since you're using Delphi, you may want to take a look at the Printer (global variablt) within the Printers unit. Because you cannot get the printer's canvas without starting a printer job, you need to use CreateIC to create an information canvas for getting the needed information. e.g.
var
    IC: HDC;
    ADeviceMode: THandle;
    DeviceMode: PDeviceMode;
    ADevice, ADriver, APort: PAnsiChar;
    DpiX,DpiY: integer;
begin
    ADevice := StrAlloc(255);
    ADriver := StrAlloc(255);
    APort   := StrAlloc(255);
    try
        Printer.GetPrinter(ADevice,ADriver,APort,ADeviceMode);
        DeviceMode := GlobalLock(ADeviceMode);
        try
            IC := CreateIC(ADriver,ADevice,nil,DeviceMode);
        finally
            GlobalUnlock(ADeviceMode);
        end;
        if IC<>0 then begin
            try
                DpiX := GetDeviceCaps(IC,LOGPIXELSX);
                DpiY := GetDeviceCaps(IC,LOGPIXELSY);
            finally
                DeleteDC(IC);
            end; 
        end;
    finally
        StrDispose(ADevice);
        StrDispose(ADriver);
        StrDispose(APort);
    end;
end;
jzchen
一般會員


發表:8
回覆:21
積分:5
註冊:2002-06-01

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-01-09 09:55:39 IP:61.30.xxx.xxx 未訂閱
感謝william及banson1716前輩.... 小弟將上面兩個方法都try過了.... 都可以得到資訊 但是用banson1716前輩的方法時 會出現一個錯誤訊息...小弟不才實在是找不出原因... 不知道各為前輩有沒有抓過影印機充當列表機的資訊(例如:全錄的Xerox) 我抓到的值是... DpiX:1928658432 DpiY:1928658968 不知道為什麼會這樣... 其他列表機都正常.... 最多也不可能這麼大.... 傷腦筋...
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-01-09 10:58:36 IP:147.8.xxx.xxx 未訂閱
引言:不知道各為前輩有沒有抓過影印機充當列表機的資訊(例如:全錄的Xerox) 我抓到的值是... DpiX:1928658432 DpiY:1928658968 不知道為什麼會這樣... 其他列表機都正常.... 最多也不可能這麼大.... 傷腦筋...
No idea... What is the dpi in printer properties (if any)? Maybe you could replace the IC with actual printer's canvas (need to start a print job) ,
jzchen
一般會員


發表:8
回覆:21
積分:5
註冊:2002-06-01

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-01-13 14:26:56 IP:61.30.xxx.xxx 未訂閱
william前輩..... 改成 Printer.BeginDoc; DpiX := GetDeviceCaps(Printer.Canvas.Handle,LOGPIXELSX); DpiY := GetDeviceCaps(Printer.Canvas.Handle,LOGPIXELSY); 這樣也是抓到 DpiX:1928658432 DpiY:1928658968 真是怪怪....為什麼會這樣... 我總覺得這個值實在是大了點...傷腦筋???
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-01-13 14:56:37 IP:147.8.xxx.xxx 未訂閱
引言:william前輩..... 改成 Printer.BeginDoc; DpiX := GetDeviceCaps(Printer.Canvas.Handle,LOGPIXELSX); DpiY := GetDeviceCaps(Printer.Canvas.Handle,LOGPIXELSY); 這樣也是抓到 DpiX:1928658432 DpiY:1928658968 真是怪怪....為什麼會這樣... 我總覺得這個值實在是大了點...傷腦筋???
Woo... How about other info (e.g. HORZRES,VERTRES, etc.)?
jzchen
一般會員


發表:8
回覆:21
積分:5
註冊:2002-06-01

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-01-13 16:19:16 IP:61.30.xxx.xxx 未訂閱
william前輩..... 其他的應該都正常....例如: HP LaserJet 4V DpiX:600 DpiY:600 Horz:4676 Vert:6814 HP DeskJet 690C DpiX:300 DpiY:300 Horz:2400 Vert:3281 Xerox -information DpiX:1928658432 DpiY:1928658968 Horz:1242296 Vert:1928659488 Epson LQ-1070C DpiX:180 DpiY:180 Horz:1443 Vert:1931 HP DeskJet 690C DpiX:300 DpiY:300 IBM5577 DpiX:180 DpiY:180 Horz:1398 Vert:1979 DL3400 DpiX:180 DpiY:180 Horz:1443 Vert:2104 以上是我這邊測的印表機... HP LaserJet 4V 是雷射印表機... HP DeskJet 690C是噴墨印表機... Xerox -information是影印機兼印表機... 其他都是點陣式....
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-01-13 16:43:31 IP:147.8.xxx.xxx 未訂閱
Hi jzchen, I have no idea why Xerox has such a strange behavior. I think they are info returned by the printer driver... Refering to your original question, it seems that here is no way to differentiate a laser printer from the ink jet/dot matrix 
jzchen
一般會員


發表:8
回覆:21
積分:5
註冊:2002-06-01

發送簡訊給我
#12 引用回覆 回覆 發表時間:2003-01-13 17:16:07 IP:61.30.xxx.xxx 未訂閱
感謝william前輩及banson1716前輩 我想我要的問題大概已經解決了.... 只有那台...Xerox 但是那應該是例外狀況.... 我在
系統時間:2024-05-05 17:39:46
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!