Capturing an Icon from an EXE (Delphi 4.0)
Take the following steps to add code that will let you capture icons from EXEs.
1. |
Start with the project that you created in Capturing an Active Window (Delphi). |
|
2. |
Select the LEAD Main Control on the VCL toolbar and add it to the form. Size and position the control as you want it to appear at run time. Change the Name to LEAD2. |
|
3. |
Select the LEAD Main Control on the VCL toolbar and add it to the form. Size and position the control as you want it to appear at run time. Change the Name to LEAD3. |
|
4. |
Add a command button and name it as follows: |
|
|
Name |
Caption |
|
CapEXE |
Capture EXE |
5. |
Code the CapEXEClick procedure as follows: |
procedure TForm1.CapEXEClick(Sender: TObject);
var
nCount : Integer;
begin
nCount := 0;
LEADScr1.CaptureGetResourceCount ('c:\windows\calc.exe', CAPTURE_ICON, nCount);
if (nCount < 1) then
ShowMessage ('No Icons.');
if (nCount >= 1) then
begin
LEADScr1.TransparentColor := clWhite;
LEAD1.TransparentColor:= clWhite;
LEAD1.UseTransparentColor := True;
{capture by string resource id}
{Please note that the exe and id may not be the same on your system.}
{Be sure to replace this with a valid exe name and id for your system. }
LEADScr1.CaptureEXE ('c:\windows\calc.exe', CAPTURE_ICON, 'sc', False, False);
LEAD1.Bitmap := LEADScr1.Bitmap;
ShowMessage ('Wait');
end;
nCount := 0;
LEADScr1.CaptureGetResourceCount ('c:\windows\defrag.exe', CAPTURE_ICON, nCount);
if (nCount < 1) then
ShowMessage ('No Icons.');
if (nCount >= 1) then
begin
LEADScr1.TransparentColor := clWhite;
LEAD2.TransparentColor:= clWhite;
LEAD2.UseTransparentColor:= True;
{now, capture by numeric resource id}
{Please note that the exe and id may not be the same on your system.}
{Be sure to replace this with a valid exe name and id for your system. }
LEADScr1.CaptureEXE ('c:\windows\defrag.exe', CAPTURE_ICON, '111', True, False);
LEAD2.Bitmap:= LEADScr1.Bitmap;
ShowMessage ('wait');
end;
nCount := 0;
LEADScr1.CaptureGetResourceCount ('c:\windows\Charmap.exe', CAPTURE_ICON, nCount);
if (nCount < 1) then
ShowMessage ('No Icons.');
if (nCount >= 1) then
begin
LEADScr1.TransparentColor := clWhite;
LEAD3.TransparentColor:= clWhite;
LEAD3.UseTransparentColor:= True;
{finally, capture by resource index}
{Please note that the exe and id may not be the same on your system.}
{Be sure to replace this with a valid exe name and id for your system. }
LEADScr1.CaptureEXE ('c:\windows\Charmap.exe', CAPTURE_ICON, '0', True, True);
LEAD3.Bitmap:= LEADScr1.Bitmap;
ShowMessage ('wait');
end;
end;
6. |
Run your program to test it. |