//提取exe或dll文件32*32图标。命令行参数为文件路径和名称,图标生成到C:\。
program Project2;{$APPTYPE CONSOLE}uses
  Windows,SysUtils,Graphics,ShellApi;var
  ico:TIcon; //默认图标是32*32
  n,i:Integer;
  inf,f:String;
  consoleHandle:THandle;begin
  if ParamCount<1 then
  begin
    WriteLn('The file''s path and name is required!');
    Exit;
  end;
  for i:=1 to ParamCount do
if i<>ParamCount then
f:=f+ParamStr(i)+' '
else
f:=f+ParamStr(i);
  if not FileExists(f) then
  begin
    WriteLn('File doesn''t exist!');
    Exit;
  end;
  //统计图标个数:
  consoleHandle:=GetStdHandle(STD_OUTPUT_HANDLE);
  n:=ExtractIcon(consoleHandle,PChar(f),UInt(-1));
  if n=0 then
  begin
    WriteLn('Find no icons!');
    Exit;
  end;
  inf:='Extract successfully:';
  try
    ico:=TIcon.Create;
    for i:=0 to n-1 do
    begin
      //获得图标句柄:
      ico.Handle:=ExtractIcon(consoleHandle,PChar(f),i);
      ico.SaveToFile('c:\'+inttostr(i+1)+'.ico');
      ico.ReleaseHandle;
      inf:=inf+#13+#10+'c:\'+InttoStr(i+1)+'.ico';
    end;
  finally
    ico.Free;
  end;
  WriteLn(inf);end.生成的exe100多KB。我知道可以用ASPack等软件来压缩。但我想通过修改源代码来减小体积。
是不是存在这样的方法来减小体积:
去除uses单元的内容并且自己声明用到的函数。如果是,具体怎样修改?到底修改后的源代码应该是怎样的呢?

解决方案 »

  1.   

    全部改用Win32 API呼叫,不用VCL的单元,肯定要小很多,但是看你编起来还有这么好写?总要付出代价。看起来你这程序也没有办法减少引用的单元了吧。
      

  2.   

    怎样做到——全部改用Win32   API呼叫,不用VCL的单元
      

  3.   

    只使用Windows,ShellApi;
    这两个单元.
      

  4.   

    只使用Windows,ShellApi; 
    这两个单元?
    怎么做到阿?直接删除了SysUtils,Graphics很显然不行。
      

  5.   

    一个很简单的办法,但是需要耐心。
    从上面的Uses单元中把用到的部分摘出来,复制这个pas文件中,然后Del 所有的引用单元,如果提示缺少XXXX,还得再找。