Sign in to follow this  
Followers 0
MrCreatoR

Highlight LV Item

15 posts in this topic

Hi there,

I need to highlight ListView item, so even when the ListView is not focused, the user will be able to see *clearly* the selected item.

This is what i am trying:

#include <GuiConstants.au3>
#include <GuiListView.au3>

$GUI = GUICreate("Test Script", 300, 230)

$ListView = GUICtrlCreateListView("Column", 20, 10, 260, 160)

For $i = 1 To 5
    GUICtrlCreateListViewItem("Item " & $i, $ListView)
Next

$Highlight_Button = GUICtrlCreateButton("Highlight", 20, 190, 60, 20)
$Clear_Button = GUICtrlCreateButton("Clear", 120, 190, 60, 20)

GUISetState(@SW_SHOW, $GUI)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Highlight_Button
            DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $GUI, "ptr", 0, "int", 0, "int", 5)
            
            $iIndex = Number(_GUICtrlListView_GetSelectedIndices($ListView))
            _GUICtrlListViewSetItemHighlight($ListView, $iIndex, 0x0000FF)
        Case $Clear_Button
            DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $GUI, "ptr", 0, "int", 0, "int", 5)
    EndSwitch
WEnd

Func _GUICtrlListViewSetItemHighlight($hListView, $iIndex, $sColor, $iLineWidth=2)
    Local $aItem_Rect = _GUICtrlListView_GetItemRect($hListView, $iIndex, 3)
    
    Local $aGUI_Pos = WinGetPos($GUI)
    Local $aLV_Pos = ControlGetPos($GUI, "", $ListView)
    
    _DrawSquare($aItem_Rect[0]+$aGUI_Pos[0]+$aLV_Pos[0]+5, $aItem_Rect[1]+$aGUI_Pos[1]+$aLV_Pos[1]+25, _
        $aLV_Pos[2]-3, $aItem_Rect[3]- 22 - ($iIndex * 14), $sColor, $iLineWidth)
EndFunc

Func _DrawSquare($iLeft, $iTop, $iWidth, $iHeight, $sColor, $iLineWidth=2, $hWnd=0)
    Local $hDC = DllCall("User32.dll", "int", "GetDC", "hwnd", $hWnd)
    Local $aPen = DllCall("GDI32.dll", "int", "CreatePen", "int", 0, "int", $iLineWidth, "int", $sColor)
    
    DllCall("GDI32.dll", "int", "SelectObject", "int", $hDC[0], "int", $aPen[0])
    
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop)
    
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop+$iHeight)
    
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop+$iHeight)
    
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop+$iHeight, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop+$iHeight)
    
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "int", $hDC[0])
EndFunc

But it's not practical, the function _GUICtrlListViewSetItemHighlight() will not work the same on all ListView items (styles, docking, etc.).

Maybe is there a way to drown using labels (with $SS_SUNKEN style) on the listview? the label can not be visible on top of the LV control...


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites



Hi there,

I need to highlight ListView item, so even when the ListView is not focused, the user will be able to see *clearly* the selected item.

This is what i am trying:

#include <GuiConstants.au3>
#include <GuiListView.au3>

$GUI = GUICreate("Test Script", 300, 230)

$ListView = GUICtrlCreateListView("Column", 20, 10, 260, 160)

For $i = 1 To 5
    GUICtrlCreateListViewItem("Item " & $i, $ListView)
Next

$Highlight_Button = GUICtrlCreateButton("Highlight", 20, 190, 60, 20)
$Clear_Button = GUICtrlCreateButton("Clear", 120, 190, 60, 20)

GUISetState(@SW_SHOW, $GUI)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Highlight_Button
            DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $GUI, "ptr", 0, "int", 0, "int", 5)
            
            $iIndex = Number(_GUICtrlListView_GetSelectedIndices($ListView))
            _GUICtrlListViewSetItemHighlight($ListView, $iIndex, 0x0000FF)
        Case $Clear_Button
            DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $GUI, "ptr", 0, "int", 0, "int", 5)
    EndSwitch
WEnd

