Jump to content

Change cursor when hovered on a listview item


 Share

Recommended Posts

  • Moderators

Lilbert,

So when do you want the cursor to change? Please give us some more hints - or much better post some code showing the listview you are using and tell us the areas where you want the cursor to change. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba23,

Sorry for being vague. Here's a sample script:

#include <Array.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <ListviewConstants.au3>
#include <SendMessage.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $iIndex = -1, $iSubIndex = -1, $no = 3, $_Files[$no], $asFiles[$no], $hGUI_ListView[$no], $hListView[$no], $hGUI_ListView_ImageList[$no]

Global $sFolderPath[$no] = [@DesktopDir, 'C:', 'D:']
$hGUI = GUICreate('GUI', 250, @DesktopHeight / 2)
$a = 0
;For $a = 0 To $no - 1 Step +1
$asFiles = _FileListToArray($sFolderPath[$a])
$_size = UBound($asFiles)
If Not IsDeclared('_Compare') Then
  Dim $_Files[$no][$_size]
  Local $_Compare = $_size
Else
  If $_size > $_Compare Then ReDim $_Files[$no][$_size]
EndIf
$hGUI_ListView[$a] = GUICtrlCreateListView($a, $a * 250, 0, 250, @DesktopHeight / 2)
GUICtrlSetCursor ( -1, 14) ; <<<<<<<<<<
$hListView[$a] = GUICtrlGetHandle($hGUI_ListView[$a])
GUICtrlSetStyle($hGUI_ListView[$a], BitOR($LVS_ICON, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOCOLUMNHEADER), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_FLATSB))

For $i = 1 To $asFiles[0]
  $lvitem = GUICtrlCreateListViewItem($asFiles[$i], $hGUI_ListView[$a])
  GUICtrlSetImage($lvitem, "shell32.dll", 224)
Next
;Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   _exit()
EndSwitch
WEnd
#region - Functions
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
For $c = 0 To $no - 1 Step +1
  If $hWndFrom = $hListView[$c] Then
   If $iCode = $NM_DBLCLK Then
    _dblclk($c)
   ElseIf $iCode = $NM_KILLFOCUS Then
    ControlListView('','',$hListView[$c],"SelectClear")
   EndIf
  EndIf
Next
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func _dblclk($no)
Local $aHit = _GUICtrlListView_SubItemHitTest($hListView[$no])
If ($aHit[0] <> -1) And (($aHit[0] <> $iIndex) Or ($aHit[1] <> $iSubIndex)) Then
  $_filename = $sFolderPath[$no] & '' & $_Files[$no][$aHit[0] + 1]
  ConsoleWrite(@CRLF & 'Double click ' & @CRLF & $_filename & @CRLF)
EndIf
EndFunc   ;==>_execute
Func _exit()
Exit
EndFunc   ;==>_exit
#endregion - Functions

I'd like to have the cursor change only when it is placed over the icons. Would that be possible?

Thanks!

Link to comment
Share on other sites

  • Moderators

Lilbert,

The only thing I can think of is to use _GUICtrlListView_GetItemRect to find the coordinates of the icons and change the cursor when it is withint those coordinates. But that seems a very complex and CPU intensive way of going about things. ;)

I am sure someone else will have a better idea. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I'd like to have the cursor change only when it is placed over the icons. Would that be possible?

Use hit test to check if mouse is over icon in LVN_HOTTRACK notification.

Notification still sent even if listview doesn't have hot tracking enabled with LVS_EX_TRACKSELECT

#include <Array.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <ListviewConstants.au3>
#include <SendMessage.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $iIndex = -1, $iSubIndex = -1, $no = 3, $_Files[$no], $asFiles[$no], $hGUI_ListView[$no] =[0,0,0], $hListView[$no], $hGUI_ListView_ImageList[$no]

Global $sFolderPath[$no] = [@DesktopDir, 'C:', 'D:']
$hGUI = GUICreate('GUI', 250, @DesktopHeight / 2)
$a = 0
;For $a = 0 To $no - 1 Step +1
$asFiles = _FileListToArray($sFolderPath[$a])

$_size = UBound($asFiles)
If Not IsDeclared('_Compare') Then
    Dim $_Files[$no][$_size]
    Local $_Compare = $_size
Else
    If $_size > $_Compare Then ReDim $_Files[$no][$_size]
EndIf

$hGUI_ListView[$a] = GUICtrlCreateListView($a, $a * 250, 0, 250, @DesktopHeight / 2)
$hListView[$a] = GUICtrlGetHandle($hGUI_ListView[$a])
GUICtrlSetStyle($hGUI_ListView[$a], BitOR($LVS_ICON, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOCOLUMNHEADER), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_FLATSB))

For $i = 1 To $asFiles[0]
    $lvitem = GUICtrlCreateListViewItem($asFiles[$i], $hGUI_ListView[$a])
    GUICtrlSetImage($lvitem, "shell32.dll", 224)
Next
;Next

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Exit()
    EndSwitch
WEnd

#region - Functions
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") ;this use of HWnd() is a leftover from the old incorrect tagNMHDR struct from years ago
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $iIDFrom ;better than looping, faster than checking handles with WinGetClassList = SysHeader32 or _WinAPI_GetClassName = SysListView32
        Case $hGUI_ListView[0], $hGUI_ListView[1], $hGUI_ListView[2] ;better to compare integer control ID instead of handle, listview handles available in $hWndFrom
            Switch $iCode
                Case $NM_DBLCLK
                    _dblclk($hWndFrom) ;use handle, as hit test functions do not convert ID to handle
                Case $NM_KILLFOCUS
                    ControlListView($hWndFrom, '', $hWndFrom, "SelectClear") ;use with handles, otherwise a search for window is done each time called
                Case $LVN_HOTTRACK; Sent by a list-view control when the user moves the mouse over an item
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    If DllStructGetData($tInfo, "Item") = -1 Then
                        GUICtrlSetCursor($iIDFrom, -1) ;not over item
                        Return 1
                    EndIf
                    Local $aHit = _GUICtrlListView_HitTest($hWndFrom);use handle, as hit test functions do not convert ID to handle
                    If @error Then Return 1
                    If $aHit[2] Then
                        GUICtrlSetCursor($iIDFrom, 14) ;over icon - includes wide margin on left/right of icon, may be due to internal imagelist size or some MS design decision.
                    Else
                        GUICtrlSetCursor($iIDFrom, -1) ;over item text
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _dblclk($hWnd)
    Local $aHit = _GUICtrlListView_SubItemHitTest($hWnd), $iI = 0
    If @error Then Return 1
    If ($aHit[0] <> -1) And (($aHit[0] <> $iIndex) Or ($aHit[1] <> $iSubIndex)) Then
        For $i = 0 To UBound($hListView) - 1
            If $hListView[$i] = $hWnd Then
                $iI = $i ; For loop auto declared $i is not valid outside loop
                ExitLoop
            EndIf
        Next
        $_filename = $sFolderPath[$iI] & '\' & $asFiles[$aHit[0] + 1]
        ConsoleWrite(@CRLF & 'Double click ' & @CRLF & $_filename & @CRLF)
    EndIf
EndFunc   ;==>_dblclk

Func _Exit()
    Exit
EndFunc   ;==>_Exit
#endregion - Functions

I see fascists...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...