先定義好my 的長和寬:2150和1400然後調用以
sh1.pagesetup.papersize:=GetPaperno;
function GetPaperno:integer;
var
printername:string;
dwPapers: DWord;
lpwPapers: array[0..255] of Word;
papersize:array[0..63,0..1] of integer;
begin
result:=0;
printername:=printer.Printers[printer.PrinterIndex];
dwPapers:=DeviceCapabilities(PChar(PrinterName),'LPT1',DC_PAPERS,@lpwPapers,nil);
DeviceCapabilities(PChar(PrinterName),'LPT1',DC_PAPERsize,@Papersize,nil);
while (dwPapers > 0)do
begin
// showmessage('u:'+inttostr(Papersize[dwpapers,0]));
// showmessage('u:'+inttostr(Papersize[dwpapers,1]));
if (Papersize[dwpapers,0]=2150) and (Papersize[dwpapers,1]=1400) then
begin
result:=lpwPapers[dwPapers];
// showmessage(inttostr(lpwPapers[dwPapers]));
end;
{
case DWORD(lpwPapers[dwPapers]) of
DMPAPER_USER: showmessage(inttostr(lpwPapers[dwPapers]));
DMPAPER_A3: showmessage(inttostr(lpwPapers[dwPapers]));
DMPAPER_A4: showmessage(inttostr(DWORD(lpwPapers[dwPapers])));
DMPAPER_B5: showmessage(inttostr(lpwPapers[dwPapers]));
end;
}
dwPapers:=dwPapers-1;
end;
end;