Func _GUICtrlListViewSetItemHighlight($hListView, $iIndex, $sColor, $iLineWidth=2)
    Local $aItem_Rect = _GUICtrlListView_GetItemRect($hListView, $iIndex, 3)
    
    Local $aGUI_Pos = WinGetPos($GUI)
    Local $aLV_Pos = ControlGetPos($GUI, "", $ListView)
    
    _DrawSquare($aItem_Rect[0]+$aGUI_Pos[0]+$aLV_Pos[0]+5, $aItem_Rect[1]+$aGUI_Pos[1]+$aLV_Pos[1]+25, _
        $aLV_Pos[2]-3, $aItem_Rect[3]- 22 - ($iIndex * 14), $sColor, $iLineWidth)
EndFunc

Func _DrawSquare($iLeft, $iTop, $iWidth, $iHeight, $sColor, $iLineWidth=2, $hWnd=0)
    Local $hDC = DllCall("User32.dll", "int", "GetDC", "hwnd", $hWnd)
    Local $aPen = DllCall("GDI32.dll", "int", "CreatePen", "int", 0, "int", $iLineWidth, "int", $sColor)
    
    DllCall("GDI32.dll", "int", "SelectObject", "int", $hDC[0], "int", $aPen[0])
    
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop)
    
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop+$iHeight)
    
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop+$iHeight)
    
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop+$iHeight, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop+$iHeight)
    
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "int", $hDC[0])
EndFunc

But it's not practical, the function _GUICtrlListViewSetItemHighlight() will not work the same on all ListView items (styles, docking, etc.).

Maybe is there a way to drown using labels (with $SS_SUNKEN style) on the listview? the label can not be visible on top of the LV control...

All goes a bit wrong when there is a vertical scrollbar in the listview. Also, the red box needs to be redrawn when the gui is redrawn.

It might be easier to have a couple of images. One just a blank, the other a pointer of some sort, then use

Dim $lit[28]
For $i = 1 To 28
    $lit[$i] = GUICtrlCreateListViewItem("Item " & $i, $ListView)
Next
.
.
.
 Case $Highlight_Button, $Listview, $GUI_EVENT_PRIMARYDOWN
            If $nmsg = $GUI_EVENT_PRIMARYDOWN Then
                $mp = GUIGetCursorInfo()
                If $mp[4] <> $ListView Then ContinueLoop
            EndIf

            GUICtrlSetImage($lit[$lastlit],"Blank.ico")
            GUICtrlSetImage($lit[$iIndex],"pointything.ico"
.
..

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here's modified version of example I posted some time ago

(the "If _GUICtrlListView_GetItemSelected" part specifically)

If you have checkboxes and images on your items, will have to fix rectangles accordingly. And if you want, you can do some other kind of drawing instead of FillRect...

#Include <GuiConstantsEx.au3>
#Include <GuiListView.au3>

;custom draw constants
Global Const $CDDS_ITEM = 0x10000
Global Const $CDDS_MAPPART = 0x5
Global Const $CDDS_POSTERASE = 0x4
Global Const $CDDS_POSTPAINT = 0x2
Global Const $CDDS_PREERASE = 0x3
Global Const $CDDS_PREPAINT = 0x1
Global Const $CDDS_SUBITEM = 0x20000
Global Const $CDDS_ITEMPOSTERASE = BitOR($CDDS_ITEM, $CDDS_POSTERASE)
Global Const $CDDS_ITEMPOSTPAINT = BitOR($CDDS_ITEM, $CDDS_POSTPAINT)
Global Const $CDDS_ITEMPREERASE = BitOR($CDDS_ITEM, $CDDS_PREERASE)
Global Const $CDDS_ITEMPREPAINT = BitOR($CDDS_ITEM, $CDDS_PREPAINT)

Global Const $CDIS_CHECKED = 0x8
Global Const $CDIS_DEFAULT = 0x20
Global Const $CDIS_DISABLED = 0x4
Global Const $CDIS_FOCUS = 0x10
Global Const $CDIS_GRAYED = 0x2
Global Const $CDIS_HOT = 0x40
Global Const $CDIS_INDETERMINATE = 0x100
Global Const $CDIS_MARKED = 0x80
Global Const $CDIS_SELECTED = 0x1
Global Const $CDIS_SHOWKEYBOARDCUES = 0x200

Global Const $CDRF_DODEFAULT = 0x0
Global Const $CDRF_NEWFONT = 0x2
Global Const $CDRF_NOTIFYITEMDRAW = 0x20
Global Const $CDRF_NOTIFYPOSTERASE = 0x40
Global Const $CDRF_NOTIFYPOSTPAINT = 0x10
Global Const $CDRF_NOTIFYSUBITEMDRAW = 0x20
Global Const $CDRF_SKIPDEFAULT = 0x4

;fonts for custom draw example
;bold
Global $aFont1 = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 700, _
                        "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _
                        "dword", 0, "str", "")
