ImOracle Posted August 3, 2015 Share Posted August 3, 2015 Hi,So i have seen a lot of Posts about this already and most of the time the users figured it out somehow, unlike me.The Problem im having is that i cant assign Icons to Listview items. I know that you have to create some fancy ImageList and i did all that.I tried extracting the Icon out of the process and now i just tried to use the icon from the .exe that is running.#include <GuiListView.au3> #include <GuiImageList.au3> #include <WinAPIProc.au3> $mainForm = GUICreate("test", 500, 500) $List = _GUICtrlListView_Create($mainForm, "Process Name|PID", 0, 0, 500, 500) $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES) _GUICtrlListView_SetExtendedListViewStyle($List, $exStyles) $aProcess = ProcessList() $hImage = _GUIImageList_Create(64, 64, 0, 1) For $i = 0 To $aProcess[0][0] $CurIcon = _WinAPI_GetProcessFileName($aProcess[$i][1]) ConsoleWrite("CurIcon: "&$CurIcon&@CRLF) _GUIImageList_AddIcon($hImage, $CurIcon) Next For $i = 0 To $aProcess[0][0] _GUICtrlListView_AddItem($List, $aProcess[$i][0]) Next _GUICtrlListView_SetImageList($List, $hImage) GUISetState() While 1 Switch GUIGetMsg() Case -3 Exit EndSwitch WEndNow i think my only problem is that im not defining the 3rd parameter in _GUIImageList_AddIcon() "$iIndex[optional] Specifies the 0-based index of the icon to extract" What is a 0-based index in an icon? I bet i just missed a single thing thats really obivious, Oracle Link to comment Share on other sites More sharing options...
jvds Posted August 5, 2015 Share Posted August 5, 2015 (edited) you have to create a image list then pick from the image list the icons#include <GuiListView.au3> #include <GuiImageList.au3> #include <WinAPIProc.au3> $iStylesEx = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES) $mainForm = GUICreate("test", 500, 500) $List = _GUICtrlListView_Create($mainForm, "Process Name|PID", 0, 0, 500, 500, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($List, $iStylesEx) GUISetState(@SW_SHOW) $aProcess = ProcessList() $hImage = _GUIImageList_Create(16, 16,6, 3) ;create an image list to pick images from, fill none icon images with an icon from some where else to make shure the images in the image list match the processlist, or images will be wrongly asignet(srry my english xD) For $i = 0 To $aProcess[0][0] $CurIcon = _WinAPI_GetProcessFileName($aProcess[$i][1]) $icon = _GUIImageList_AddIcon($hImage, $CurIcon,0) ;if exe does not have an icon extract an icon from shell32 or some where else if $icon = -1 then _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 0);using 0 but 2 is exe icon probably not the right one, you will need to correct this one Next _GUICtrlListView_SetImageList($List, $hImage, 1) For $i = 0 To $aProcess[0][0] _GUICtrlListView_AddItem($List, $aProcess[$i][0],$i) ; add items and pick the image position (in $hImage) to show for the exe with $i _GUICtrlListView_AddSubItem($List, $i, $aProcess[$i][1], 1, -1) ;-1 for no icon Next GUISetState() While 1 Switch GUIGetMsg() Case -3 Exit EndSwitch WEnd Edited August 5, 2015 by jvds Link to comment Share on other sites More sharing options...
ImOracle Posted August 5, 2015 Author Share Posted August 5, 2015 you have to create a image list then pick from the image list the icons#include <GuiListView.au3> #include <GuiImageList.au3> #include <WinAPIProc.au3> $iStylesEx = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES) $mainForm = GUICreate("test", 500, 500) $List = _GUICtrlListView_Create($mainForm, "Process Name|PID", 0, 0, 500, 500, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($List, $iStylesEx) GUISetState(@SW_SHOW) $aProcess = ProcessList() $hImage = _GUIImageList_Create(16, 16,6, 3) ;create an image list to pick images from, fill none icon images with an icon from some where else to make shure the images in the image list match the processlist, or images will be wrongly asignet(srry my english xD) For $i = 0 To $aProcess[0][0] $CurIcon = _WinAPI_GetProcessFileName($aProcess[$i][1]) $icon = _GUIImageList_AddIcon($hImage, $CurIcon,0) ;if exe does not have an icon extract an icon from shell32 or some where else if $icon = -1 then _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 0);using 0 but 2 is exe icon probably not the right one, you will need to correct this one Next _GUICtrlListView_SetImageList($List, $hImage, 1) For $i = 0 To $aProcess[0][0] _GUICtrlListView_AddItem($List, $aProcess[$i][0],$i) ; add items and pick the image position (in $hImage) to show for the exe with $i _GUICtrlListView_AddSubItem($List, $i, $aProcess[$i][1], 1, -1) ;-1 for no icon Next GUISetState() While 1 Switch GUIGetMsg() Case -3 Exit EndSwitch WEnd so basically the same but with the additional parameter of _GUIImageList_AddIcon() set to 0 which is defaulted to 0.Im sorry but this still doenst make sense to me. I created:1. The Listview2. the image list3. added the icon to the imagelist4. assigned the image list to the ListView5. added the Items for the ListView.Still doesnt work... Link to comment Share on other sites More sharing options...
jvds Posted August 6, 2015 Share Posted August 6, 2015 look, i took your script and plaid around with it until i got it working, did you even try the one I posted?it works, the general script is almost as yours but not exactlythree things that I've added or did diferentfill in blank icons for executables with no icon if $icon = -1 then _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 0)add the image list to the item in the listview _GUICtrlListView_AddItem($List, $aProcess[$i][0],$i)and the last one _GUICtrlListView_SetImageList($List, $hImage,1) and also the one that add the PID to the list, which im not going to count, it was late at night so i didn't mind to explain it all and just added the script so you can test for yourself and maybe spot the difference, and see maybe what you did wrongExplain to me what you mean with Still doesnt work... Link to comment Share on other sites More sharing options...
LarsJ Posted August 6, 2015 Share Posted August 6, 2015 To get the right process icons you have to use a system image list and you have to use PIDLs to get the icons. You can continue with this. Eg. determine which icon you want to use if $icon = 0.expandcollapse popup#include <GuiListView.au3> #include <GuiImageList.au3> #include <WinAPIProc.au3> #include <WinAPICom.au3> #include <WinAPIShellEx.au3> _WinAPI_CoInitialize() $iStylesEx = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES) $mainForm = GUICreate("test", 500, 500) $List = _GUICtrlListView_Create($mainForm, "Process Name|PID", 0, 0, 500, 500, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($List, $iStylesEx) GUISetState(@SW_SHOW) $aProcess = ProcessList() $hImage = GetSystemImageList() _GUICtrlListView_SetImageList($List, $hImage, 1) ;create an image list to pick images from, fill none icon images with an icon from some where else to make shure the images in the image list match the processlist, or images will be wrongly asignet(srry my english xD) For $i = 0 To $aProcess[0][0] $CurIcon = _WinAPI_GetProcessFileName($aProcess[$i][1]) ;ConsoleWrite( "$CurIcon = " & $CurIcon & @CRLF ) ;$icon = _GUIImageList_AddIcon($hImage, $CurIcon,0) $icon = GetIconIndex( $CurIcon ) ;ConsoleWrite( "$icon = " & $icon & @CRLF ) ;if exe does not have an icon extract an icon from shell32 or some where else ;if $icon = -1 then _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 0);using 0 but 2 is exe icon probably not the right one, you will need to correct this one _GUICtrlListView_AddItem($List, $aProcess[$i][0], $icon) ; add items and pick the image position (in $hImage) to show for the exe with $i _GUICtrlListView_AddSubItem($List, $i, $aProcess[$i][1], 1 ) Next GUISetState() While 1 Switch GUIGetMsg() Case -3 Exit EndSwitch WEnd _WinAPI_CoUninitialize() Func GetSystemImageList( $bLargeIcons = False ) Local $tSHFILEINFO = DllStructCreate( $tagSHFILEINFO ) Local $dwFlags = BitOR( $SHGFI_USEFILEATTRIBUTES, $SHGFI_SYSICONINDEX ) If Not $bLargeIcons Then $dwFlags = BitOR( $dwFlags, $SHGFI_SMALLICON ) Local $hIml = _WinAPI_ShellGetFileInfo( ".txt", $dwFlags, $FILE_ATTRIBUTE_NORMAL, $tSHFILEINFO ) If @error Then Return SetError( @error, 0, 0 ) Return $hIml EndFunc Func GetIconIndex( $sFileName ) Local $pPIDL = _WinAPI_ShellILCreateFromPath( $sFileName ) Local $tSHFILEINFO = DllStructCreate( $tagSHFILEINFO ) Local $iFlags = BitOr( $SHGFI_PIDL, $SHGFI_SYSICONINDEX ) ShellGetFileInfo( $pPIDL, $iFlags, 0, $tSHFILEINFO ) Local $iIcon = DllStructGetData( $tSHFILEINFO, "iIcon" ) _WinAPI_CoTaskMemFree( $pPIDL ) Return $iIcon EndFunc Func ShellGetFileInfo($pPIDL, $iFlags, $iAttributes, ByRef $tSHFILEINFO) Local $aRet = DllCall('shell32.dll', 'dword_ptr', 'SHGetFileInfoW', 'ptr', $pPIDL, 'dword', $iAttributes, 'struct*', $tSHFILEINFO, 'uint', DllStructGetSize($tSHFILEINFO), 'uint', $iFlags) If @error Then Return SetError(@error, @extended, 0) Return $aRet[0] EndFunc jvds 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions 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