How to use. NET Compact framework in Windows Mobile to retrieve the icon from the execution File

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.