Capturing an Icon from an EXE (Visual C++ 5 and later)
Take the following steps to add some code that will let you capture icons from EXEs.
1. |
Start with the project you created in Capturing an Active Window. |
|
2. |
Add a command button and set the ID and Caption properties as follows: |
|
|
ID |
Caption |
|
IDC_CAPEXE |
Capture EXE |
3. |
Back in MFC Class Wizard, do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CScrCapDlg. |
|
c. |
In the Object IDs list box, select IDC_CAPEXE. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnCapexe). |
|
f. |
Click the Edit Code button and code the OnCapexe procedure as follows: |
void CScrCapDlg::OnCapexe()
{
short nCount = 0;
m_pLEADRasterScr->CaptureGetResourceCount ("c:\\win98\\calc.exe", SCR_CAP_ICON);
nCount = m_pLEADRasterScr->GetCaptureResourceCount();
if (nCount < 1)
AfxMessageBox(TEXT("No Icons."));
else
{
m_pLEADRasterScr->PutTransparentColor (RGB(255,255, 255));
/*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. */
m_pLEADRasterScr->CaptureEXE ("c:\\win98\\calc.exe", SCR_CAP_ICON, "sc", FALSE, FALSE);
m_LEADRasterView1.GetRaster().SetBitmap(m_pLEADRasterScr->GetBitmap ());
m_LEADRasterView1.GetRaster().SetBitmapTransparentColor (RGB(255, 255, 255));
m_LEADRasterView1.GetRaster().SetBitmapEnableTransparency (TRUE);
AfxMessageBox(TEXT("Wait"));
}
nCount = 0;
m_pLEADRasterScr->CaptureGetResourceCount ("c:\\win98\\defrag.exe", SCR_CAP_ICON);
nCount = m_pLEADRasterScr->GetCaptureResourceCount ();
if (nCount < 1)
AfxMessageBox(TEXT("No Icons."));
else
{
m_pLEADRasterScr->PutTransparentColor (RGB(255,255, 255));
/* 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. */
m_pLEADRasterScr->CaptureEXE ("c:\\win98\\defrag.exe", SCR_CAP_ICON, "113", TRUE, FALSE);
m_LEADRasterView1.GetRaster().SetBitmap(m_pLEADRasterScr->GetBitmap ());
m_LEADRasterView1.GetRaster().SetBitmapTransparentColor (RGB(255, 255, 255));
m_LEADRasterView1.GetRaster().SetBitmapEnableTransparency (TRUE);
AfxMessageBox(TEXT("Wait"));
}
nCount = 0;
m_pLEADRasterScr->CaptureGetResourceCount ("c:\\win98\\Explorer.exe", SCR_CAP_ICON);
nCount = m_pLEADRasterScr->GetCaptureResourceCount ();
if (nCount < 1)
AfxMessageBox(TEXT("No Icons."));
else
{
m_pLEADRasterScr->PutTransparentColor (RGB(255,255, 255));
/* 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. */
m_pLEADRasterScr->CaptureEXE ("c:\\win98\\Explorer.exe", SCR_CAP_ICON, "0", TRUE, TRUE);
m_LEADRasterView1.GetRaster().SetBitmap(m_pLEADRasterScr->GetBitmap ());
m_LEADRasterView1.GetRaster().SetBitmapTransparentColor (RGB(255,255, 255));
m_LEADRasterView1.GetRaster().SetBitmapEnableTransparency (TRUE);
AfxMessageBox(TEXT("Wait"));
}
}
4. |
On the main menu, select Build> Build ScrCap.exe to build the project. |
5. |
On the main menu, select Build> Execute ScrCap.exe to run the project. |