;italic
Global $aFont2 = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 400, _
                        "dword", 1, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _
                        "dword", 0, "str", "")
                        


$GUI = GUICreate("Listview Custom Draw", 400, 300)

$cListView = GUICtrlCreateListView("", 2, 2, 394, 268, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$hListView = GUICtrlGetHandle($cListView)

_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

; Add items
For $i = 1 To 30
    _GUICtrlListView_AddItem($hListView, "Row" & $i & ": Col 1", $i-1)
    For $j = 1 To 2
        _GUICtrlListView_AddSubItem ($hListView, $i-1, "Row" & $i & ": Col " & $j+1, $j)
    Next
Next

GUICtrlCreateInput("", 50, 275, 100, 15)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aFont1[0])
DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aFont2[0])
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
                    Local $tCustDraw = DllStructCreate('hwnd hwndFrom;int idFrom;int code;' & _
                                        'dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;' & _
                                        'dword clrText;dword clrTextBk;int SubItem;' & _
                                        'dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align', _ ;winxp or later
                                        $lParam), $iDrawStage, $iItem, $iSubitem, $hDC, $tRect, $iColor1, $iColor2, $iColor3
                    $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage')
                    Switch $iDrawStage
                        Case $CDDS_PREPAINT
                            Return $CDRF_NOTIFYITEMDRAW
                        Case $CDDS_ITEMPREPAINT
                            Return $CDRF_NOTIFYSUBITEMDRAW
                        Case $CDDS_ITEMPOSTPAINT
                        Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
                            $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                            $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
                            If _GUICtrlListView_GetItemSelected($hWndFrom, $iItem) Then
                                $hDC = _WinAPI_GetDC($hWndFrom)
                                $tRect = DllStructCreate('long;long;long;long')
                                If $iSubitem = 0 Then
                                    DllCall('user32.dll','int','SendMessage', 'hwnd',$hWndFrom, 'uint',$LVM_GETSUBITEMRECT, 'wparam',$iItem, 'lparam',DllStructGetPtr($tRect))
                                    DllStructSetData($tRect, 1, 2)
                                    DllCall('user32.dll', 'int', 'FillRect', 'ptr', $hDC, 'ptr', DllStructGetPtr($tRect), 'int', _WinAPI_GetStockObject(4))
                                EndIf
                                DllStructSetData($tRect, 1, 2)
                                DllStructSetData($tRect, 2, $iSubitem)
                                DllCall('user32.dll','int','SendMessage', 'hwnd',$hWndFrom, 'uint',$LVM_GETSUBITEMRECT, 'wparam',$iItem, 'lparam',DllStructGetPtr($tRect))
                                Local $sText = _GUICtrlListView_GetItemText($hWndFrom, $iItem, $iSubitem)
                                DLLCall("gdi32.dll","int","SetTextColor", "ptr", $hDC, "int", RGB2BGR(0xffff00))
                                DLLCall("gdi32.dll","int","SetBkMode", "ptr", $hDC, "int", 1)
                                DllStructSetData($tRect, 1, DllStructGetData($tRect, 1)+2)
                                _WinAPI_DrawText($hDC, $sText, $tRect, 0x8000) ;; $DT_END_ELLIPSIS
                                _WinAPI_ReleaseDC($hWndFrom, $hDC)                          
                                Return $CDRF_SKIPDEFAULT
                            EndIf
                            Switch $iItem
                                Case 0 To 9 ;for rows 1-10 lets do this
                                    $iColor1 = RGB2BGR(0xFBFFD8)
                                    $iColor2 = RGB2BGR(-1)
                                    $iColor3 = RGB2BGR(0xFF0000)
                                    If Mod($iSubitem, 2) Then ;odd columns
                                        DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                        DllStructSetData($tCustDraw, 'clrText', 0)
                                    Else ;even columns
                                        DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                        DllStructSetData($tCustDraw, 'clrText', $iColor3)
                                    EndIf
                                Case 10 To 19 ;for rows 11-20 lets do this
                                    $iColor1 = RGB2BGR(0xFBFFD8)
                                    $iColor2 = RGB2BGR(0x3DF8FF)
                                    $hDC = DllStructGetData($tCustDraw, 'hdc')
                                    If Mod($iItem, 2) Then
                                        If Mod($iSubitem, 2) Then
                                            DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                        Else
                                            DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                        EndIf
                                        DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $hDC, "hwnd", $aFont1[0]) ;select our chosen font into DC
                                    Else
                                        If Mod($iSubitem, 2) Then
                                            DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                        Else
                                            DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                        EndIf
                                        DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $hDC, "hwnd", $aFont2[0])
                                    EndIf
                                Case 20 To 29 ;for rows 21-30 lets do this
                                    $iColor1 = RGB2BGR(0xFBFFD8)
                                    $iColor2 = RGB2BGR(-1)
                                    If Mod($iItem, 2) Then ;odd rows
                                        DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                    Else
                                        DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                    EndIf                           
                            EndSwitch
                            Return $CDRF_NEWFONT
                        Case BitOR($CDDS_ITEMPOSTPAINT, $CDDS_SUBITEM)                      
                        Case Else
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func RGB2BGR($iColor)
    Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc
Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Nice! I like it :)

