Soui Interface Library Add Windows system files icon Skin

Source: Internet
Author: User

Recently learning the Soui interface library. It is useful to slistctrl this control to present file information. Control usage is basically the same as MFC's CListCtrl. Icon display is also supported. But the icon is to be added to the icon image yourself. It's a little hard to get. So I realized the skin of the Windows System file icon skins. Not much to say, directly on the code.

1 #ifndef __winfile_icon_skin_hpp_2 #define__winfile_icon_skin_hpp_3 4#include"core/sskinobjbase.h"5#include <commoncontrols.h>6 //************************************7 //This is the skin control of the System file icon. Use Shgetfileinfo to get an icon index8 //Register Theapp->registerskinfactory (tplskinfactory<sskinsystemiconlist> ()) before use; //Registering Skins9 //then add the resources in the Skin.xml <sysiconlist name= "Sysiconlist" flag= "1"/> flag indicates the icon size type this must beTen //  One //************************************ A classSskinsystemiconlist: PublicSskinobjbase - { -Soui_class_name (Sskinsystemiconlist, L"sysiconlist") the  -  Public: - sskinsystemiconlist () - : M_hiconlist (NULL) +     {             -          +     } A     Virtual~sskinsystemiconlist () at     { -         if(NULL! =m_hiconlist) -         { -((iimagelist*) m_hiconlist)Release (); -M_hiconlist =NULL; -         } in     } -  to     VirtualSIZE getskinsize () +     { -         returnM_szsimpleicon; the     } * protected: $     Virtual void_draw (Irendertarget *PRT, Lpcrect rcdraw, DWORD dwstate,byte byalpha)Panax Notoginseng     { -         if(NULL = =m_hiconlist) the             return ; +  AHicon Hicon =NULL; the((iimagelist*) m_hiconlist)->geticon (dwstate, Ild_normal, &hicon); +         if(NULL! =hicon) -         { $Prt->drawiconex (Rcdraw->left, Rcdraw->top, Hicon, Rcdraw->right-rcdraw->left, rcDraw-> Bottom-rcdraw->top, di_normal); $ DestroyIcon (HICON); -Hicon =NULL; -         } the     } - Private:Wuyihimagelist*m_hiconlist; the SIZE M_szsimpleicon; -  Wu Soui_attrs_begin () -Attr_custom (L"Flag", Onattrflag)//the image resource name specified in the XML file, (Type:name) flag indicates that the icon type has small large About soui_attrs_end () $ protected: -LRESULT Onattrflag (ConstSstringw &strvalue,bool bloading) -     { -         intnret=0;  A:: Strtointexw (strvalue, Stif_support_hex, &nret); +  the         //#define SHIL_LARGE 0//normally 32x32 -         //#define Shil_small 1//normally 16x16 $         //Shil_extralarge Gets the 48 * 48 icon, Shil_jumbo gets the 256 * 256 icon.  theHRESULT HRESULT =:: Shgetimagelist (Nret, Iid_iimagelist, (void* *) &m_hiconlist); the         if(S_OK! =HResult) the             returnS_FALSE; the  -         //Calculate icon Size in         intNX =0; the         intNY =0; the((iimagelist*) m_hiconlist)->geticonsize (&nx, &NY); AboutM_szsimpleicon.cx =NX; theM_szsimpleicon.cy =NY; the  the         returnS_OK; +     } - }; the //////////////////////////////////////////////////////////////////////////Bayi #endif //__winfile_icon_skin_hpp_

Let's talk about how to use it first.

1. Skin.xml is added to the latest version of the Soui interface library. All the picture resources are to be added here.

<? XML version= "1.0" ?> < Skin >    <  name= "sysiconlist"  flag= "1"/>  flag Represents the icon size type this must have </skin>

Flag this has to be. Because the System icon also has a lot of. 1 represents a small icon. You can see the code specifically.

#define SHIL_LARGE 0//normally 32x32
#define SHIL_SMALL 1//normally 16x16

The skin must be registered before use.

Sapplication *theapp=New  sapplication (NULL, hinstance);
Theapp->registerskinfactory (tplskinfactory<sskinsystemiconlist> ()); // Registering Skins

Then you can use it in the layout mainwnd.xml. There is no difference between using the method and others.

Iconskin= "Sysiconlist"

Finally, we use Shgetfileinfo to get the specific icon index.

Finish...

Soui Interface Library Add Windows system files icon Skin

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.