Jump to content
careca

Listview row background color

Recommended Posts

Hi forum, im trying to figure out how to do this and put it in a function with a simple syntax, such as: 

LVBK($Row, $Color)

The problem is that all the code i find is built around

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

In this example i was messing with it, i identified what actually changed the background color, and it was this:

Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aRowBK))

right now all rows become of the defined color, but that is besides the point,

the point is all this code is very cryptic to me, have no idea on how to turn this into a callable function.

Func WM_NOTIFY($hWnd, $msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aRowBK[2]))
                    ;ConsoleWrite('Item '&$iItem&' BK: '&$aRowBK[$iIndex][1] & @CRLF)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 


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

Share this post


Link to post
Share on other sites

Wouldn't that mean that the same items would be colored many times over and over?


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

Share this post


Link to post
Share on other sites
Posted (edited)

Yes, it would be painted every time a drawing event occurs (e.g. LV was covered and is uncovered again). On the other hand that's necessary, as otherwise no table at all would be drawn.

Look at the helpfile example for _GUIImageList_BeginDrag(), at the bottom you'll find the line "If BitAND($iItemSpec, 1) = 1 Then", that's where the item number is checked and it's either painted in white or blue. You can add a test there for id = 1 and set it to green, then you realize how it works,

Edit:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

GUICreate("listview items", 220, 250, 100, 200)

Local $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 230)     ;,$LVS_SORTDESCENDING)
Global $g_hListView = GUICtrlGetHandle($idListview)

Local $idItem1 = GUICtrlCreateListViewItem("item1|col22|col23", $idListview)
Local $idItem2 = GUICtrlCreateListViewItem("item2|col12|col13", $idListview)
Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
Local $idItem4 = GUICtrlCreateListViewItem("item4|col22|col23", $idListview)
Local $idItem5 = GUICtrlCreateListViewItem("item5|col12|col13", $idListview)
Local $idItem6 = GUICtrlCreateListViewItem("item6|col32|col33", $idListview)
Local $idItem7 = GUICtrlCreateListViewItem("item7|col12|col13", $idListview)
Local $idItem8 = GUICtrlCreateListViewItem("item8|col32|col33", $idListview)

Global $s_Rows_to_Paint_Green = ";2;;5;" ; 0-based

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


Func WM_NOTIFY($hWndGUI, $iMsgID, $wParam, $lParam)
    #forceref $hWndGUI, $iMsgID, $wParam
    Local $tNMHDR, $iCode, $x, $y, $tNMLISTVIEW, $hWndFrom, $tDraw, $iDrawStage, $iItemSpec
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    If @error Then Return
    $iCode = DllStructGetData($tNMHDR, "Code")
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    Switch $hWndFrom
        Case $g_hListView
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    $tDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    $iDrawStage = DllStructGetData($tDraw, "dwDrawStage")
                    $iItemSpec = DllStructGetData($tDraw, "dwItemSpec")
                    Switch $iDrawStage
                        Case $CDDS_PREPAINT
                            Return $CDRF_NOTIFYITEMDRAW
                        Case $CDDS_ITEMPREPAINT

                            If StringInStr($s_Rows_to_Paint_Green, ";" & $iItemSpec & ";") Then DllStructSetData($tDraw, "clrTextBk", 0x00ff00)

                            Return $CDRF_NEWFONT
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Edited by KaFu

Share this post


Link to post
Share on other sites
Posted (edited)

GUICtrlSetBkColor ($idItem3, 0x00FF00) ?

or more precisely :

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

GUICreate("listview items", 220, 250, 100, 200)

Local $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 230)
For $i = 1 to 10
  GUICtrlCreateListViewItem("item" & $i & "|col" & $i & "2|col" & $i & "3", $idListview)
Next

LVBK ($idListview, 2, 0x00ff00)
LVBK ($idListview, 5, 0x00ff00)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func LVBK ($ListView, $row, $color)
  GUICtrlSetBkColor (_GUICtrlListView_GetItemParam($ListView, $row),$color)
EndFunc

 

Edited by Nine

Share this post


Link to post
Share on other sites
Posted (edited)

Awesome @Nine this was what i was looking for!

Thank you all for the answers!

Edited 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

Share this post


Link to post
Share on other sites
2 hours ago, careca said:

this was what i was looking for!

Great, also, you can use _GUICtrlListView_MapIndexToID if the controls were created with non-native functions (_GUICtrlListView_AddItem and _GUICtrlListView_SubAddItem)

Share this post


Link to post
Share on other sites

If i may ask, how did you come up with this for GUICtrlSetBkColor?

I ask because i didn't notice that _GUICtrlListView_GetItemParam() retrieves a control id,

instead it says: "Returns the application specific value."

I would never make the logical jump into expecting a control id out of it.

 


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

Share this post


Link to post
Share on other sites

In help file, in example of _GUICtrlListView_GetItemParam, there is a comment saying :

; Warning do not use SetItemParam on items created with GUICtrlCreateListViewItem
; Param is the controlID for items created with built-in function

Always in help file, now with _GUICtrlListView_SetItemParam, remarks says :

Quote

As AutoIt uses the $iParam parameter to store the controlID of native-created ListView items, this value should be set sufficiently high for UDF-created items to avoid possible conflict with any existing controls - a starting value of 1000 is recommended.

:)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...