Share this post


Link to post
Share on other sites

Here's modified version of example I posted some time ago

(the "If _GUICtrlListView_GetItemSelected" part specifically)

If you have checkboxes and images on your items, will have to fix rectangles accordingly. And if you want, you can do some other kind of drawing instead of FillRect...

Thanks for the excellent example Siao, you should put that in example scripts because it's really useful. That must have taken some time to work out.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Doesn't work in 3.2.11.1

Because someone's been fixing internal bugs with an axe? :)

In 3.2.11.1, it works if I subclass main GUI (it seems that otherwise my return value from CDDS_ITEMPREPAINT doesn't make it back to listview, for whatever reason):

#Include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>

;custom draw constants
;~ Global Const $CDDS_ITEM = 0x10000
;~ Global Const $CDDS_MAPPART = 0x5
;~ Global Const $CDDS_POSTERASE = 0x4
;~ Global Const $CDDS_POSTPAINT = 0x2
;~ Global Const $CDDS_PREERASE = 0x3
;~ Global Const $CDDS_PREPAINT = 0x1
;~ Global Const $CDDS_SUBITEM = 0x20000
;~ Global Const $CDDS_ITEMPOSTERASE = BitOR($CDDS_ITEM, $CDDS_POSTERASE)
;~ Global Const $CDDS_ITEMPOSTPAINT = BitOR($CDDS_ITEM, $CDDS_POSTPAINT)
;~ Global Const $CDDS_ITEMPREERASE = BitOR($CDDS_ITEM, $CDDS_PREERASE)
;~ Global Const $CDDS_ITEMPREPAINT = BitOR($CDDS_ITEM, $CDDS_PREPAINT)

;~ Global Const $CDIS_CHECKED = 0x8
;~ Global Const $CDIS_DEFAULT = 0x20
;~ Global Const $CDIS_DISABLED = 0x4
;~ Global Const $CDIS_FOCUS = 0x10
;~ Global Const $CDIS_GRAYED = 0x2
;~ Global Const $CDIS_HOT = 0x40
;~ Global Const $CDIS_INDETERMINATE = 0x100
;~ Global Const $CDIS_MARKED = 0x80
;~ Global Const $CDIS_SELECTED = 0x1
;~ Global Const $CDIS_SHOWKEYBOARDCUES = 0x200

;~ Global Const $CDRF_DODEFAULT = 0x0
;~ Global Const $CDRF_NEWFONT = 0x2
;~ Global Const $CDRF_NOTIFYITEMDRAW = 0x20
;~ Global Const $CDRF_NOTIFYPOSTERASE = 0x40
;~ Global Const $CDRF_NOTIFYPOSTPAINT = 0x10
;~ Global Const $CDRF_NOTIFYSUBITEMDRAW = 0x20
;~ Global Const $CDRF_SKIPDEFAULT = 0x4

;fonts for custom draw example
;bold
Global $aFont1 = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 700, _
                        "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _
                        "dword", 0, "str", "")
;italic
Global $aFont2 = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 400, _
                        "dword", 1, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _
                        "dword", 0, "str", "")
                        


$hGUI = GUICreate("Listview Custom Draw", 400, 300)

