Windows Mobile process viewer Development (3) -- get process icons

Source: Internet
Author: User

The extracticonex function is used to extract the process icon.

 

Add several functions to the process class:

 

Public String getfullpath () // obtain the path of the Process file <br/>{< br/> stringbuilder S = new stringbuilder (); <br/> S. capacity = 100; <br/> process. getmodulefilename (this. processid, S, S. capacity); <br/> string Path = path. getfullpath (S. tostring (); <br/> return path; <br/>}</P> <p> Public icon geticonfromexe () <br/>{< br/> intptr hlargeicon = intptr. zero; <br/> intptr hsmallicon = intptr. zero; <br/> string Path = This. getfullpath (); <br/> try <br/>{< br/> extracticonex (path, 0, ref hlargeicon, ref hsmallicon, 1 ); <br/>}< br/> catch (exception ex) <br/>{< br/> throw new exception (ex. message); <br/>}< br/> icon Ic = NULL; <br/> try <br/> {<br/> Ic = (icon) icon. fromhandle (hsmallicon ). clone (); <br/>}< br/> catch (exception e) <br/>{< br/> return NULL; <br/>}< br/> return IC; <br/>}</P> <p> [dllimport ("coredll. DLL ", charset = charset. auto)] <br/> Public extern static int getmodulefilename (uint hmodule, stringbuilder strfullpath, int nsize); </P> <p> [dllimport ("coredll. DLL ", setlasterror = true)] <br/> Private Static extern intptr extracticonex (string filename, int index, ref intptr hiconlarge, ref intptr hiconsmall, uint nicons); <br/>

 

Let's take a look at the displayed icon. You need to add imagelist to the listview control of the interface.

 

Private void refreshlist () <br/>{< br/> processes = process. getprocesses (); </P> <p> listviewitem LVI; </P> <p> listprocess. beginupdate (); <br/> listprocess. items. clear (); <br/> imagelist imagelistsmall = new imagelist (); <br/> int I = 0; </P> <p> foreach (PROCESS p in processes) <br/>{< br/> LVI = new listviewitem (P. processname); <br/> icon IC; <br/> Ic = P. geticonfromexe (); <br/> If (IC! = NULL) <br/>{< br/> imagelistsmall. images. add (IC); <br/> LVI. imageindex = I ++; <br/>}</P> <p> string pid = string. format ("{0: x}", p. processid); <br/> LVI. subitems. add (PID); <br/> LVI. subitems. add (P. threadcount. tostring (); <br/> listprocess. items. add (LVI); <br/>}< br/> listprocess. smallimagelist = imagelistsmall; </P> <p> listprocess. endupdate (); <br/>}</P> <p>

 

Listprocess is an instance of the listview control.

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.