Delphi gets the printer device name and port name

zhaozj2021-02-08  201

uses Printers; {$ IFNDEF WIN32} const MAX_PATH = 144; {$ ENDIF} procedure TForm1.Button1Click (Sender: TObject); var pDevice: pChar; pDriver: pChar; pPort: pChar; hDMode: THandle; begin if PrintDialog1.Execute then begin GetMem (pDevice, cchDeviceName); GetMem (pDriver, MAX_PATH); GetMem (pPort, MAX_PATH); Printer.GetPrinter (pDevice, pDriver, pPort, hDMode); if lStrLen (pDriver) = 0 then begin GetProfileString ( 'Devices', PDEvice, '', PDRIVER, MAX_PATH); PDRIVER [POS (',', PDRIVER) - 1]: = # 0; end; if lstrlen (pport) = 0 THEN BEGIN GETPROFILESTRING ('Devices', PDEvice, '', Pport, max_path; lstrcpy (pport, @pport [lstrlen 2]); end; memo1.lines.add ('device: =' strpas (pdevice)); memo1.lines.add ('Driver: = ' STRPAS (PDRiver)); Memo1.Lines.Add (' port: = ' strPas (pport)); FreeMem (PDEvice, cchdevicename); FreeMem (PDRIVER, MAX_PATH); FreeMem (pport, max_path); END;

转载请注明原文地址:https://www.9cbs.com/read-1997.html

New Post(0)