$cListView = GUICtrlCreateListView("", 2, 2, 394, 268, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$hListView = GUICtrlGetHandle($cListView)
GUICtrlCreateInput("", 50, 275, 100, 15)

_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

; Add items
For $i = 1 To 30
    _GUICtrlListView_AddItem($hListView, "Row" & $i & ": Col 1", $i-1)
    For $j = 1 To 2
        _GUICtrlListView_AddSubItem ($hListView, $i-1, "Row" & $i & ": Col " & $j+1, $j)
    Next
Next

$tNewProc = DllCallbackRegister("_NewWindowProc", "int", "hwnd;uint;wparam;lparam")
$pOldProc = _WinAPI_SetWindowLong($hGUI, -4, DllCallbackGetPtr($tNewProc))
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aFont1[0])
DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aFont2[0])
_WinAPI_SetWindowLong($hGUI, -4, $pOldProc)
DllCallbackFree($tNewProc)
Exit

Func _NewWindowProc($hWnd, $Msg, $wParam, $lParam)
    If $Msg = $WM_NOTIFY Then
        Local $iRet = WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
        If $iRet <> $GUI_RUNDEFMSG Then Return $iRet
    EndIf
    Return _CallWindowProc($pOldProc, $hWnd, $Msg, $wParam, $lParam)
EndFunc
Func _CallWindowProc($pOldProc, $hWnd, $Msg, $wParam, $lParam)
    Local $aRet = DllCall('user32.dll', 'uint', 'CallWindowProc', 'ptr', $pOldProc, 'hwnd', $hWnd, 'uint', $Msg, 'wparam', $wParam, 'lparam', $lParam)
;~  If @error Then Return 0
    Return $aRet[0]
EndFunc
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = 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
                    Local $tCustDraw = DllStructCreate('hwnd hwndFrom;int idFrom;int code;' & _
                                        'dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;' & _
                                        'dword clrText;dword clrTextBk;int SubItem;' & _
                                        'dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align', _ ;winxp or later
                                        $lParam), $iDrawStage, $iItem, $iSubitem, $hDC, $tRect, $iColor1, $iColor2, $iColor3
                    $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage')
                    Switch $iDrawStage
                        Case $CDDS_PREPAINT
                            Return $CDRF_NOTIFYITEMDRAW
                        Case $CDDS_ITEMPREPAINT
                            Return $CDRF_NOTIFYSUBITEMDRAW
                        Case $CDDS_ITEMPOSTPAINT
                        Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
                            $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                            $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
                            If _GUICtrlListView_GetItemSelected($hWndFrom, $iItem) Then
                                $hDC = DllStructGetData($tCustDraw, 'hdc');_WinAPI_GetDC($hWndFrom)
                                $tRect = DllStructCreate('long;long;long;long')
                                If $iSubitem = 0 Then
                                    DllCall('user32.dll','int','SendMessage', 'hwnd',$hWndFrom, 'uint',$LVM_GETSUBITEMRECT, 'wparam',$iItem, 'lparam',DllStructGetPtr($tRect))
                                    DllStructSetData($tRect, 1, 2)
                                    DllCall('user32.dll', 'int', 'FillRect', 'ptr', $hDC, 'ptr', DllStructGetPtr($tRect), 'int', _WinAPI_GetStockObject(4))
                                EndIf
                                DllStructSetData($tRect, 1, 2)
                                DllStructSetData($tRect, 2, $iSubitem)
                                DllCall('user32.dll','int','SendMessage', 'hwnd',$hWndFrom, 'uint',$LVM_GETSUBITEMRECT, 'wparam',$iItem, 'lparam',DllStructGetPtr($tRect))
                                Local $sText = _GUICtrlListView_GetItemText($hWndFrom, $iItem, $iSubitem)
                                DLLCall("gdi32.dll","int","SetTextColor", "ptr", $hDC, "int", RGB2BGR(0xffff00))
                                DLLCall("gdi32.dll","int","SetBkMode", "ptr", $hDC, "int", 1)
                                Local $iAlign = 6
                                If $iSubitem = 0 Then $iAlign = 2
                                DllStructSetData($tRect, 1, DllStructGetData($tRect, 1)+$iAlign)
                                _WinAPI_DrawText($hDC, $sText, $tRect, 0x8000) ;; $DT_END_ELLIPSIS
