Re: Значки из Shell32.dll?
От: PA  
Дата: 05.07.05 07:31
Оценка:
Здравствуйте, 2Diamond, Вы писали:

D>В VB6 все до боли просто:

D>ExtractIcon(...
D>DrawIcon(...
D>Но в .NET такая схема не работает!
D>MSDN уходит от ответа.
D>Как получить иконки из shell32.dll в VB.NET?

Например так:


    <DllImport("shell32", EntryPoint:="ExtractIconA")> _
    Shared Function ExtractIcon(ByVal hInst As Integer, _
        ByVal lpszExeFileName As String, _
        ByVal nIconIndex As Integer) As Integer
    End Function

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

        Dim x As Integer = 1
        Dim y As Integer = 1
        Dim g As Graphics = e.Graphics

        Dim IconHeight As Integer = SystemInformation.IconSize.Height
        Dim IconWidth As Integer = SystemInformation.IconSize.Width
        Dim i As Icon
        For Each i In IconsCollection
            If Not i Is Nothing Then
                g.DrawIcon(i, x, y)
                g.DrawRectangle(Pens.Black, x, y, i.Width, i.Height)
                If x + 2 * IconWidth > Panel1.Width Then
                    x = 1
                    y += IconHeight + 2
                Else
                    x += IconWidth + 2
                End If
            End If
        Next

        g.Dispose()
    End Sub

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Panel1.Invalidate()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim hIcon As Integer
        Dim IconIndex As Integer
        Dim IconStorage As String = System.Environment.GetEnvironmentVariable("systemroot") & "\system32\shell32.dll"
        Dim IconCount As Integer = ExtractIcon(0, IconStorage, -1)
        If IconCount > 0 Then
            Dim w As Integer = Math.Ceiling(Math.Sqrt(IconCount))
            Me.ClientSize = New Size((SystemInformation.IconSize.Width + 2) * w, _
                (SystemInformation.IconSize.Height + 2) * w)
        End If

        Do While IconCount > IconIndex
            hIcon = ExtractIcon(0, IconStorage, IconIndex)
            Dim i As Icon = System.Drawing.Icon.FromHandle(hIcon)
            IconsCollection.Add(i)
            IconIndex += 1
        Loop
    End Sub
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.