Capturing an Icon from an EXE (Visual Basic 5 and later)
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. |
|
2. |
Add a command button and name it as follows: |
|
|
Name |
Caption |
|
CapEXE |
Capture EXE |
3. |
Code the CapEXE_Click procedure as follows: |
Private Sub CapEXE_Click()
Dim nCount As Integer
nCount = 0
LEADRasterScr1.CaptureGetResourceCount "c:\win98\calc.exe", SCR_CAP_ICON
nCount =LEADRasterScr1.CaptureResourceCount
If nCount < 1 Then
MsgBox "No Icons."
Else
LEADRasterScr1.TransparentColor = vbWhite
'capture by string resource id
'Please note that the exe and the id may not be the same on your system.
'Be sure to replace these with a valid exe name and id for your system.
LEADRasterScr1.CaptureEXE "c:\win98\calc.exe", SCR_CAP_ICON, "sc", False, False
LEADRasterView1.AutoRepaint = False
LEADRasterView1.Raster.Bitmap = LEADRasterScr1.Bitmap
LEADRasterView1.Raster.BitmapTransparentColor = vbWhite
LEADRasterView1.Raster.BitmapEnableTransparency = True
LEADRasterView1.AutoRepaint = True
MsgBox "wait"
End If
nCount = 0
LEADRasterScr1.CaptureGetResourceCount "c:\win98\defrag.exe", SCR_CAP_ICON
nCount = LEADRasterScr1.CaptureResourceCount
If (nCount < 1) Then
MsgBox "No Icons."
Else
LEADRasterScr1.TransparentColor = vbWhite
'now, capture by numeric resource id
'Please note that the exe and the id may not be the same on your system.
'Be sure to replace these with a valid exe name and id for your system.
LEADRasterScr1.CaptureEXE "c:\win98\defrag.exe", SCR_CAP_ICON, "113", True, False
LEADRasterView1.Raster.Bitmap = LEADRasterScr1.Bitmap
LEADRasterView1.AutoRepaint = False
LEADRasterView1.Raster.Bitmap = LEADRasterScr1.Bitmap
LEADRasterView1.Raster.BitmapTransparentColor = vbWhite
LEADRasterView1.Raster.BitmapEnableTransparency = True
LEADRasterView1.AutoRepaint = True
MsgBox "wait"
End If
nCount = 0
LEADRasterScr1.CaptureGetResourceCount "c:\win98\Explorer.exe", SCR_CAP_ICON
nCount = LEADRasterScr1.CaptureResourceCount
If (nCount < 1) Then
MsgBox "No Icons."
Else
LEADRasterScr1.TransparentColor = vbWhite
'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.
LEADRasterScr1.CaptureEXE "c:\win98\Explorer.exe", SCR_CAP_ICON, "0", True, True
LEADRasterView1.Raster.Bitmap = LEADRasterScr1.Bitmap
LEADRasterView1.AutoRepaint = False
LEADRasterView1.Raster.Bitmap = LEADRasterScr1.Bitmap
LEADRasterView1.Raster.BitmapTransparentColor = vbWhite
LEADRasterView1.Raster.BitmapEnableTransparency = True
LEADRasterView1.AutoRepaint = True
MsgBox "wait"
End If
End Sub
4. |
Run your program to test it. |