;~                              _WinAPI_ReleaseDC($hWndFrom, $hDC)                          
                                Return $CDRF_SKIPDEFAULT
                            EndIf
                            Switch $iItem
                                Case 0 To 9 ;for rows 1-10 lets do this
                                    $iColor1 = RGB2BGR(0xFBFFD8)
                                    $iColor2 = RGB2BGR(-1)
                                    $iColor3 = RGB2BGR(0xFF0000)
                                    If Mod($iSubitem, 2) Then ;odd columns
                                        DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                        DllStructSetData($tCustDraw, 'clrText', 0)
                                    Else ;even columns
                                        DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                        DllStructSetData($tCustDraw, 'clrText', $iColor3)
                                    EndIf
                                Case 10 To 19 ;for rows 11-20 lets do this
                                    $iColor1 = RGB2BGR(0xFBFFD8)
                                    $iColor2 = RGB2BGR(0x3DF8FF)
                                    $hDC = DllStructGetData($tCustDraw, 'hdc')
                                    If Mod($iItem, 2) Then
                                        If Mod($iSubitem, 2) Then
                                            DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                        Else
                                            DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                        EndIf
                                        DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $hDC, "hwnd", $aFont1[0]) ;select our chosen font into DC
                                    Else
                                        If Mod($iSubitem, 2) Then
                                            DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                        Else
                                            DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                        EndIf
                                        DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $hDC, "hwnd", $aFont2[0])
                                    EndIf
                                Case 20 To 29 ;for rows 21-30 lets do this
                                    $iColor1 = RGB2BGR(0xFBFFD8)
                                    $iColor2 = RGB2BGR(-1)
                                    If Mod($iItem, 2) Then ;odd rows
                                        DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                    Else
                                        DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                    EndIf                           
                            EndSwitch
                            Return $CDRF_NEWFONT
                        Case BitOR($CDDS_ITEMPOSTPAINT, $CDDS_SUBITEM)                      
                        Case Else
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func RGB2BGR($iColor)
    Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc
Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Outstanding Siao! :) - I will definitly use this somehow.

But my task for now can not be compatible with such method, i need to highlight item "on call" (by function), not on item selection. As i understand, this method required $lParam from the WM_NOTIFY, so i guess i can not use this to highlight without actualy selecting the item.

I looking for a simple method to highlight item with some function call, just like i demonstrated it in my example from the first post. But i need it more efficient ;) .

BTW, how to reduce the font size when item is highlighted in your example? i want it to be the same as item text font.


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

BTW, how to reduce the font size when item is highlighted in your example? i want it to be the same as item text font.

See example for 3.2.11.1 in my previous post (use hdc from customdraw struct).

But my task for now can not be compatible with such method, i need to highlight item "on call" (by function), not on item selection.

And what if user selects another item after that call, what happens to your highlight? Or do you want to highlight any item of your choosing? You can do that with custom draw too I think. Have that function of yours set some variable with index of the item you want highlighted, check the variable in NM_CUSTOMDRAW and color that item. If you don't want to have global variable for that purpose, try storing this flag in lparam of the item's LVITEM structure (_GUICtrlListView_SetItemParam, then _GUICtrlListView_GetItemParam or better yet DllStructGetData($tCustDraw, 'Itemlparam') to check). Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

See example for 3.2.11.1 in my previous post (use hdc from customdraw struct).

It would be too difficult for me now, because i am using v3.2.8.1 (my current project was written on versions earlier than 3.2.8.1, and then rewritten for 3.2.8.1), and i have 3.2.10.0 for testing and new projects. But thank for that example, i will use it when i rewrite all my stuff to 3.2.10.0+ ;)

Sorry, i didn't read very well your example, now it's work with 3.2.8.1 too.

And what if user selects another item after that call, what happens to your highlight?

User can not (should not) select anything while the item is highlighted, the main window is disabled :)

Have that function of yours set some variable with index of the item you want highlighted, check the variable in NM_CUSTOMDRAW and color that item.

The problem is, that the item is not neccessary will be selected (but it might be), how the NM_CUSTOMDRAW message will be sent than?

My main problem for now is to get a correct rectangle for the whole item (including the subitems area). Then i can just draw my highlighting box over that item. As martin has mention, it could be incorrect when there is vertical scroll bars, and also i have checkboxes and images on the items...

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

The problem is, that the item is not neccessary will be selected (but it might be), how the NM_CUSTOMDRAW message will be sent than?

