bladem2003 Posted July 30, 2022 Posted July 30, 2022 (edited) hi, with the code below you can change the color of the selected item in a listview. In the example below in red. Is the same possible with a treeview? expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <File.au3> #include <String.au3> #include <Array.au3> #include <GuiListView.au3> Global $iCurentSelectet = 0, $iCurentSelectetPrev = 0 $hGui = GUICreate("1", 370, 464) Global $h_ListView = GUICtrlCreateListView("", 4, 32, 362, 414) _GUICtrlListView_AddColumn($h_ListView, "Items", 362) GUICtrlCreateListViewItem("TEST", $h_ListView) GUICtrlCreateListViewItem("TEST2", $h_ListView) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState(@SW_SHOW, $hGui) While 1 Sleep(10) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit WEnd Func _WM_NOTIFY($hwnd, $iMsg, $iwParam, $ilParam) #forceref $hwnd, $iMsg, $iwParam Local Static $iHot = -1, $iHotPrev = -1 Local $hWndFrom, $iCode, $tNMHDR, $tInfo $hWndListView = $h_ListView If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($h_ListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_ITEMCHANGING ;disable blue on hover Return 1 Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) $iCurentSelectet = DllStructGetData($tInfo, "Item") _GUICtrlListView_RedrawItems($hWndListView, $iCurentSelectet, $iCurentSelectet) _GUICtrlListView_RedrawItems($hWndListView, $iCurentSelectetPrev, $iCurentSelectetPrev) $iCurentSelectetPrev = $iCurentSelectet Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage") Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem Local $dwItemSpec = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index If $dwItemSpec = $iCurentSelectet Then DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", _RGB2BGR(0xFFFFFF)) DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", _RGB2BGR(0xFF2400)) Else ; Other rows DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", _RGB2BGR(0xFFFFFF)) DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", _RGB2BGR(0x919191)) ;_RGB2BGR(0x191919)) EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Func _RGB2BGR($iColor) Local $sH = Hex($iColor, 6) Return '0x' & StringRight($sH, 2) & StringMid($sH, 3, 2) & StringLeft($sH, 2) EndFunc ;==>_RGB2BGR Edited July 30, 2022 by bladem2003
Nine Posted July 31, 2022 Posted July 31, 2022 22 hours ago, bladem2003 said: Is the same possible with a treeview? Yes, just about the same with stage and stuff. Search forum, you will find multiple examples of it... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
bladem2003 Posted August 6, 2022 Author Posted August 6, 2022 I searched the forum before posting here. can you give me a link?
Nine Posted August 7, 2022 Posted August 7, 2022 5 hours ago, bladem2003 said: I searched the forum before posting here. can you give me a link? Well you did not Search well enough “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
junkew Posted August 8, 2022 Posted August 8, 2022 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
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