jugador Posted October 25, 2019 Posted October 25, 2019 Example taken from this thread listview-item-subitem-background-colour Not able to get focus of current Listview when changing Tab. Color getting mixed up. so, how I do it without using Virtual Listview. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <TabConstants.au3> #include <GuiTab.au3> $iRows = 3 $iCols = 3 Global $hListView Global $ListView1,$ListView2 Global $aColors[$iRows][$iCols] _Example_1() ; #FUNCTION# =================== ; _Example_1() ; ============================== Func _Example_1() Local $iGui_Width = 350 Local $iGui_Height = 250 Local $Form1 = GUICreate("Form1", $iGui_Width, $iGui_Height, -1, -1) Local $idTab = GUICtrlCreateTab(2, 2, $iGui_Width - 5, $iGui_Height - 78) ;;Tab1 GUICtrlCreateTabItem("Tab1") $ListView1 = GUICtrlCreateListView("Header|Header|Header", 3, 22, $iGui_Width - 10, $iGui_Height - 100) GuiCtrlCreateListViewItem('White|White|White',$ListView1) GuiCtrlCreateListViewItem('Green|Pink|Green',$ListView1) GuiCtrlCreateListViewItem('White|White|White',$ListView1) Local $btn = GuiCtrlCreateButton('button', 20, 210, 50, 25) ;;Tab2 GUICtrlCreateTabItem("Tab2") $ListView2 = GUICtrlCreateListView("Number|Number|Number", 3, 22, $iGui_Width - 10, $iGui_Height - 100) GuiCtrlCreateListViewItem('1|1|1',$ListView2) GuiCtrlCreateListViewItem('2|2|2',$ListView2) GuiCtrlCreateListViewItem('3|3|3',$ListView2) GUICtrlCreateTabItem("") ; end tabitem definition _Tab_Check($idTab) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idTab Switch GUICtrlRead($idTab) Case 0 _Tab_Check($idTab) Case 1 _Tab_Check($idTab) EndSwitch Case $btn ;;MsgBox("", "", " Button is clicked") EndSwitch WEnd EndFunc ; #FUNCTION# =================== ; _Tab_Check ; ============================== ;;this not working color getting mixed up Func _Tab_Check($mdTab) If GUICtrlRead($mdTab) = 0 Then $aColors[1][1] = 0xffaaff $hListView = GUICtrlGetHandle ( $ListView1 ) Else $aColors[1][2] = 0x00aa00 $hListView = GUICtrlGetHandle ( $ListView2 ) EndIf EndFunc ; #FUNCTION# =================== ; WM_NOTIFY ; ============================== Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") If $aColors[$iItem][$iSubItem] <> "" Then DllStructSetData($tCustDraw, "clrTextBk", $aColors[$iItem][$iSubItem]) Else DllStructSetData($tCustDraw, "clrTextBk", 0xFFFFFF) ;white EndIf Return $CDRF_NEWFONT EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY pixelsearch 1
Danyfirex Posted October 25, 2019 Posted October 25, 2019 hello. In your tab even redraw the listviews like this: Switch GUICtrlRead($idTab) Case 0 _Tab_Check($idTab) _WinAPI_RedrawWindow(GUICtrlGetHandle($ListView1)) Case 1 _Tab_Check($idTab) _WinAPI_RedrawWindow(GUICtrlGetHandle($ListView2)) EndSwitch Saludos jugador and pixelsearch 2 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
jugador Posted October 25, 2019 Author Posted October 25, 2019 Thanks @Danyfirex yes _WinAPI_RedrawWindow() solve color missing problem when changing Tab. but how do I solve this color mixing problem. should be like this..... $ListView1 cell [1][1] => pink(0xffaaff) $ListView2 cell [1][2] => Green(0x00aa00)
pixelsearch Posted October 25, 2019 Posted October 25, 2019 Hi jugador Not sure I took the easiest way, adding a 3rd dimension to get a set of colors per tab : expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <TabConstants.au3> #include <GuiTab.au3> $iRows = 3 $iCols = 3 Global $hListView, $iIndex_TabItem Global $ListView1,$ListView2 Global $aColors[2][$iRows][$iCols] _Example_1() ; #FUNCTION# =================== ; _Example_1() ; ============================== Func _Example_1() Local $iGui_Width = 350 Local $iGui_Height = 250 Local $Form1 = GUICreate("Form1", $iGui_Width, $iGui_Height, -1, -1) Local $idTab = GUICtrlCreateTab(2, 2, $iGui_Width - 5, $iGui_Height - 78) ;;Tab1 GUICtrlCreateTabItem("Tab1") $ListView1 = GUICtrlCreateListView("Header|Header|Header", 3, 22, $iGui_Width - 10, $iGui_Height - 100) GuiCtrlCreateListViewItem('White|White|White',$ListView1) GuiCtrlCreateListViewItem('Green|Pink|Green',$ListView1) GuiCtrlCreateListViewItem('White|White|White',$ListView1) Local $btn = GuiCtrlCreateButton('button', 20, 210, 50, 25) ;;Tab2 GUICtrlCreateTabItem("Tab2") $ListView2 = GUICtrlCreateListView("Number|Number|Number", 3, 22, $iGui_Width - 10, $iGui_Height - 100) GuiCtrlCreateListViewItem('1|1|1',$ListView2) GuiCtrlCreateListViewItem('2|2|2',$ListView2) GuiCtrlCreateListViewItem('3|3|3',$ListView2) GUICtrlCreateTabItem("") ; end tabitem definition _Tab_Check($idTab) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idTab $iIndex_TabItem = GUICtrlRead($idTab) Switch $iIndex_TabItem Case 0 _Tab_Check($idTab) _WinAPI_RedrawWindow(GUICtrlGetHandle($ListView1)) Case 1 _Tab_Check($idTab) _WinAPI_RedrawWindow(GUICtrlGetHandle($ListView2)) EndSwitch Case $btn MsgBox("", "", " Button is clicked") EndSwitch WEnd EndFunc ; #FUNCTION# =================== ; _Tab_Check ; ============================== Func _Tab_Check($mdTab) If GUICtrlRead($mdTab) = 0 Then $aColors[0][1][1] = 0xffaaff ; pink $hListView = GUICtrlGetHandle ( $ListView1 ) Else $aColors[1][1][2] = 0x00aa00 ; dark green $hListView = GUICtrlGetHandle ( $ListView2 ) EndIf EndFunc ; #FUNCTION# =================== ; WM_NOTIFY ; ============================== Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") If $aColors[$iIndex_TabItem][$iItem][$iSubItem] <> "" Then DllStructSetData($tCustDraw, "clrTextBk", $aColors[$iIndex_TabItem][$iItem][$iSubItem]) Else DllStructSetData($tCustDraw, "clrTextBk", 0xFFFFFF) ;white EndIf Return $CDRF_NEWFONT EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY jugador 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
Nine Posted October 25, 2019 Posted October 25, 2019 Here one way you could do it : expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <TabConstants.au3> #include <GuiTab.au3> Const $iTab = 2 Const $iRows = 3 Const $iCols = 3 Global $hListView, $idTab Global $ListView1,$ListView2 Global $aColors[$iTab][$iRows][$iCols] _Example_1() ; #FUNCTION# =================== ; _Example_1() ; ============================== Func _Example_1() Local $iGui_Width = 350 Local $iGui_Height = 250 Local $Form1 = GUICreate("Form1", $iGui_Width, $iGui_Height, -1, -1) Local $idTab = GUICtrlCreateTab(2, 2, $iGui_Width - 5, $iGui_Height - 78) ;;Tab1 GUICtrlCreateTabItem("Tab1") $ListView1 = GUICtrlCreateListView("Header|Header|Header", 3, 22, $iGui_Width - 10, $iGui_Height - 100) GuiCtrlCreateListViewItem('White|White|White',$ListView1) GuiCtrlCreateListViewItem('Green|Pink|Green',$ListView1) GuiCtrlCreateListViewItem('White|White|White',$ListView1) Local $btn = GuiCtrlCreateButton('button', 20, 210, 50, 25) ;;Tab2 GUICtrlCreateTabItem("Tab2") $ListView2 = GUICtrlCreateListView("Number|Number|Number", 3, 22, $iGui_Width - 10, $iGui_Height - 100) GuiCtrlCreateListViewItem('1|1|1',$ListView2) GuiCtrlCreateListViewItem('2|2|2',$ListView2) GuiCtrlCreateListViewItem('3|3|3',$ListView2) GUICtrlCreateTabItem("") ; end tabitem definition ;init background colors $aColors[0][1][1] = 0xffaaff $aColors[1][1][2] = 0x00aa00 _Tab_Check($idTab) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idTab Switch GUICtrlRead($idTab) Case 0 _Tab_Check($idTab) _WinAPI_RedrawWindow(GUICtrlGetHandle($ListView1)) Case 1 _Tab_Check($idTab) _WinAPI_RedrawWindow(GUICtrlGetHandle($ListView2)) EndSwitch Case $btn ;;MsgBox("", "", " Button is clicked") EndSwitch WEnd EndFunc ; #FUNCTION# =================== ; _Tab_Check ; ============================== ;;this not working color getting mixed up Func _Tab_Check($mdTab) $idTab = GUICtrlRead($mdTab) If $idTab = 0 Then $hListView = GUICtrlGetHandle ( $ListView1 ) Else $hListView = GUICtrlGetHandle ( $ListView2 ) EndIf EndFunc ; #FUNCTION# =================== ; WM_NOTIFY ; ============================== Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") If $aColors[$idTab][$iItem][$iSubItem] <> "" Then DllStructSetData($tCustDraw, "clrTextBk", $aColors[$idTab][$iItem][$iSubItem]) Else DllStructSetData($tCustDraw, "clrTextBk", 0xFFFFFF) ;white EndIf Return $CDRF_NEWFONT EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY jugador 1 “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
pixelsearch Posted October 25, 2019 Posted October 25, 2019 Hi Nine, we did it the same way Jugador, in case you want all other cells to have the default background, no matter the user's Windows theme (each user getting a different background color), this seems to work nicely : Else ; DllStructSetData($tCustDraw, "clrTextBk", 0xFFFFFF) ;white DllStructSetData($tCustDraw, "clrTextBk", 0xFF000000) ; $CLR_DEFAULT EndIf jugador 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
jugador Posted October 25, 2019 Author Posted October 25, 2019 @pixelsearch and @Nine Thanks. @pixelsearch as a learner suggestion, modification everything welcome. So I miss the 3rd dimension.😅
pixelsearch Posted October 25, 2019 Posted October 25, 2019 Thank you jugador but you know, I have few knowledge in AutoIt compared to many others posters. Just like you, I try actually to improve my knowledge concerning ListView and study, one by one, the different useful events that can be used with WM_NOTIFY, like the whole gang found in the help file example, topic _GUICtrlListView_Create() Ideally, I would like to be able to easily edit any subitem (there are several posts concerning this), or move through subitems using the 4 directions keys, change any subitem color easily (maybe with a right click and context menu), think about what Enter should do (probably start editing the subitem), what should double click do on any subitem etc... The question is why script all this and not use an Excel sheet which actually is designed to do the same ? I guess it's more a challenge than a real need in fact, plus it may help me (or you) to learn more about AutoIt. Anyway, a few minutes ago, I found a good script written by Melba23 (again) showing how to Select subitems (like when you select a single cell in Excel) and it works nicely. This could be a good start to learn that $LVN_ITEMCHANGED he scripted in WM_NOTIFY, also $NM_CUSTOMDRAW is used in his script. In case you test it, it requires the file "edit-zoom_step_av_value.csv" found just before Melba's 23 script. But I don't know why he used : $aInfo = _GUICtrlListView_SubItemHitTest($hListview, $aInfo[0] - 24, $aInfo[1] - 100) ; Upper left position of ListView within GUI - so must match actual position When I tried it in a simpler way (after quickly reading the help file concerning this function), what follows seems to do same, but I have to check more because I'm certainly mistaken : $aInfo = _GUICtrlListView_SubItemHitTest($hListview, -1, -1) Also, during his $NM_CUSTOMDRAW, for all other "cells" (except the selected one), changing his backcolor from White to $CLR_DEFAULT (like shown in my precedent post) gives good results on my computer because my windows background are grey. But all this requires a lot of time... I see you're a member for 10 months now (it's 1 year and a half for me) and it's a strange feeling when you look at some members posts, dated 12-13 years of more, then you look into their profiles and you see they were members here during several years, then they disappeared in 2013 or 2014... and other new members arrive... just like what happens in real life (unfortunately). I wish they were all here again ! jugador 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
jugador Posted October 25, 2019 Author Posted October 25, 2019 (edited) Member for 10 month but practicing Autoit just for 4/5 months. No coding background, so don’t know how much I can improve. Anyway I search on WM_NOTIFY Listview and messages & got this individual-control-info but this too complicated for me at this moment. This is good listview-color-hover-item Edited October 26, 2019 by jugador add link
pixelsearch Posted November 12, 2019 Posted November 12, 2019 Just now, jugador said: as a learner suggestion, modification everything welcome. Hi jugador With the help of mikell, we scripted a simple but solid WM_NOTIFY function in a thread called "Wandering through ListView" It allows to select any item or subitem by using the 4 direction keys in a basic Listview. The Enter key is also managed. The function can be reused in other scripts without modification, depending on everyone's need. If you got questions about the function, don't hesitate to ask them in the other thread (found in 'AutoIt Example Scripts') jugador 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
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