cojms1 Posted August 14, 2007 Share Posted August 14, 2007 I am writing an application that loops through a list of servers running some checks. I decided to use a listview to display the results. The intention is for the listview to have 2 colums. 1 for the task that is running and 1 for the result. The task should be displayed in the listview whilst running and the result column populated when the task has finished. The results column should display only an icon of a tick or cross. My problem is that I don't seem to be able to make a ListViewSubItem have an icon associated with it. Can anybody help? Link to comment Share on other sites More sharing options...
Zedna Posted August 14, 2007 Share Posted August 14, 2007 Search is your friend Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
randallc Posted August 14, 2007 Share Posted August 14, 2007 Hi,For working scripts, see also "SearchMiner" from my signature, and [the link above pooints to gary's working script too, but there is a comment on difficulty changing dynamically which is not warranted...]ExIcons7.zipBest, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
cojms1 Posted August 16, 2007 Author Share Posted August 16, 2007 Hi, Thanks for your help so far. I have attached a screenshot with what I have so far. As you can see the green tick appears in both columns. Is there a way to only have it appear in the 'Result' column and not the 'Task' column? Link to comment Share on other sites More sharing options...
Zedna Posted August 16, 2007 Share Posted August 16, 2007 (edited) Hi,Thanks for your help so far. I have attached a screenshot with what I have so far. As you can see the green tick appears in both columns. Is there a way to only have it appear in the 'Result' column and not the 'Task' column?Post your script to get help. Edited August 16, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
cojms1 Posted August 16, 2007 Author Share Posted August 16, 2007 (edited) The code needs tidying up but here it is: - expandcollapse popup#include <GuiStatusBar.au3> #include <GuiConstants.au3> #include <GuiListView.au3> $hwndMain = 0 $hwndProgress = 0 $lblProgress = 0 $hwndSB = 0 $cidLVW = 0 $hwndLVW = 0 $TICK_ICO = @tempdir & "\tick.ico" $CROSS_ICO = @tempdir & "\cross.ico" $LVW_HEAD = "Task|Result" Const $LVM_SETIMAGELIST = ($LVM_FIRST + 3) Const $LVIF_IMAGE = 0x0002 Const $LVM_SETITEM = ($LVM_FIRST + 6) CreateMainWindow() GUICtrlCreateListViewItem("Test", $cidLVW) sleep(2000) _GUICtrlListViewSetItemImage($hwndLVW, 0, 1, 0) ; listview handle, index, subitem, image index while 1 sleep(100) wend ;========================================================================== ; Aim: To create the main window that will house all of the logging ;========================================================================== Func CreateMainWindow() $hwndMain = GUICreate("Farm Management Log Window", -1, -1, -1, -1, $WS_CAPTION) $hwndSB = _GUICtrlStatusBarCreate($hwndMain, -1, "") ;GUISetState(@SW_SHOW, $hwndMain) $pos = WinGetPos($hwndMain) $left = 10 $top = 10 $width = $pos[2] - ($left * 3) $cidLVW = GUICtrlCreateListView($LVW_HEAD, $left, $top, $width) GUICtrlSendMsg($cidLVW, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_SUBITEMIMAGES) $hwndLVW = ControlGetHandle($hwndMain, "", $cidLVW) $h_images = _GUICtrlListViewCreateImageList(16, 16, 0x0021, 0, 4, $LVSIL_SMALL) ;create the imagelist _GUICtrlListViewImageListAdd($h_images, @scriptdir & "\tick.ico") _GUICtrlListViewImageListAdd($h_images, @scriptdir & "\cross.ico") _GuiCtrlListViewSetImageList($hwndLVW, $h_images, $LVSIL_SMALL) GUISetState() EndFunc ; ; ; Func ProgressUpdate($text) _GUICtrlStatusBarSetText($hwndSB, $text) EndFunc #region Image Lists *********************************************************************************************** Func _GUICtrlListViewCreateImageList($iCX = 16, $iCY = 16, $iFlags = 0x0021, $iInitial = 4, $iGrow = 4, $iType = 0) Local $h_images, $aResult If @error Then Return SetError(-1, -1, 0) $h_images = DllCall("ComCtl32.dll", "hwnd", "ImageList_Create", "int", $iCX, "int", $iCY, _ "int", $iFlags, "int", $iInitial, "int", $iGrow) If @error Then Return SetError(-1, -1, 0) $h_images = $h_images[0] Return $h_images EndFunc ;==>_GUICtrlListViewCreateImageList Func _GUICtrlListViewDestroyImageList($h_images) Local $result = DllCall("ComCtl32.dll", "int", "ImageList_Destroy", "hwnd", $h_images) If @error Then Return SetError(-1, -1, 0) Return $result[0] EndFunc ;==>_GUICtrlListViewDestroyImageList Func _GuiCtrlListViewSetImageList($h_LV, $h_images, $iType = 0) Local $iResult = _SendMessage($h_LV, $LVM_SETIMAGELIST, $iType, $h_images) If @error Then Return SetError(-1, -1, 0) EndIf Return $iResult EndFunc ;==>_GuiCtrlListViewSetImageList Func _GUICtrlListViewImageListAdd($hImageList, $szFile, $nIconID = -1, $i_Width = -1, $i_Height = -1, $Mask = 0) Local $result Local $ext = StringLower(StringRight($szFile, 3)) If $ext = "ico" Or $ext = "cur" Or $ext = "exe" Or $ext = "dll" Then If $nIconID = -1 Then $nIconID = 0 Local $hIcon = DllStructCreate("int") $result = DllCall("shell32.dll", "int", "ExtractIconEx", "str", $szFile, "int", $nIconID, "hwnd", 0, "ptr", DllStructGetPtr($hIcon), "int", 1) If @error Then Return SetError(-1, -1, 0) $result = $result[0] If $result > 0 Then Local $icon_handle = DllStructGetData($hIcon, 1) $result = DllCall("ComCtl32.dll", "int", "ImageList_ReplaceIcon", "hwnd", $hImageList, "int", -1, _ "hwnd", $icon_handle) If @error Then Return SetError(-1, -1, 0) DllCall("user32.dll", "int", "DestroyIcon", "hwnd", $icon_handle) If @error Then Return SetError(-1, -1, 0) Return $result[0] EndIf ElseIf $ext = "bmp" Then Local $fuLoad = $LR_LOADFROMFILE If $i_Width = -1 Then $i_Width = 20 If $i_Height = -1 Then $i_Height = 20 Local $h_Bitmap = DllCall('user32.dll', 'hwnd', 'LoadImage', 'hwnd', 0, 'str', $szFile, _ 'int', 0, 'int', $i_Width, 'int', $i_Height, 'int', $fuLoad) If @error Then Return SetError(-1, -1, 0) $result = DllCall("ComCtl32.dll", "int", "ImageList_Add", "hwnd", $hImageList, "hwnd", $h_Bitmap[0], "hwnd", $Mask) If @error Then Return SetError(-1, -1, 0) DllCall('gdi32.dll', 'int', 'DeleteObject', 'hwnd', $h_Bitmap[0]) Return $result[0] EndIf EndFunc ;==>_GUICtrlListViewImageListAdd Func _GUICtrlListViewImageListRemove($hImageList, $iIndex = -1) ; -1 removes all images Local $result = DllCall("ComCtl32.dll", "int", "ImageList_Remove", "hwnd", $hImageList, "int", $iIndex) If @error Then Return SetError(-1, -1, 0) Return $result[0] EndFunc ;==>_GUICtrlListViewImageListRemove Func _GUICtrlListViewReleaseBitMap(ByRef $hLVBitmap) DllCall('gdi32.dll', 'int', 'DeleteObject', 'hwnd', $hLVBitmap) If @error Then Return SetError(-1, -1, 0) EndFunc ;==>_GUICtrlListViewReleaseBitMap #endregion Images Lists *********************************************************************************************** Func _GUICtrlListViewSetItemImage($h_ListView, $i_index = 0, $i_subindex = 0, $i_IconIdex = 0) If Not IsHWnd($h_ListView) Then Return SetError(-1, -1, 0) Local $LVITEM_pointer, $iResult, $struct_LVITEM $struct_LVITEM = DllStructCreate("int;int;int;int;int;ptr;int;int;int;int") If @error Then Return SetError(-1, -1, 0) EndIf DllStructSetData($struct_LVITEM, $LVI_MASK, $LVIF_IMAGE) DllStructSetData($struct_LVITEM, $LVI_IITEM, $i_index) DllStructSetData($struct_LVITEM, $LVI_ISUBITEM, $i_subindex) DllStructSetData($struct_LVITEM, $LVI_IIMAGE, $i_IconIdex) $LVITEM_pointer = DllStructGetPtr($struct_LVITEM) If @error Then Return SetError(-1, -1, 0) $iResult = _SendMessage($h_ListView, $LVM_SETITEM, 0, $LVITEM_pointer) If @error Then Return SetError(-1, -1, 0) ;**************************************************************************************** EndFunc ;==>_GUICtrlListViewSetItemImage Edited August 16, 2007 by cojms1 Link to comment Share on other sites More sharing options...
randallc Posted August 16, 2007 Share Posted August 16, 2007 Hi, youneed to itmize your added images; global $image_indexes[3], $image_indexes2[5] _GUICtrlListViewSetItemImage($hwndLVW, 0, 0, $image_indexes[0]) ; listview handle, index, subitem, image index _GUICtrlListViewSetItemImage($hwndLVW, 0, 1,$image_indexes[1]) ; listview handle, index, subitem, image index $image_indexes[0]=_GUICtrlListViewImageListAdd($h_images, $ar_Images[0][0], $ar_Images[1][0] ) $image_indexes[1]=_GUICtrlListViewImageListAdd($h_images, $ar_Images[0][1] , $ar_Images[1][1]) ;~ $image_indexes[0]=_GUICtrlListViewImageListAdd($h_images, @scriptdir & "\tick.ico") ;~ $image_indexes[1]=_GUICtrlListViewImageListAdd($h_images, @scriptdir & "\cross.ico")working modified script; expandcollapse popup; iconsLVcojms1.au3 #include <GuiStatusBar.au3> #include <GuiConstants.au3> #include <GuiListView.au3> #include <array.au3> $hwndMain = 0 $hwndProgress = 0 $lblProgress = 0 $hwndSB = 0 $cidLVW = 0 $hwndLVW = 0 $TICK_ICO = @tempdir & "\tick.ico" $CROSS_ICO = @tempdir & "\cross.ico" $LVW_HEAD = "Task|Result" Global $ar_Images[2][2] = [[ @WindowsDir & "\Cursors\arrow_m.cur", "shell32.dll"], [0, 22]], $s_ExtImages, $szIconFileDef, $nIconDef;,$h_Gui,$ListView ;~ _ArrayDisplay($ar_Images) global $image_indexes[3], $image_indexes2[5] Const $LVM_SETIMAGELIST = ($LVM_FIRST + 3) Const $LVIF_IMAGE = 0x0002 Const $LVM_SETITEM = ($LVM_FIRST + 6) Global Const $LR_LOADFROMFILE = 0x0010 Global Const $LR_LOADMAP3DCOLORS = 0x1000 Global Const $LR_DEFAULTSIZE = 0x0040 Global Const $LR_LOADTRANSPARENT = 0x20 ;~ Global Const $LVM_GETIMAGELIST = ($LVM_FIRST + 2) ;~ Global Const $LVM_SETIMAGELIST = ($LVM_FIRST + 3) #endregion End Global variables Global Const $WM_KEYDOWN = 0x0100 Global Const $LVN_ENDLABELEDITA = (-106) Global $bUPDATELOSTFOCUS = True ;not save editing if another cell is clicked Global $bEDITondblclick = True ;Must dblclick to edit Global $old_col Global $LISTVIEWCTRL = -999 Global $Gui, $editFlag Global $editCtrl ;= the CtrlId of the editing control. Global $LVcolControl[1] = [0] ;0= edit, 1= combo, 2= calendar 99 = readonly Global $lvEdit, $lvCombo, $lvDate Global $LVINFO[10]; CreateMainWindow() GUICtrlCreateListViewItem("Test|test2", $cidLVW) ;~ sleep(2000) _GUICtrlListViewSetItemImage($hwndLVW, 0, 0, $image_indexes[0]) ; listview handle, index, subitem, image index _GUICtrlListViewSetItemImage($hwndLVW, 0, 1,$image_indexes[1]) ; listview handle, index, subitem, image index while 1 sleep(100) wend ;========================================================================== ; Aim: To create the main window that will house all of the logging ;========================================================================== Func CreateMainWindow() $hwndMain = GUICreate("Farm Management Log Window", -1, -1, -1, -1, $WS_CAPTION) $hwndSB = _GUICtrlStatusBarCreate($hwndMain, -1, "") ;GUISetState(@SW_SHOW, $hwndMain) $pos = WinGetPos($hwndMain) $left = 10 $top = 10 $width = $pos[2] - ($left * 3) $cidLVW = GUICtrlCreateListView($LVW_HEAD, $left, $top, $width) GUICtrlSendMsg($cidLVW, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_SUBITEMIMAGES) $hwndLVW = ControlGetHandle($hwndMain, "", $cidLVW) $h_images = _GUICtrlListViewCreateImageList(16, 16, 0x0021, 0, 4, $LVSIL_SMALL) ;create the imagelist $image_indexes[0]=_GUICtrlListViewImageListAdd($h_images, $ar_Images[0][0], $ar_Images[1][0] ) $image_indexes[1]=_GUICtrlListViewImageListAdd($h_images, $ar_Images[0][1] , $ar_Images[1][1]) ;~ $image_indexes[0]=_GUICtrlListViewImageListAdd($h_images, @scriptdir & "\tick.ico") ;~ $image_indexes[1]=_GUICtrlListViewImageListAdd($h_images, @scriptdir & "\cross.ico") _GuiCtrlListViewSetImageList($hwndLVW, $h_images, $LVSIL_SMALL) GUISetState() EndFunc ; ; ; Func ProgressUpdate($text) _GUICtrlStatusBarSetText($hwndSB, $text) EndFunc #region Image Lists *********************************************************************************************** Func _GUICtrlListViewCreateImageList($iCX = 16, $iCY = 16, $iFlags = 0x0021, $iInitial = 4, $iGrow = 4, $iType = 0) Local $h_images, $aResult If @error Then Return SetError(-1, -1, 0) $h_images = DllCall("ComCtl32.dll", "hwnd", "ImageList_Create", "int", $iCX, "int", $iCY, _ "int", $iFlags, "int", $iInitial, "int", $iGrow) If @error Then Return SetError(-1, -1, 0) $h_images = $h_images[0] Return $h_images EndFunc ;==>_GUICtrlListViewCreateImageList Func _GUICtrlListViewDestroyImageList($h_images) Local $result = DllCall("ComCtl32.dll", "int", "ImageList_Destroy", "hwnd", $h_images) If @error Then Return SetError(-1, -1, 0) Return $result[0] EndFunc ;==>_GUICtrlListViewDestroyImageList Func _GuiCtrlListViewSetImageList($h_LV, $h_images, $iType = 0) Local $iResult = _SendMessage($h_LV, $LVM_SETIMAGELIST, $iType, $h_images) If @error Then Return SetError(-1, -1, 0) EndIf Return $iResult EndFunc ;==>_GuiCtrlListViewSetImageList Func _GUICtrlListViewImageListAdd($hImageList, $szFile, $nIconID = -1, $i_Width = -1, $i_Height = -1, $Mask = 0) Local $result Local $ext = StringLower(StringRight($szFile, 3)) If $ext = "ico" Or $ext = "cur" Or $ext = "exe" Or $ext = "dll" Then If $nIconID = -1 Then $nIconID = 0 Local $hIcon = DllStructCreate("int") $result = DllCall("shell32.dll", "int", "ExtractIconEx", "str", $szFile, "int", $nIconID, "hwnd", 0, "ptr", DllStructGetPtr($hIcon), "int", 1) If @error Then Return SetError(-1, -1, 0) $result = $result[0] If $result > 0 Then Local $icon_handle = DllStructGetData($hIcon, 1) $result = DllCall("ComCtl32.dll", "int", "ImageList_ReplaceIcon", "hwnd", $hImageList, "int", -1, _ "hwnd", $icon_handle) If @error Then Return SetError(-1, -1, 0) DllCall("user32.dll", "int", "DestroyIcon", "hwnd", $icon_handle) If @error Then Return SetError(-1, -1, 0) Return $result[0] EndIf ElseIf $ext = "bmp" Then Local $fuLoad = $LR_LOADFROMFILE If $i_Width = -1 Then $i_Width = 20 If $i_Height = -1 Then $i_Height = 20 Local $h_Bitmap = DllCall('user32.dll', 'hwnd', 'LoadImage', 'hwnd', 0, 'str', $szFile, _ 'int', 0, 'int', $i_Width, 'int', $i_Height, 'int', $fuLoad) If @error Then Return SetError(-1, -1, 0) $result = DllCall("ComCtl32.dll", "int", "ImageList_Add", "hwnd", $hImageList, "hwnd", $h_Bitmap[0], "hwnd", $Mask) If @error Then Return SetError(-1, -1, 0) DllCall('gdi32.dll', 'int', 'DeleteObject', 'hwnd', $h_Bitmap[0]) Return $result[0] EndIf EndFunc ;==>_GUICtrlListViewImageListAdd Func _GUICtrlListViewImageListRemove($hImageList, $iIndex = -1) ; -1 removes all images Local $result = DllCall("ComCtl32.dll", "int", "ImageList_Remove", "hwnd", $hImageList, "int", $iIndex) If @error Then Return SetError(-1, -1, 0) Return $result[0] EndFunc ;==>_GUICtrlListViewImageListRemove Func _GUICtrlListViewReleaseBitMap(ByRef $hLVBitmap) DllCall('gdi32.dll', 'int', 'DeleteObject', 'hwnd', $hLVBitmap) If @error Then Return SetError(-1, -1, 0) EndFunc ;==>_GUICtrlListViewReleaseBitMap #endregion Images Lists *********************************************************************************************** Func _GUICtrlListViewSetItemImage($h_ListView, $i_index = 0, $i_subindex = 0, $i_IconIdex = 0) If Not IsHWnd($h_ListView) Then Return SetError(-1, -1, 0) Local $LVITEM_pointer, $iResult, $struct_LVITEM $struct_LVITEM = DllStructCreate("int;int;int;int;int;ptr;int;int;int;int") If @error Then Return SetError(-1, -1, 0) EndIf DllStructSetData($struct_LVITEM, $LVI_MASK, $LVIF_IMAGE) DllStructSetData($struct_LVITEM, $LVI_IITEM, $i_index) DllStructSetData($struct_LVITEM, $LVI_ISUBITEM, $i_subindex) DllStructSetData($struct_LVITEM, $LVI_IIMAGE, $i_IconIdex) $LVITEM_pointer = DllStructGetPtr($struct_LVITEM) If @error Then Return SetError(-1, -1, 0) $iResult = _SendMessage($h_ListView, $LVM_SETITEM, 0, $LVITEM_pointer) If @error Then Return SetError(-1, -1, 0) ;**************************************************************************************** EndFunc ;==>_GUICtrlListViewSetItemImagebest, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
randallc Posted August 16, 2007 Share Posted August 16, 2007 hi, Sorry if I made that more complex than necessary; [i keep 2 arrys of my added image values, so the direct values don't work for me, but they do in your simpler example...] _GUICtrlListViewSetItemImage($hwndLVW, 0, 0, 0) ; listview handle, index, subitem, image index _GUICtrlListViewSetItemImage($hwndLVW, 0, 1,1) ; listview handle, index, subitem, image index Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
cojms1 Posted August 17, 2007 Author Share Posted August 17, 2007 (edited) @randallcThanks for the response. I have looked at the script but that also adds an icon to the ListViewItem as well as the ListViewSubItem. I tried removing the line that placed an icon on the ListViewItem but that still resulted in icon being placed on it.I'm hoping to have no icon on the ListViewItem and an icon on the ListViewSubItem. Is this possible? All examples I have found seem to have an icon on items and subitems or just on items. Edited August 17, 2007 by cojms1 Link to comment Share on other sites More sharing options...
randallc Posted August 17, 2007 Share Posted August 17, 2007 @randallcThanks for the response. I have looked at the script but that also adds an icon to the ListViewItem as well as the ListViewSubItem. I tried removing the line that placed an icon on the ListViewItem but that still resulted in icon being placed on it.I'm hoping to have no icon on the ListViewItem and an icon on the ListViewSubItem. Is this possible? All examples I have found seem to have an icon on items and subitems or just on items.Works in 3.2.5.5 latest beta; though it leaves a gap on the item line wide enough for an image!Best, randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
cojms1 Posted August 20, 2007 Author Share Posted August 20, 2007 @randallcMany thanks randallc. I have just downloaded the beta and it works. As you have said though there is that space. 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