Capturing an Icon from an EXE (Builder 3.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 (Builder).

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:

 

void __fastcall TForm1::CapExeClick(TObject *Sender)

{

int nCount = 0;
 
LEADScr1->CaptureGetResourceCount ("c:\\windows\\calc.exe", CAPTURE_ICON, nCount);
if ( (nCount < 1) )
   ShowMessage ("No Icons.");

if ( (nCount >= 1) )
{
   LEADScr1->TransparentColor = clWhite;
   LEAD1->TransparentColor = clWhite;
   LEAD1->UseTransparentColor = true;
   /*capture by string resource id*/
   /*Please note that the exe and id may ! 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");
}

nCount = 0;
LEADScr1->CaptureGetResourceCount ("c:\\windows\\defrag.exe", CAPTURE_ICON, nCount);
if ( (nCount < 1) )
   ShowMessage ("No Icons.");

if ( (nCount >= 1) )
{
   LEADScr1->TransparentColor = clWhite;
   LEAD2->TransparentColor= clWhite;
   LEAD2->UseTransparentColor = true;
   /*now, capture by numeric resource id*/
   /*Please note that the exe and id may ! 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");
}
nCount = 0;
LEADScr1->CaptureGetResourceCount ("c:\\windows\\Charmap.exe", CAPTURE_ICON, nCount);
if ( (nCount < 1) )
   ShowMessage ("No Icons.");

if ( (nCount >= 1) )
{
   LEADScr1->TransparentColor = clWhite;
   LEAD3->TransparentColor = clWhite;
   LEAD3->UseTransparentColor = true;
   /*finally, capture by resource index*/
   /*Please note that the exe and id may ! 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");
}

}

 

6.

Run your program to test it.