Requirement
You need to read the icons of other execution files, and thenProgram.
Implementation
Class Extracticon
{
Public static Bitmap Getbitmapfromeicon ( String Path)
{
Return Getbitmap (geticonfromexe (PATH ));
}
Public static Icon Geticonfromexe ( String Path)
{
Return Geticonfromexe (path, True );
}
// Http://www.pinvoke.net/default.aspx/shell32/ExtractIconEx.html
Public static Icon Geticonfromexe ( String Path, Bool Large)
{
Intptr Hlargeicon = Intptr . Zero;
Intptr Hsmallicon = Intptr . Zero;
Extracticonex (path, 0, Ref Hlargeicon, Ref Hsmallicon, 1 );
If (Large)
{
Return ( Icon ) Icon . Fromhandle (hlargeicon). Clone ();
}
Else
{
Return ( Icon ) Icon . Fromhandle (hsmallicon). Clone ();
}
}
// Http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/e765775c-a5b5-493f-baeb-3eaee1d41cef
Public static Bitmap Getbitmap ( Icon Icon)
{
Bitmap BMP = New Bitmap (Icon. Width, icon. Height );
// Create temporary graphics
Graphics Gxmem = Graphics . Fromimage (BMP );
// Draw the icon
Gxmem. drawicon (icon, 0, 0 );
// Clean up
Gxmem. Dispose ();
Return BMP;
}
// Http://msdn.microsoft.com/en-us/library/aa922154.aspx
[ Dllimport ( "Coredll. dll" , Setlasterror = True )]
Private Static extern Intptr Extracticonex ( String Filename, Int Index, Ref Intptr Hiconlarge, Ref Intptr Hiconsmall, Uint Nicons );
}
Ms provides the extracticonex function to retrieve the ICO icon information of the execution file. The third parameter is a large icon, and the fourth parameter is a small icon.
Because the icon object cannot be directly drawn on graphics, it needs to be converted to bitmap, but Compact framework does not support icon. Save (), soBitmapGetbitmap (IconIcon) function.
Take out the word icon as follows.
Figure 2 removes the ICO background