My main problem for now is to get a correct rectangle for the whole item (including the subitems area). Then i can just draw my highlighting box over that item. As martin has mention, it could be incorrect when there is vertical scroll bars, and also i have checkboxes and images on the items...

NM_CUSTOMDRAW notification is sent for each item if you request it, and even for each subitem if you request it too (although this part doesn't work in the latest version).

But you're right that if you won't have repaint problems due to user interaction, you probably don't need that.

To get item rectangle, use _GUICtrlListView_GetSubItemRect with subitem 0 like in my example, or _GUICtrlListView_GetItemRect like you did, except use $iPart=0 (which helpfile says "The bounding rectangle of the entire item"). Why you're adding GUI and LV coords to it, is beyond me though. Draw on LV's device context.

Something like that

#include <GuiConstants.au3>
#include <GuiListView.au3>

$GUI = GUICreate("Test Script", 300, 230)

$ListView = GUICtrlCreateListView("Column|111|222", 20, 10, 260, 160, -1, $LVS_EX_CHECKBOXES)

For $i = 1 To 50
    GUICtrlCreateListViewItem("Item " & $i & "|111|222", $ListView)
Next

$Highlight_Button = GUICtrlCreateButton("Highlight", 20, 190, 60, 20)
$Clear_Button = GUICtrlCreateButton("Clear", 120, 190, 60, 20)

GUISetState(@SW_SHOW, $GUI)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Highlight_Button
            DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $GUI, "ptr", 0, "int", 0, "int", 5)
            
            $iIndex = Number(_GUICtrlListView_GetSelectedIndices($ListView))
            _GUICtrlListViewSetItemHighlight(GUICtrlGetHandle($ListView), $iIndex, 0x0000FF)
        Case $Clear_Button
            DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $GUI, "ptr", 0, "int", 0, "int", 5)
    EndSwitch
WEnd

Func _GUICtrlListViewSetItemHighlight($hListView, $iIndex, $sColor, $iLineWidth=2)
    Local $aItem_Rect = _GUICtrlListView_GetItemRect($hListView, $iIndex, 0)
    _DrawSquare($aItem_Rect[0], $aItem_Rect[1], $aItem_Rect[2]-$aItem_Rect[0], $aItem_Rect[3]-$aItem_Rect[1], _
                $sColor, $iLineWidth, $hListView)
EndFunc

Func _DrawSquare($iLeft, $iTop, $iWidth, $iHeight, $sColor, $iLineWidth=2, $hWnd=0)
    Local $hDC = DllCall("User32.dll", "int", "GetDC", "hwnd", $hWnd)
    Local $aPen = DllCall("GDI32.dll", "int", "CreatePen", "int", 0, "int", $iLineWidth, "int", $sColor)
    
    DllCall("GDI32.dll", "int", "SelectObject", "int", $hDC[0], "int", $aPen[0])
    
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft+$iWidth, "int", $iTop+$iHeight)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop+$iHeight)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hDC[0], "int", $iLeft, "int", $iTop)
    
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "int", $hDC[0])
    DllCall("GDI32.dll", "int", "DeleteObject", "int", $aPen[0])
    
EndFunc

Exit
Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Why you're adding GUI and LV coords to it, is beyond me though.

It's because i didn't knew how to use the $hWnd...

Draw on LV's device context.

Now i know :)

Something like that

It's perfect! thank you!

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Here's modified version of example I posted some time ago

(the "If _GUICtrlListView_GetItemSelected" part specifically)

If you have checkboxes and images on your items, will have to fix rectangles accordingly. And if you want, you can do some other kind of drawing instead of FillRect...

#Include <GuiConstantsEx.au3>
#Include <GuiListView.au3>

;custom draw constants
Global Const $CDDS_ITEM = 0x10000
...............................................................
Is it possible to get this to work on multiple listviews without duplicating the function...I have four listviews I want to use it on. I played around with it for a while and couldn't get it.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Is it possible to get this to work on multiple listviews without duplicating the function...I have four listviews I want to use it on. I played around with it for a while and couldn't get it.

The

Switch $hWndFrom
        Case $hListView

statement obviously only executes the code inside it for 1 control whose handle is stored in $hListView. If you want it to be applied to more listviews, simply add them to the case:

Switch $hWndFrom
        Case $hListView, $hListView2, $hListView3 ;etc...
Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Thanks, I didn't know you could add more than one thing to a Case by just separating them by a comma.

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
Sign in to follow this  
Followers 0