wolflake Posted April 18, 2020 Share Posted April 18, 2020 So I think I found a bug but since it's "usually me" that's wrong, I'm coming here for confirmation. I was writing a script and I was trying to get the window background and the listview background and the listview items background all to be the same color. The problem was I was they were different even though they were using the same color values. The hex of the basic colors of red green and blue would be: FF0000 red 00FF00 green 0000FF blue. What appears to happen is the first two digits in the last two digits are transposed when the color is set on the listview. When I read the values from the controls they are correct, it's the colors that are wrong. So red becomes blue becomes red. I've written a small program to show the errors. First note that looking at the code below the text background should be blue and the listview background should be red. Instead it's just the reverse. _GUICtrlListView_SetTextBkColor($List1,$color_blue) _GUICtrlListView_SetBkColor($List1,$color_red) expandcollapse popup;Color Test #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <ColorConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $hGUI = GUICreate("Form1", 290, 169, 192, 124) $List1 = GUICtrlCreateListView("Col 1", 48, 16, 89, 110,$LVS_SHOWSELALWAYS) $Input1 = GUICtrlCreateInput("0x0000FF", 168, 16, 100, 21) $Input2 = GUICtrlCreateInput("0xFF0000", 168, 48, 100, 21) $Button1 = GUICtrlCreateButton("Button1", 168, 80, 65, 17) $Button2 = GUICtrlCreateButton("Button2", 168, 104, 65, 17) GUICtrlCreateListViewItem("One", $List1) GUICtrlCreateListViewItem("Two", $List1) GUICtrlCreateListViewItem("Three", $List1) _GUICtrlListView_SetTextBkColor($List1,$color_blue) _GUICtrlListView_SetBkColor($List1,$color_red) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $ic=number(GUICtrlRead($Input1)) ConsoleWrite($ic & @CRLF) GUISetBkColor ($ic ,$hGUI ) _GUICtrlListView_SetTextBkColor($List1,$ic) _GUICtrlListView_SetBkColor($List1,$ic) tooltip(Hex(_GUICtrlListView_GetTextBkColor($List1))) Case $Button2 $ic=number(GUICtrlRead($Input2)) ConsoleWrite($ic & @CRLF) GUISetBkColor ($ic ,$hGUI ) _GUICtrlListView_SetTextBkColor($List1,$ic) _GUICtrlListView_SetBkColor($List1,$ic) tooltip(Hex(_GUICtrlListView_GetTextBkColor($List1))) EndSwitch WEnd Button1 should apply the color red in the first input box (red) to the window background, listview background and the listview text back color. The Button2 two should make them all blue. As you can see the background color for the window does what it's supposed to do but the listview doesn't. Note if you apply green 00FF00 then everything works right. The middle two digits are left alone. The tool tip is showing the color value on the control using Hex(_GUICtrlListView_GetTextBkColor($List1)). Which shows the value on the control is correct it's the color that is wrong. Thanks to anyone that took the time to look at this and please let me know you think. Link to comment Share on other sites More sharing options...
careca Posted April 19, 2020 Share Posted April 19, 2020 expandcollapse popup;Color Test #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <ColorConstants.au3> #include <WinAPIGdi.au3> ;ConsoleWrite($CLR_MONEYGREEN &@CRLF) ;ConsoleWrite(Hex($CLR_MONEYGREEN)&@CRLF) ;ConsoleWrite(Dec($color_red) &@CRLF) #include <WindowsConstants.au3> #include <WinAPIGdi.au3> #Region ### START Koda GUI section ### Form= $hGUI = GUICreate("Form1", 290, 169, 192, 124) $List1 = GUICtrlCreateListView("Col 1", 48, 16, 89, 110,$LVS_SHOWSELALWAYS) $Input1 = GUICtrlCreateInput("0x0000FF", 168, 16, 100, 21) $Input2 = GUICtrlCreateInput("0xFF0000", 168, 48, 100, 21) $Button1 = GUICtrlCreateButton("Button1", 168, 80, 65, 17) $Button2 = GUICtrlCreateButton("Button2", 168, 104, 65, 17) GUICtrlCreateListViewItem("One", $List1) GUICtrlCreateListViewItem("Two", $List1) GUICtrlCreateListViewItem("Three", $List1) _GUICtrlListView_SetTextBkColor($List1,$color_blue) _GUICtrlListView_SetBkColor($List1,$color_red) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $ic=number(GUICtrlRead($Input1)) GUISetBkColor ($ic ,$hGUI ) $ic=_WinAPI_SwitchColor($ic) _GUICtrlListView_SetTextBkColor($List1,$ic) _GUICtrlListView_SetBkColor($List1,$ic) tooltip(Hex(_GUICtrlListView_GetTextBkColor($List1))) _WinAPI_RedrawWindow($hGUI) Case $Button2 $ic=number(GUICtrlRead($Input2)) GUISetBkColor ($ic ,$hGUI ) $ic=_WinAPI_SwitchColor($ic) _GUICtrlListView_SetTextBkColor($List1,$ic) _GUICtrlListView_SetBkColor($List1,$ic) tooltip(Hex(_GUICtrlListView_GetTextBkColor($List1))) _WinAPI_RedrawWindow($hGUI) EndSwitch WEnd See if this works for you. I cannot explain why these other functions don't accept the values like the guisetbkcolor function. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
wolflake Posted April 19, 2020 Author Share Posted April 19, 2020 (edited) @Careca yes that works fine. "_WinAPI_RedrawWindow()" How did you think of that? I've never scene it but I'll keep it in mind if I ever run into this sort of problem again. So do you think this is a windows issue rather than an Autoit issue? Actually the buttons work fine now but the initial setting of the listview with the $color_blue and $color_red is still reversed and the RedrawWindow doesn't seem to fix it. I tried it the redraw both before and after GUISetState(). Anyway thanks again for your help I don't believe I'd ever have gotten that on my own. Edited April 19, 2020 by wolflake Link to comment Share on other sites More sharing options...
careca Posted April 19, 2020 Share Posted April 19, 2020 (edited) The _WinAPI_RedrawWindow helps with painting the bits that get painted but dont show the new color. As for the initial setting being reversed, if you notice, you do have 2 different colors in there, so im not sure what you expected. _GUICtrlListView_SetTextBkColor($List1,$color_blue) _GUICtrlListView_SetBkColor($List1,$color_red) maybe change it to GUISetBkColor ($color_red ,$hGUI ) _GUICtrlListView_SetTextBkColor($List1,$color_blue) _GUICtrlListView_SetBkColor($List1,$color_blue) and it will start all the same color. Im not sure what the issue is, i opened a bug ticket, we'll see how it goes, it seems like an autoit issue to me. Edited April 19, 2020 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
wolflake Posted April 19, 2020 Author Share Posted April 19, 2020 (edited) Actually when I change it to : _GUICtrlListView_SetTextBkColor($List1,number($color_blue)) _GUICtrlListView_SetBkColor($List1,number($color_blue)) I get red for both instead of blue for both. 🤔 Which again illustrates the problem. Thanks for opening the bug ticket. To be clear this is more than just 2 colors being switched this is any two digits in the hex '00' 00 '00' the high order two and the low order two will be reversed so 0xAB00CD will produce a color 0xCD00AB I just used the red and blue example because it's easy to see and you can tell what it does. Edited April 19, 2020 by wolflake Link to comment Share on other sites More sharing options...
mikell Posted April 19, 2020 Share Posted April 19, 2020 I'd rather say that there is a missing remark in the help file, where examples use "$CLR_MONEYGREEN" which is "0xC0DCC0" The colors are sent as BGR and not RGB so such a conversion is needed Func _BGR2RGB($iColor) ;Author: Wraithdu Return BitOR(BitShift(BitAND($iColor, 0x0000FF), -16), BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0xFF0000), 16)) EndFunc ;==>_BGR2RGB Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 19, 2020 Moderators Share Posted April 19, 2020 (edited) Hi all, There is an internal function in the GUIListView library for reversing RGB->BGR->RGB colours, but is is only used in the _GetBkColor function. I have replaced it with _WinAPI_SwitchColor and added a suitable call to that function to ALL the colour functions in the library - now everything seems to work fine for me. Can the rest of you test it too please. M23 Edited June 14, 2020 by Melba23 Beta code removed 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 Link to comment Share on other sites More sharing options...
wolflake Posted April 19, 2020 Author Share Posted April 19, 2020 @Melba23 I tested your fix on my little script and I am pleased to say it worked perfectly. The initial listviewSetTextBkColor was set to blue and the listviewSetBkColor was set to red as it should be. The buttons also set the colors correctly without having to use the _WinApi_RedrawWindow function. BTW I want to thank you for your GUIListViewEx.au3 which I have used and appreciated. 😁 Thanks to everyone who took the time to look at this for me. Link to comment Share on other sites More sharing options...
careca Posted April 20, 2020 Share Posted April 20, 2020 (edited) Hi, my test went fine, altough, using the code in the OP, and unrelated to the changes, if i don't use the redraw window command, there's always a thin border of the previous color around the listview. It assumes the color if i press the same button again, or if i only press it once, but have the redraw window command in there, otherwise i always get the border unpainted. Can we expect this change (fix) to happen in a future autoit update? Why does this happen? I mean, why isn't the function accepting RGB like "it's supposed to"? Edited April 20, 2020 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 20, 2020 Moderators Share Posted April 20, 2020 careca, I think we should leave the redraw call up to the user. Adding redraw calls to the UDF for each of the colour functions would mean multiple redraws as the recolouring progressed - better to do it just the once after all the recolouring is done, which can only be determined by the user As to why the functions do not accept RGB - I do not believe that the functions were ever "supposed to" accept that particular colour mode as they all use API calls to do their magic and the API has, in my experience, always used BGR. I imagine that there was a general acceptance of the need to use BGR which has got lost over time. Certainly in my GUIListViewEx UDF I convert all the RGB values to BGR internally before using them in any API calls. And now the GUIListView library will do the same - so all will be well. If no problems turn up in testing then you could expect to see the amended GUIListView library in the next release - until then you can either use the Beta code I posted above or make suitable colour mode changes within your own script. 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 Link to comment Share on other sites More sharing options...
wolflake Posted April 20, 2020 Author Share Posted April 20, 2020 (edited) Never mind what I've written below I misunderstood that the outline was for images in items. To Carera's point about the line around the listview, unless I've done something wrong I can't change the color of the border/outline of the listview. Here is the code I used. Note it's pretty much the same as before with the addition of _GUICtrlListView_SetExtendedListViewStyle($List1, $LVS_EX_BORDERSELECT) and _GUICtrlListView_SetOutlineColor($List1,$ic) and I've commented out the other changes to highlight the outline. Edited April 20, 2020 by wolflake I was wrong. Link to comment Share on other sites More sharing options...
mikell Posted April 20, 2020 Share Posted April 20, 2020 (edited) @Melba23 Hmm I understand that doing such a change in the UDF could be consistent, GuiCtrlSetBkColor uses RGB while _GUICtrlListView_SetBkColor uses BGR But this is a big script breaking change, all the concerned examples in the helpfile should be rewritten, and this doesn't change the fact that - as you said - the dll customdraw structures etc will continue to use BGR anyway Maybe it would be more convenient to simply put some warning remarks in the helpfile to mention the existence of this BGR thing and the possible use of _WinAPI_SwitchColor OTOH the Treeview colour functions already use $vRGBColor as param with an internal __GUICtrlTreeView_ReverseColorOrder func Here is the _GUICtrlListView_GetBkColor example from the helpfile using GuiListView_color.au3 expandcollapse popup#include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include "GuiListView_color.au3" #include <MsgBoxConstants.au3> Example() Func Example() Local $idListview GUICreate("ListView Get BkColor", 400, 300) $idListview = GUICtrlCreateListView("", 2, 2, 394, 268) GUISetState(@SW_SHOW) ; Set colors _GUICtrlListView_SetBkColor($idListview, 0xff0000) _GUICtrlListView_SetTextColor($idListview, 0x0000ff) _GUICtrlListView_SetTextBkColor($idListview, $CLR_RED) ; Add columns _GUICtrlListView_AddColumn($idListview, "Items", 100) ; Add items _GUICtrlListView_BeginUpdate($idListview) For $iI = 1 To 10 _GUICtrlListView_AddItem($idListview, "Item " & $iI) Next _GUICtrlListView_EndUpdate($idListview) ; Show colors MsgBox($MB_SYSTEMMODAL, "Information", "Back Color ....: " & _GUICtrlListView_GetBkColor($idListview) & @CRLF & _ "Text Color ....: " & _GUICtrlListView_GetTextColor($idListview) & @CRLF & _ "Text Back Color: " & _GUICtrlListView_GetTextBkColor($idListview)) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Edited April 20, 2020 by mikell 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