JohnOne Posted April 4, 2010 Share Posted April 4, 2010 (edited) 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 April 8, 2010 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 More sharing options...
Yashied Posted April 4, 2010 Share Posted April 4, 2010 #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 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
JohnOne Posted April 4, 2010 Author Share Posted April 4, 2010 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 More sharing options...
JohnOne Posted April 8, 2010 Author Share Posted April 8, 2010 (edited) 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 April 8, 2010 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now