need an image tool to extract bitmap resources from Windows files.

Hi all,
I need an image tool to extract bitmap resources from Windows files. When I choose a directory or driver, it must can extract all the bmps/icons from this directory or the driver.

Thanks, supwang
LVL 2
SupWangAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
YensidModConnect With a Mentor Commented:
PAQed per request/recommendation & Points refunded

YensidMod
Community Support Moderator
0
 
JaccoCommented:
You may want to take a look at jcl. (JEDI code library)

http://www.delphi-jedi.org/Jedi:CODELIBJCL:21737

There is a unit inside jclPeImage.pas

It can get anything from a PE file. EXE DLL DRV etc.

Regards Jacco.
0
 
SupWangAuthor Commented:
Hi Jacco,
It seems that the "JCL" just for D4/D5, but I am using D3.
I dont need the source. just need a image tool.
I find many image tools in here: http://www.torry.net/tools_imagetools.htm

But I dont know which can extract all the bmps/icons from a directory or a driver.

Regards, supwang
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
SlavakCommented:
Hi, Supwang.

Thanks for great idea. I spend many times looking for icons.

So, it's a code:

Const
 IconN : Integer = 0;
 BmpN  : Integer = 0;


function SaveResource(hModule : THandle; lpszType : PChar;
                      lpszName : PChar;  lParam   : Integer) : Boolean; stdcall;
Var
 Dst   : String;
 HI    : HIcon;
 Info  : TIconInfo;
Begin
 Result := True;

 Dst := PChar(lParam);

 If (lpszType = RT_BITMAP) Then Begin
  With TBitmap.Create Do Begin
   Try
    Handle := LoadBitmap(hModule, lpszName);
    SaveToFile(Dst + Format('Bmp%d.bmp', [BmpN]));
    Inc(BmpN);
   finally
    Handle := 0;
    Free;
   end;
  End;
 End;

 If (lpszType = RT_GROUP_ICON) Then Begin
  With TIcon.Create Do Begin
   Try
    HI := LoadIcon(hModule, lpszName);
    If GetIconInfo(HI, Info) and Info.fIcon Then Begin
     Handle := HI;
     SaveToFile(Dst + Format('Icon%d.ico', [IconN]));
    End;
    Inc(IconN);
//    Free;
   except
   end;
   Free;
  End;
 End;

End;

procedure ExtractIconsFromFile(AFile, Dst : String);
Var
 Lib : THandle;
Begin
 Lib := LoadLibraryEx(PChar(AFile), 0, LOAD_LIBRARY_AS_DATAFILE);
 If Lib = 0 Then Exit;
 Try
  EnumResourceNames(Lib, RT_BITMAP, @SaveResource, Integer(Dst));

  EnumResourceNames(Lib, RT_GROUP_ICON, @SaveResource, Integer(Dst));


 finally
  FreeLibrary(Lib);
 end;
End;

procedure ExtractIconsFromFolder(Src, Dst : String);
Var
 Rec : TSearchRec;
 Res : Integer;
 Ext : String;
Begin
 If Src[Length(Src)] <> '\' Then
  Src := Src + '\';

 If Dst[Length(Dst)] <> '\' Then
  Dst := Dst + '\';

 Res := FindFirst(Src + '*.*', faAnyFile, Rec);
 Try
  While Res = 0 Do Begin
   Application.ProcessMessages;

   If Rec.Name[1] = '.' Then Begin
    Res := FindNext(Rec);
    Continue;
   End;

   If (faDirectory and Rec.Attr) <> 0 Then
    ExtractIconsFromFolder(Src + Rec.Name, Dst)

   Else Begin
    Ext := LowerCase(ExtractFileExt(Rec.Name));

    If (Ext = '.ico') Then Begin
     CopyFile(PChar(Src + Rec.Name), PChar(Dst + Format('Icon%d.ico', [IconN])), False);
     Inc(IconN);
    End;

    If (Ext = '.bmp') Then Begin
     CopyFile(PChar(Src + Rec.Name), PChar(Dst + Format('Bmp%d.bmp', [BmpN])), False);
     Inc(BmpN);
    End;

    If (Ext = '.dll') or (Ext = '.exe') Then
     ExtractIconsFromFile(Src + Rec.Name, Dst);
   End;

   Res := FindNext(Rec);
  End;
 finally
  FindClose(Rec);
 end;
End;

--------------------------------------------


procedure TForm1.Button1Click(Sender: TObject);
begin
 ExtractIconsFromFolder('C:\Windows', 'C:\Icons');
end;


There are some problems with extracting icons (sometimes it raise errors). I comment "Free" method, and it have memory leak. But the function should be in small console application that closed after the function (I good enough for me :) )

0
 
SupWangAuthor Commented:
Hi Slavak,
Thanks.  :-)
But why I extract 9500 bitmaps from "Program Files", have 8000 bitmaps is 0 bytes file?

Thanks, supwang
0
 
SupWangAuthor Commented:
Hi Slavak,
I try to extract bmps/icons from "c:\Program Files\Borland\Delphi 3\Bin" and  "c:\Program Files\Borland\Delphi4\Bin", but just get some 0 size files.

Regards, supwang
0
 
SlavakCommented:
Hi,

I tried it on C:\Program files and get 3113 not empty files. I did in on Win2K system using Delphi  5. In debugger I sometimes get exception "Bitmap image not valid" for icons. It happends in SaveToFile function. Maybe ver. 3,4 of Delphi opens a file before check the image.
0
 
SupWangAuthor Commented:
Hi Slavak,
I am using D3 + win98.  :-(  more ideas?

Regards, supwang
0
 
SlavakCommented:
Run it in debugger :), I have not D3, so cannot check it, sorry.
0
 
SupWangAuthor Commented:
Hi Slavak,
Can you send me the exe files?
Put two edit components on the form. one is source path, another is target path.
my email is addsup@163.net

Thanks, supwang
0
 
SlavakCommented:
done
0
 
SlavakCommented:
done
0
 
SupWangAuthor Commented:
Hi Slavak,
I use your program and try this path "c:\Program Files\Borland\Delphi 3\BIN", get all the 0 size bmp files.

and try "c:\Program Files\Borland\Delphi4", all 0 size bmp files.

Regards, supwang
0
 
SlavakCommented:
Hi,

I don't know what a problem. On my computer it works. If files is '.bmp' or '.ico' then I just copy them, so I have not idea why at your computer all files with 0 length :(

Regards
0
 
SupWangAuthor Commented:
Don't know, I had already tried it on two computers. :-(
0
 
SlavakCommented:
Did you tried to run it from IDE?
0
 
SupWangAuthor Commented:
Now I try it at IDE three times, but the result as same as using your exe files.

Regards, supwang
0
 
SlavakCommented:
Did you get any exceptions?
0
 
SupWangAuthor Commented:
Yes, After I extract 13,020 bmp files from "C:", (But 12,544 files is 0 size)  the IDE show me a error message.
0
 
geobulCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQed and points refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.