Use the 32-bit icon in VB6 (version 2)

Source: Internet
Author: User

Original: http://blog.csdn.net/Modest/archive/2008/05/22/2468937.aspx

 

This version adds the hicon attribute and setformicon method. As the name suggests, setformicon is a 32-bit icon application that implements VB6 forms. The implementation is very simple, and sending a message is sufficient. The hicon attribute returns the icon Handle Based on the icon index. This handle can also be used to beautify 32-bit icons in the tray.

'::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::: <Br/> 'vb6 using 32-bit icons (second edition) <br/> 'grammed by Wei sort order <br/> 'website: http://www.chenoe.com <br/> 'blog: http://blog.csdn.net/Modest <br/> ':::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::: ::: </P> <p> Option explicit <br/> private type icondirentry <br/> bwidth as byte <br/> bheight as byte <br/> bcolorcount as byte <br/> breserved as byte <br/> wplanes as integer <br/> wbitcount as integer <br/> dwbytesinres as long <br/> dwimageoffset as long <br/> end type <br /> private type icondir <br/> idreserved as integer <br/> idtype as integer <br/> idcount as integer <br/> identries () as icondirentry <br/> end type <br/> private declare function createiconfromresourceex lib "USER32" (presbits as byte, byval dwressize as long, byval ficon as long, byval dwver as long, byval cxdesired as long, byval cydesired as long, byval uflags as long) As long <br/> private declare function drawiconex lib "user32.dll" (byval HDC as long, byval xleft as long, byval ytop as long, byval hicon as long, byval cxwidth as long, byval cywidth as long, byval istepifanicur as long, byval hbrflickerfreedraw as long, byval diflags as long) as long <br/> private declare function destroyicon lib "USER32" (byval hicon as long) as long <br/> private declare sub copymemory lib "kernel32.dll" alias "rtlmovememory" (byref destination as any, byref source as any, byval length as long) <br/> private declare function sendmessagelong lib "USER32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, byval lparam as long) as long <br/> private m_data () as byte <br/> private m_icount as integer <br/> private m_idir as icondir <br/> Public Property get count () as long <br/> COUNT = m_icount <br/> end property <br/> Public Property get height (optional byval index as long) as long <br/> Height = m_idir.identries (index ). bheight <br/> end property <br/> Public Property get width (optional byval index as long) As long <br/> width = m_idir.identries (index ). bwidth <br/> end property <br/> Public Property get length (optional byval index as long) As long <br/> length = m_idir.identries (index ). dwbytesinres <br/> end property <br/> Public Property get data (optional byval index as long) as byte () <br/> dim o as long, l as long, D () as byte <br/> O = m_idir.identries (index ). dwimageoffset <br/> L = m_idir.identries (index ). dwbytesinres <br/> redim D (L-1) <br/> copymemory D (0), m_data (O ), L <br/> DATA = d <br/> end property <br/> Public Function loadfromdata (data () as byte) as Boolean <br/> dim I as long <br/> m_data = data <br/> copymemory m_icount, m_data (4 ), 2' get the number of icons <br/> If m_icount> 0 then <br/> redim m_idir.identries (0 to m_icount-1) 'icon directory structure data <br/> for I = 0 to m_icount-1 <br/> copymemory m_idir.identries (I), m_data (6 + Len (m_idir.identries (I )) * I), Len (m_idir.identries (I )) <br/> next <br/> loadfromdata = true <br/> end if <br/> end function <br/> Public Function loadfromfile (byval filename as string) as Boolean <br/> dim hfile as integer <br/> dim data () as byte <br/> If Dir (filename) = "" Then exit function </P> <p> hfile = freefile <br/> open filename for binary as # hfile <br/> redim data (lof (hfile) -1) <br/> Get # hfile, data <br/> close # hfile <br/> loadfromfile = loadfromdata (data) <br/> end function <br/> Public Property get hicon (optional byval index as long) As long <br/> dim D () as byte, l as long, w as long, H as long <br/> d = data (INDEX): L = length (INDEX) <br/> W = width (INDEX ): H = height (INDEX) <br/> hicon = createiconfromresourceex (D (0), L, 1, & h30000, W, H, 0) <br/> end property <br/> Public Function draw (byval HDC as long, byval X as long, byval y as long, optional byval index as long = 0) as Boolean <br/> dim w as long, H as long <br/> W = width (INDEX): H = height (INDEX) <br/> draw = drawiconex (HDC, X, Y, hicon (INDEX), W, H, 0, 0, 3) <> 0 <br/> destroyicon hicon <br/> end function <br/> Public sub setformicon (byval form as form, optional byval index as long = 0) <br/> sendmessagelong form. hwnd, & h80, 0, hicon (INDEX) <br/> end sub <br/> private sub class_terminate () <br/> erase m_data <br/> end sub <br/>

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.