找回密码
 加入
搜索
查看: 6589|回复: 4

[系统综合] 请教高手,delphi 改成au3可以吗?

[复制链接]
发表于 2014-9-4 17:31:04 | 显示全部楼层 |阅读模式
本帖最后由 pchome2000 于 2014-9-4 19:01 编辑

请教高手,delphi 改成au3可以吗?

uses Printers, WinSpool;

type
   TPointWord = packed record
     X: LongWord;
     Y: LongWord;
   end;

   TPaperName = array[0..63] of Char;
   PPaperInfo = ^TPaperInfo;
   TPaperInfo = packed record
     papername: TPapername; { display name of the paper }
     paperID: Smallint; { DMPAPER_* ID }
     papersize: TPoint; { Size in 0.1 mm }
   end;
   TPaperInfos = array of TPaperInfo;
   TPaperSizes = array of TPoint;
   TPrinterResolutions= array of TPointWord;

procedure GetPapernames(sl: TStrings; index: Integer);
type
   TPaperNameArray = array[1..High(Integer) div Sizeof(TPaperName)] of TPaperName;
   PPapernameArray = ^TPaperNameArray;
   TPaperArray = array[1..High(Integer) div Sizeof(Word)] of Word;
   PPaperArray = ^TPaperArray;
var
   Device, Driver, Port: array[0..255] of Char;
   hDevMode: THandle;
   i, numPaperNames, numPapers, temp: Integer;
   pPaperNames: PPapernameArray;
   pPapers: PPaperArray;
begin
   Assert(Assigned(sl));
   Printer.PrinterIndex := index;
   Printer.GetPrinter(Device, Driver, Port, hDevmode);
   numPaperNames := WinSpool.DeviceCapabilities(Device, Port, DC_PAPERNAMES, nil, nil);
   numPapers := WinSpool.DeviceCapabilities(Device, Port, DC_PAPERS, nil, nil);
   if numPapers <> numPaperNames then
   begin
     raise Exception.Create('DeviceCapabilities reports different number of papers and '+ ' paper names!');
   end;
   if numPaperNames > 0 then
   begin
     GetMem(pPaperNames, numPaperNames * Sizeof(TPapername));
     GetMem(pPapers, numPapers * Sizeof(Word));
     try
       WinSpool.DeviceCapabilities(Device, Port, DC_PAPERNAMES, Pchar(pPaperNames), nil);
       WinSpool.DeviceCapabilities(Device, Port, DC_PAPERS, Pchar(pPapers), nil);
       sl.clear;
       for i := 1 to numPaperNames do
       begin
         temp := pPapers^;
         sl.addObject(pPaperNames^, TObject(temp));
       end;
     finally
       FreeMem(pPaperNames);
       if pPapers <> nil then
         FreeMem(pPapers);
     end;
   end;
end;

procedure GetPapersizes(var sizes: TPaperSizes; index: Integer);
var
   Device, Driver, Port: array[0..255] of Char;
   hDevMode: THandle;
   numPapers: Integer;
begin
   Printer.PrinterIndex := index;
   Printer.GetPrinter(Device, Driver, Port, hDevmode);
   numPapers := WinSpool.DeviceCapabilities(Device, Port, DC_PAPERS, nil, nil);
   SetLength(sizes, numPapers);
   if numPapers > 0 then
     WinSpool.DeviceCapabilities(Device, Port, DC_PAPERSIZE, PChar(@sizes[0]), nil);
end;

procedure GetPaperInfo(var infos: TPaperInfos; index: Integer);
var
   sizes: TPaperSizes;
   sl: TStringlist;
   i: Integer;
begin
   sl := Tstringlist.Create;
   try
     GetPaperNames(sl, index);
     GetPaperSizes(sizes, index);
     Assert(sl.count = Length(sizes));
     SetLength(infos, sl.count);
     for i := 0 to sl.count - 1 do
     begin
       StrPLCopy(infos.papername, sl, Sizeof(TPapername) - 1);
       infos.paperID := LoWord(Longword(sl.Objects));
       infos.papersize := sizes;
     end;
   finally
     sl.Free;
   end;
end;

//实现过程
var
  ADevice,ADriver, APort:array[0..255] of char;
  infos: TPaperInfos;
  DeviceHandle,hPrinter:THandle;
  PDMode:     PDEVMODE;
  P:Pchar;
  i,iIndex:integer;
begin
  GetPaperInfo(infos, Printer.PrinterIndex);  //获取纸张列表
Printer.GetPrinter(ADevice,ADriver, APort, DeviceHandle); //取打印机数据
pDMode := GlobalLock(DeviceHandle);
  ListBox1.Items.Clear;
  for i:=low(infos) to high(infos) do begin
     GetMem(P, sizeof(TPaperInfo));
     move(infos, p^, sizeof(TPaperInfo));
     iIndex:=ListBox1.Items.AddObject(infos.papername, Tobject(P));
     if pDMode^.dmPaperSize=infos.paperID then begin //关键就是对比dmPaperSize参数
      ListBox1.ItemIndex := iIndex
     end;
  end;
  GlobalUnlock(DeviceHandle);
end;
发表于 2014-9-4 18:19:04 | 显示全部楼层
如果你确定你贴的代码是vb的话,我就给你改了
发表于 2014-9-5 08:56:11 | 显示全部楼层
Delphi为什么要改成AU3,按理说Delphi的效率比AU3更高...
 楼主| 发表于 2014-9-5 11:57:54 | 显示全部楼层
想用au3直接操作,
发表于 2014-9-5 12:43:53 | 显示全部楼层
不懂 啊   懂delphy 还用au3?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-23 00:59 , Processed in 0.076660 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表