Jump to content

Icon to Image


Recommended Posts

Hi, been looking for a way to get an applications/documents icon to an image file (Supported in gui)

So far All I can find is _WinAPI_ShellExtractIcons() from Yashieds WinAPIEx UDFs (thanks) which will return a hadle to an icon.

But I'm totally stuck as to how to convert this to an image I can save to disk and use in a gui.

My limited search skills are not prodicing much fruit.

Any hints/tips would be warmly welcomed and greatly appreciated.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

#Include <WinAPIEx.au3>

GUICreate('MyGUI', 128, 128)
$Icon = GUICtrlCreateIcon('', 0, 40, 40, 48, 48)
$hIcon = _WinAPI_ShellExtractIcons(@SystemDir & '\shell32.dll', 130, 48, 48)
GUICtrlSendMsg($Icon, 0x0172, 1, $hIcon)
GUISetState()

Do
Until GUIGetMsg() = -3

Link to comment
Share on other sites

Thanks Yashied, I appreciate your option and code greatly.

Using it, I found It did not show the icon of a none executable file, like a document of any kind and thats a problem to me.

I duly found your _WinAPI_ExtractAssociatedIcon() func, and without knowing fully how to use it properly (Dont know what to put in as $hInstance and assumed its a live application handle that uses the file extension), managed to get it working to my satisfaction

#Include <WinAPIEx.au3>

OnAutoItExitRegister("_destroyicons")

Global $hIcon2

GUICreate('MyGUI', 128, 128)
$Icon = GUICtrlCreateIcon('', 0, 40, 40, 32, 32)
$hIcon = _WinAPI_ExtractAssociatedIcon('','F:\Program Files\Wireshark\WinPcap_4_1_1.exe', 0)
GUICtrlSendMsg($Icon, 0x0172, 1, $hIcon)

GUISetState()

Do
Until GUIGetMsg() = -3

Func _destroyicons()
    _WinAPI_FreeIcon($hIcon)
    _WinAPI_FreeIcon($hIcon2)
EndFunc

Thank you very much once again.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Ive kind of fell at the first hurdle with this.

While the above code works fine, I really need to be able to add the icon or multiple icons from within a function.

GUICtrlCreateIcon() dosent seem to offer a way to get the icon where I want it, so Im trying to use GUICtrlSetImage() which Im failing at and cannot see what Im doing wrong.

Any advice ?

#Include <WinAPIEx.au3>

OnAutoItExitRegister("_destroyicons")

Global $hIcon2

GUICreate('MyGUI', 500, 500)
$Icon = GUICtrlCreateIcon('', 0, 40, 40, 32, 32)
$Icon2 = GUICtrlCreateIcon('', 0, 40, 80, 32, 32)
$var = FileOpenDialog("Select File To Open", @ProgramFilesDir, "All Files (*.*)")
$hIcon = _WinAPI_ExtractAssociatedIcon('',$var, 0)
GUICtrlSendMsg($Icon, 0x0172, 1, $hIcon)

GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $Icon Then _Add()

Wend

Func _destroyicons()
    _WinAPI_FreeIcon($hIcon)
    _WinAPI_FreeIcon($hIcon2)
EndFunc

Func _Add()
    $var2 = FileOpenDialog("Select File To Open", @ProgramFilesDir, "All Files (*.*)")
    $hIcon2 = _WinAPI_ExtractAssociatedIcon('',$var2, 0)
    GUICtrlSetImage($Icon2,$hIcon2,0)
EndFunc

Edit: solved I was trying to get the icon in a tabItem and was missing GUISwitch()

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...