Delphi 프린터 설정

4221 단어
Delphi     2009-02-03 19:192009-02-03 15:37http://blog.sina.com.cn/s/blog_46666bf90100001f.html   :   
     Borland       。           ,         getprinters          ,   WIN.INI   。
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(pPort) + 2]);
end;
FreeMem(pDevice,cchDeviceName);
FreeMem(pDriver,MAX_PATH);
FreeMem(pPort,MAX_PATH);
end;
end;

·             :
      ,              ,    WindowsAPI  ENumJobs             。
                         。
(1)       ;
(2)   Form1     Button     Memo  ,         ;
(3)  Button1 OnClick  。
procedure TForm1.Button1Click(Sender :TObject);
var
LPHandle : THandle;//     
LPStrBuf : Array [0..256] of Char;//     
NoJobs : Word; //        
s : LongWord; //Job_Info    
Job_Info : Array [0..10] of JOB_INFO_1; //      
cbNeeded : Cardinal;
cReturned : Cardinal; //      
ret : LongBool;
I : integer;
begin
LPStrBuf := 'HPLaserJet';//      
//     
if OpenPrinter() then
begin
MessageBox(Form1.Handle,'       。','  ',MB_OK);
Exit;
end;
s := SizeOf(Job_Info);
cbNeeded := 0;
cReturned := 0;
NoJobs := 10;
ret := ENumJobs(LPHandle,0,NoJobs,1,@Job_Info,s,cbNeeded,cReturn);
//        
Memo1.Lines.Add('      :' + InttoStr(cReturned) + ' 。');
for I := 0 to cReturned -1 do
Memo1.Lines.Add(' ' + IntToStr(I+1) + '      ' + IntToStr(Job_Info[I].TotalPages) + ' 。');
end;
        ,              LPStrBuf   ,    Windows   “    ”              。

·           :
 Windows Win.ini             :
[Windows]
load = 
run =
NullPort = None
device = HPLaserJetIII,HPPCL5MS,LPT1
.............
  Windows  device                  。    WindowsAPI  GetProfileString     。  GetProfileString     :
DWORDGetProfileString(
LPCTSTRlpAppName, //        
LPCTSTRlpKeyName, //        
LPCTSTRlpDefault, //             
LPTSTRlpReturnedString, //            
DWORDnSize //lpReturnedString    
);
    :
(1)        ;
(2)   Form1     Button     Edit  ,        ;
(3)  Button1 OnClick  。
procedure TForm1.Button1Click(Sender : TObject);
var 
AppName : Array [0..256] of Char; //      
KeyName : Array [0..256] of Char; //      
DefaultString : Array [0..256] of Char; //              
ReturnedString : Array [0..256] of Char; //           
begin
AppName := 'Windows';//   
KeyName := 'device'; //   
GetProfileString(AppName,KeyName,DefaultString,ReturnedString,Sizeof(ReturnedString));
Edit1.Text := ReturnedString;//    
end;
       win.ini    。 
 

전재 대상:https://www.cnblogs.com/zsdentist/articles/1562889.html

좋은 웹페이지 즐겨찾기