Burgaud Posted April 16, 2018 Posted April 16, 2018 Listbox can retain the Highlight even if the listbox is not in focus. Whereas a ListView looses Hightlight when it is no longer in focus. A Listbox cannot change color/font of an item. Listview can. Am I correct? I am stuck for the last week or so figuring out how to do maintain highlight and I need ability to change color/font of selection. I have been shuffling between ListBox and ListView. I know there are sample scripts of listview sustaining highlights, but the codes are too cryptic to easily comprehend.
BrewManNH Posted April 16, 2018 Posted April 16, 2018 Regardless of the language used, you're going to have to do some code wizardry to get it working. https://www.google.com/search?q=listview+highlight+when+loses+focus&ie=utf-8&oe=utf-8 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Moderators Melba23 Posted April 16, 2018 Moderators Posted April 16, 2018 Burgaud, Quote a ListView looses Hightlight when it is no longer in focus Not so. By default, an Autoit ListView retains the selection when focus is removed because of the $LVS_SHOWSELALWAYS style. What you and others have found is that the default Windows colours for the ListView background and the "selected but not in focus" item are very close (0xFFFFFF vs 0xF0F0F0) which makes the still-selected item quite hard to see on some monitors. If you change the ListView background colour you can see the item much more clearly when focus is lost: #include <GUIConstantsEx.au3> #include <GUIListView.au3> $hGUI = GUICreate("Test", 500, 500) $cLV = GUICtrlCreateListView("", 10, 10, 200, 200) GUICtrlSetBkColor($cLV, 0xC4C4C4) _GUICtrlListView_AddColumn($cLV, "Col 0", 85) _GUICtrlListView_AddColumn($cLV, "Col 1", 85) For $i = 0 to 5 GUICtrlCreateListViewItem("Item " & $i & "|SubItem " & $i, $cLV) Next $cButton = GUICtrlCreateButton("Get Focus", 10, 300, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Earthshine Posted April 16, 2018 Posted April 16, 2018 (edited) nm Edited April 16, 2018 by Earthshine My resources are limited. You must ask the right questions
Burgaud Posted April 16, 2018 Author Posted April 16, 2018 (edited) Still not it. What i am referring to is the blue highlight when you click on a listview item. i need to retain that color when I click on some other GUI. Listboxes maintains *that* highlight color; but Listview highlight turns gray when I click away which is not what I want. Here is what I have been testing out: expandcollapse popup;--------------------------------------------------------------------------------------------------- GLOBAL $TITLE = "T&C 2" GLOBAL $VERSION = "(v20180416)" #include <Color.au3> #include <Math.au3> #include <Date.au3> #include <GuiListBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <guiconstants.au3> #include <ColorConstants.au3> #include <Misc.au3> #include <GuiListView.au3> ;--------------------------------------------------------------------------------------------------- ; GUI Routines ;--------------------------------------------------------------------------------------------------- Global $FontSize= 14 Global $GUIMinX = 1220, $GUIMaxX = @DesktopWidth Global $GUIMinY = _Min(600,@DesktopHeight * 0.75), $GUIMaxY = @DesktopHeight Global $MW = GUICreate($TITLE & " " & $VERSION, $GUIMinX, $GUIMinY, -1, -1, BitOR($WS_MAXIMIZE,$WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX)) GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO") func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam) $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam) DllStructSetData($tagMaxinfo, 7, $GUIMinX) ; min X DllStructSetData($tagMaxinfo, 8, $GUIMinY) ; min Y DllStructSetData($tagMaxinfo, 9, $GUIMaxX) ; max X DllStructSetData($tagMaxinfo, 10, $GUIMaxY) ; max Y return 0 endfunc ;==>WM_GETMINMAXINFO func MakeLabel($text="", $x=0, $y=0, $w=100, $h=50, $fontface="Courier New", $fontsize=$FontSize, $fontweight=500, $fontcolor=0x000000, $bgcolor=0x80C0FF) local $handle = GUICtrlCreateLabel($text, $x, $y, $w, $h, $SS_SUNKEN) GUICtrlSetFont($handle, $fontsize, $fontweight, 0, $fontface, 5) GUICtrlSetColor($handle, $fontcolor) GUICtrlSetBkColor($handle, $bgcolor) GUICtrlSetResizing($handle, $GUI_DOCKALL) return $handle endfunc func MakeList ($text="", $x=0, $y=0, $w=100, $h=50, $fontface="Courier New", $fontsize=$FontSize, $fontweight=400, $fontcolor=0x000000, $bgcolor=0xD0D0D0) local $handle = GUICtrlCreateList($text, $x, $y, $w, $h, BitOR($WS_BORDER, $WS_VSCROLL)) GUICtrlSetFont($handle, $fontsize, $fontweight, 0, $fontface, 5) GUICtrlSetColor($handle, $fontcolor) GUICtrlSetBkColor($handle, $bgcolor ) GUICtrlSetResizing($handle, $GUI_DOCKALL) return $handle endfunc func MakeListView ($text="", $x=0, $y=0, $w=100, $h=50, $fontface="Courier New", $fontsize=$FontSize, $fontweight=400, $fontcolor=0x000000, $bgcolor=0xD0D0D0) local $handle = GUICtrlCreateListView($text, $x, $y, $w, $h, BitOR($LVS_SINGLESEL,$LVS_NOCOLUMNHEADER), BitOR($LVS_EX_FULLROWSELECT,0)) GUICtrlSetFont($handle, $fontsize, $fontweight, 0, $fontface, 5) GUICtrlSetColor($handle, $fontcolor) GUICtrlSetBkColor($handle, $bgcolor ) GUICtrlSetResizing($handle, $GUI_DOCKALL) return $handle endfunc func MakeEdit ($text="", $x=0, $y=0, $w=100, $h=50, $fontface="Courier New", $fontsize=$FontSize, $fontweight=400, $fontcolor=0x000000, $bgcolor=0xD0D0D0) local $handle = GUICtrlCreateEdit($text, $x, $y, $w, $h, BitOr($ES_MULTILINE,$ES_WANTRETURN) ) GUICtrlSetFont($handle, $fontsize, $fontweight, 0, $fontface, 5) GUICtrlSetColor($handle, $fontcolor) GUICtrlSetBkColor($handle, $bgcolor ) GUICtrlSetResizing($handle, $GUI_DOCKALL) return $handle endfunc func MakeInput ($text="", $x=0, $y=0, $w=100, $h=50, $fontface="Courier New", $fontsize=$FontSize, $fontweight=400, $fontcolor=0x000000, $bgcolor=0xFFFFFF) local $handle = GUICtrlCreateInput($text, $x, $y, $w, $h ) GUICtrlSetFont($handle, $fontsize, $fontweight, 0, $fontface, 5) GUICtrlSetColor($handle, $fontcolor) GUICtrlSetBkColor($handle, $bgcolor ) GUICtrlSetResizing($handle, $GUI_DOCKALL) return $handle endfunc func MakeButton($text="", $x=0, $y=0, $w=100, $h=50, $fontface="Courier New", $fontsize=$FontSize, $fontweight=400, $fontcolor=0x000000, $bgcolor=0x80C0FF) local $handle = GUICtrlCreateButton($text, $x, $y, $w, $h) GUICtrlSetFont($handle, $fontsize, $fontweight, 0, $fontface, 5) ; GUICtrlSetColor($handle, $fontcolor) ; these makes button ugly ; GUICtrlSetBkColor($handle, $bgcolor ) GUICtrlSetResizing($handle, $GUI_DOCKALL) return $handle endfunc func MakeTab($x=0, $y=0, $w=100, $h=50, $fontface="Courier New", $fontsize=$FontSize, $fontweight=400, $fontcolor=0x000000, $bgcolor=0x80C0FF) local $handle = GUICtrlCreateTab($text, $x, $y, $w, $h) GUICtrlSetFont($handle, $fontsize, $fontweight, 0, $fontface, 5) GUICtrlSetColor($handle, $fontcolor) GUICtrlSetBkColor($handle, $bgcolor ) GUICtrlSetResizing($handle, $GUI_DOCKALL) return $handle endfunc Local $menu1 = GUICtrlCreateMenu("&File") ; Local $menu2 = GUICtrlCreateMenu("&Account") ; local $LabelAccount = MakeLabel("Account List", 0,0,0,0,"Courier New", $FontSize*1.2) local $ListAccount = MakeListView("|",0,0,0,0,"Courier New", $FontSize,400,0x000000,0x80C0FF) local $hListAccount = GUICtrlGetHandle($ListAccount) local $LabelName = MakeLabel("Account Name", 0,0,0,0,"Courier New", $FontSize*1.2) local $InputName = MakeInput("") local $LabelAddress = MakeLabel("Billing Address", 0,0,0,0,"Courier New", $FontSize*1.2) local $ListAddress = MakeEdit("") local $LabelTransaction = MakeLabel("Transactions", 0,0,0,0,"Courier New", $FontSize*1.2) local $ListTransaction = MakeListView("Date|Detail|Type|Amount") local $hListTransaction = GUICtrlGetHandle($ListTransaction) local $InputDate = MakeInput("") local $InputDetail = MakeInput("") local $ButtonType = MakeButton('',0,0,0,0,"Verdana",$FontSize*0.8) local $InputAmount = MakeInput("Amount") local $ButtonSubmit = MakeButton('+') GLOBAL $types[10] = ['Type1', 'Type2', 'Type3', 'Type4', 'Type5', 'Type6', '']; GLOBAL $TYPE = 0 func toggleType() $TYPE += 1 if $types[$TYPE] = '' then $TYPE = 1 GUICtrlSetData($ButtonType, $types[$TYPE]) endfunc func resizeMainWindow() local $XY = WinGetPos($MW) local $DimX=$XY[2], $DimY=$XY[3] ;save actual width, height of $MW local $mx = 3, $my=3, $w1 = 350, $w2 = 275 ;margin and width ;Left Panels GUICtrlSetPos($LabelAccount, $mx, $my, $w1, 2.0*$FontSize) ;use actual dimension to resize Panel1 GUICtrlSetPos($ListAccount, $mx, 2.0*$FontSize+$my, $w1, $DimY-65-2.0*$FontSize) ;resize Panel2 $XY = ControlGetPos($MW, "", $LabelAccount) ;get actual dimension local $h1 = $XY[3] ;save actual height to $h1 _GUICtrlListView_SetColumnWidth($ListAccount, 0, $w1-20) _GUICtrlListView_SetColumnWidth($ListAccount, 1, 0) _GUICtrlListView_JustifyColumn ($ListAccount, 0, 0) ;Right Panels local $h2 = $FontSize*1.65*4 GUICtrlSetPos($LabelName, $w1+2*$mx, $my, $w2, 2.0*$FontSize) GUICtrlSetPos($InputName, $w2+$w1+2*$mx, $my, $DimX-2*$my-17-$w1-$w2, 2.0*$FontSize) GUICtrlSetPos($ListAddress, $w2+$w1+2*$mx, 2.0*$FontSize+$my, $DimX-2*$my-17-$w1-$w2, $h2) $XY = ControlGetPos($MW,"",$ListAddress) $h2 = $XY[3] GUICtrlSetPos($LabelAddress, $w1+2*$mx, 2.0*$FontSize+$my, $w2, $h2) local $h3 = $DimY-59-5.8*$FontSize-$h2-4*$my ;panel6 heigth GUICtrlSetPos($LabelTransaction, $w1+2*$mx, $h2+2.0*$FontSize+$my, $DimX-2*$my-17-$w1, 2.0*$FontSize) GUICtrlSetPos($ListTransaction, $w1+2*$mx, $h2+4.0*$FontSize+$my, $DimX-2*$my-17-$w1, $h3) $XY[0] = $DimX-17-3*$my-$w1 - 35*$FontSize _GUICtrlListView_SetColumnWidth($ListTransaction, 0, 9*$FontSize-3) _GUICtrlListView_SetColumnWidth($ListTransaction, 1, $XY[0]) _GUICtrlListView_SetColumnWidth($ListTransaction, 2, 12*$FontSize) _GUICtrlListView_SetColumnWidth($ListTransaction, 3, 12*$FontSize) _GUICtrlListView_JustifyColumn ($ListTransaction, 0, 0) _GUICtrlListView_JustifyColumn ($ListTransaction, 1, 0) _GUICtrlListView_JustifyColumn ($ListTransaction, 2, 0) _GUICtrlListView_JustifyColumn ($ListTransaction, 3, 1) GUICtrlSetPos($InputDate, $w1+2*$mx, $h3+4.0*$FontSize+$h2+2*$my, 9*$FontSize-1, 1.8*$FontSize) GUICtrlSetPos($InputDetail, 9*$FontSize+$w1+2*$mx, $h3+4.0*$FontSize+$h2+2*$my, $XY[0]-1, 1.8*$FontSize) GUICtrlSetPos($ButtonType, $XY[0]+ 9*$FontSize+$w1+2*$mx, $h3+4.0*$FontSize+$h2+2*$my, 12*$FontSize-1, 1.8*$FontSize) GUICtrlSetPos($InputAmount, $XY[0]+21*$FontSize+$w1+2*$mx, $h3+4.0*$FontSize+$h2+2*$my, 12*$FontSize-1, 1.8*$FontSize) GUICtrlSetPos($ButtonSubmit, $XY[0]+33*$FontSize+$w1+2*$mx, $h3+4.0*$FontSize+$h2+2*$my, 2*$FontSize-1, 1.8*$FontSize) endfunc func commify ($num) $num = stringFormat("%0.2f", $num) local $input do $input = $num $num = StringRegExpReplace($input, '^(-?\d+)(\d{3})', '$1,$2') until $input = $num return($input) endfunc ; MAIN toggleType() resizeMainWindow() SampleData() GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") GUISetState(@SW_SHOW, $MW) while 1 switch GUIGetMsg(0) case $GUI_EVENT_MAXIMIZE resizeMainWindow() case $GUI_EVENT_RESIZED resizeMainWindow() case $GUI_EVENT_RESTORE resizeMainWindow() case $GUI_EVENT_DROPPED resizeMainWindow() case $ButtonType toggleType() case $GUI_EVENT_CLOSE exit endswitch wend Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Return $GUI_RUNDEFMSG EndFunc func SampleData () GUICtrlSetData($ListAddress, "123 Street," & @CRLF & "Capital City," & @CRLF & "Country 10000" ) _GUICtrlListView_DeleteAllItems($ListAccount) _GUICtrlListView_DeleteAllItems($ListTransaction) for $i = 0 to 200 GUICtrlCreateListViewItem( $i, $ListAccount ) local $s = StringFormat("%s|%s|%s|%s", "Date "&$i, "Detail "&$i, $types[Random(1,5,1)], commify(Random(1,1000,0))) GUICtrlCreateListViewItem( $s, $ListTransaction ) next endfunc I want to maintain the Highlight on the Account List ListView (Account List) when i click on any GUI. I dont need to maintain Highlight on the Transaction ListView. This is a sample script I found that performs what i wanted: expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <StructureConstants.au3> $GUI = GUICreate("Listview Custom Draw", 600, 400) $cListView = GUICtrlCreateListView("Column 1|Column 2|Column 3", 5, 2, 590, 200, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $hListView = GUICtrlGetHandle($cListView) $xListView = GUICtrlCreateListView("Column 1|Column 2|Column 3", 5, 204, 590, 200, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $iListView = GUICtrlGetHandle($xListView) ; Add items For $i = 1 To 30 GUICtrlCreateListViewItem("Row" & $i & ": Col 1|Row" & $i & ": Col 2|Row" & $i & ": Col 3", $cListView) GUICtrlCreateListViewItem("Row" & $i & ": Col 1|Row" & $i & ": Col 2|Row" & $i & ": Col 3", $xListView) Next GUICtrlCreateInput("Click here to test focus", 50, 425, 200, 18) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Exit Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG ; Not in details mode endif Local $tCustDraw, $iDrawStage, $iItem, $iSubitem, $hDC, $tRect, $iColor1, $iColor2, $iColor3 $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case $CDDS_PREPAINT Return $CDRF_NOTIFYITEMDRAW Case $CDDS_ITEMPREPAINT Return $CDRF_NOTIFYSUBITEMDRAW Case $CDDS_ITEMPOSTPAINT ; Not handled Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) $iItem = DllStructGetData($tCustDraw, 'dwItemSpec') $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') If _GUICtrlListView_GetItemSelected($hWndFrom, $iItem) Then ; Item to draw is selected $hDC = _WinAPI_GetDC($hWndFrom) $tRect = DllStructCreate($tagRECT) ; We draw the background when we draw the first item. If $iSubitem = 0 Then ; We must send the message as we want to use the struct. _GUICtrlListView_GetSubItemRect returns an array. _SendMessage($hWndFrom, $LVM_GETSUBITEMRECT, $iItem, DllStructGetPtr($tRect)) DllStructSetData($tRect, "Left", 2) _WinAPI_FillRect($hDC, DllStructGetPtr($tRect), _WinAPI_GetStockObject($GRAY_BRUSH)) ; Change the bush here. You can use GDI+ to make your own. EndIf DllStructSetData($tRect, "Left", 2) DllStructSetData($tRect, "Top", $iSubitem) _SendMessage($hWndFrom, $LVM_GETSUBITEMRECT, $iItem, DllStructGetPtr($tRect)) Local $sText = _GUICtrlListView_GetItemText($hWndFrom, $iItem, $iSubitem) _WinAPI_SetBkMode($hDC, $TRANSPARENT) ; It uses the background drawn for the first item. ; Select the font we want to use _WinAPI_SelectObject($hDC, _SendMessage($hWndFrom, $WM_GETFONT)) If $iSubitem = 0 Then DllStructSetData($tRect, "Left", DllStructGetData($tRect, "Left") + 2) Else DllStructSetData($tRect, "Left", DllStructGetData($tRect, "Left") + 6) EndIf _WinAPI_DrawText($hDC, $sText, $tRect, BitOR($DT_VCENTER, $DT_END_ELLIPSIS, $DT_SINGLELINE)) _WinAPI_ReleaseDC($hWndFrom, $hDC) Return $CDRF_SKIPDEFAULT ; Don't do default processing EndIf Return $CDRF_NEWFONT ; Let the system do the drawing for non-selected items Case BitOR($CDDS_ITEMPOSTPAINT, $CDDS_SUBITEM) ; Not handled EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func RGB2BGR($iColor) Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF) EndFunc ;==>RGB2BGR The top ListView retains the highlight (albeit in dark gray). However, I could not make it work on my script. I am stuck. and need help. Thanks. Edited April 16, 2018 by Burgaud
Moderators Melba23 Posted April 16, 2018 Moderators Posted April 16, 2018 Burgaud, have you looked at my GUIListViewEx UDF (the link is in my sig)? It allows you to retain the "selected" colour when the ListView is not focused - Example 6 is the one to run. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Burgaud Posted April 16, 2018 Author Posted April 16, 2018 Melba, not yet. will test that out and see how it goes. thanks
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