Jump to content

Recommended Posts

Posted (edited)

#include<ButtonConstants.au3>
#Include <WinAPI.au3>
#include<array.au3>

$hGUI = GUICreate("Form1", 200, 200, 193, 125)
$Button1 = GUICtrlCreateButton("Button1", 50,50, 32, 32, $BS_ICON)
                                                 
GUISetState()


GUICtrlSetImage($Button1,_WinAPI_ExtractIconEx(@DesktopDir&"\low.mp3", -1, 0, 0, 0))

sleep(5000)

what am i doing wrong....

Edited by Aceguy
Posted

#include<ButtonConstants.au3>
#Include <WinAPI.au3>
#include<array.au3>

$hGUI = GUICreate("Form1", 200, 200, 193, 125)
$Button1 = GUICtrlCreateButton("Button1", 50,50, 32, 32, $BS_ICON)
                                                 
GUISetState()


GUICtrlSetImage($Button1,_WinAPI_ExtractIconEx(@DesktopDir&"\low.mp3", -1, 0, 0, 0))

sleep(5000)

what am i doing wrong....

This returns the count of icons in the file:
_WinAPI_ExtractIconEx(@DesktopDir&"\low.mp3", -1, 0, 0, 0)

How is that count going to work as a button image?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

well, been doing lots of searching and came up wih this, tried to modify to my needs but fail...

All credit goes to rasim.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

$hGUI = GUICreate("Test GUI", 300, 200)

$cMenu_File = GUICtrlCreateMenu("&File")

$cMenuItem_Open = GUICtrlCreateMenuItem("Open", $cMenu_File)

$cListView = GUICtrlCreateListView("Items", 10, 10, 280, 160)

$hImage = _GUIImageList_Create(16, 16, 5, 3, 1)
_GUICtrlListView_SetImageList($cListView, $hImage, 1)

GUICtrlSendMsg($cListView, $LVM_SETCOLUMNWIDTH, 0, 200)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cMenuItem_Open
            $sFile = FileOpenDialog("Select file", "", "All files (*.*)", 1, "", $hGUI)
            If Not @error Then
                $hIcon = _ExtractAssociatedIcon($hGUI, $sFile)
                $Index = _ImageList_AddIcon($hImage, $hIcon)
                _DestroyIcon($hIcon)
                _GUICtrlListView_InsertItem($cListView, $sFile, -1, $Index)
            EndIf
    EndSwitch
WEnd

Func _ExtractAssociatedIcon($hWnd, $sFile)
    Local $aRet = DllCall("shell32.dll", "hwnd", "ExtractAssociatedIcon", _
                                                 "hwnd", $hWnd, _
                                                 "str", $sFile, _
                                                 "short*", 0)
    Return $aRet[0]
EndFunc   ;==>_ExtractAssociatedIcon

Func _ImageList_AddIcon($hImage, $hIcon)
    Local $aRet = DllCall("comctl32.dll", "int", "ImageList_AddIcon", _
                                                 "hwnd", $hImage, _
                                                 "hwnd", $hIcon)
    Return $aRet[0]
EndFunc   ;==>_ImageList_AddIcon

Func _DestroyIcon($hIcon)
    Local $aRet = DllCall("user32.dll", "int", "DestroyIcon", _
                                               "hwnd", $hIcon)
    Return $aRet[0]
EndFunc   ;==>_DestroyIcon

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...