Sign in to follow this  
Followers 0
jennico

assign cursor to listviewitem ?

3 posts in this topic

#1 ·  Posted (edited)

Hi there,

i noticed that you cannot assign a special cursor to a listviewitem.

GUICtrlSetCursor(-1,0) works for the entire list view but not for the items.

first question: maybe anyone knows how to do it ?

then, at least i tried to create my own function "_GUICtrlListViewSetHotCursor()" by studying msdn but my script is messing up autoit:

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

Opt ('MustDeclareVars', 1)
Dim $listview, $Btn_Exit, $msg, $Status, $hCursor
GUICreate("ListView Set Hot Cursor", 392, 322)

$listview = GUICtrlCreateListView("col1|col2|col3", 40, 30, 310, 144)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_HEADERDRAGDROP, $LVS_EX_HEADERDRAGDROP)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_TRACKSELECT, $LVS_EX_TRACKSELECT)
    ;GUICtrlSetCursor(-1,0) ;   works for entire listview

;   this line causes an error
$hCursor=DllCall ( "user32.dll", "int_ptr", "LoadCursorFromFile" , "str", @WindowsDir&"\Cursors\harrow.cur" )
MsgBox(0,@error,$hCursor)

;   Global Const $LVM_SETHOTCURSOR = ($LVM_FIRST + 62)
;   Global Const $LVM_FIRST = 0x1000
    If IsHWnd($listview) Then
        MsgBox(0,1,_SendMessage($listview, 0x1000 + 62, 0, $hCursor))
    Else
        MsgBox(0,2,GUICtrlSendMsg($listview, 0x1000 + 62, 0, $hCursor))
    EndIf

For $i = 1 To 20
    GUICtrlCreateListViewItem("line" & $i & "|data" & $i & "|more" & $i, $listview)
    ;GUICtrlSetCursor(-1,0) ;   does not work !
Next

$Btn_Exit = GUICtrlCreateButton("Exit", 300, 260, 70, 30)
$Status = GUICtrlCreateLabel("Hot Cursor: " & _GUICtrlListViewGetHotCursor($listview), 0, 302, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
    EndSelect
WEnd
Exit

second question: what do i do wrong ?

in my script you can manually enter a value for hCursor, but this does not change the cursor indeed.

third question: basically, what does the value returned by "_GUICtrlListViewGetHotCursor()" mean ?

the (helpfile) example script always returns 65581 or 0x100D2. so what do i do with this value ?

thank you and sorry for my messy noob dll handling :) i need some more lessons.

j.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites



anybody out there ?


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The DllCall return $hCursor is an array, where $hCursor[0] is the handle to the new cursor.

Try this, I've modified the help file example for _GUICtrlListView_GetHotItem. It works but I'm sure there's a better way.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

Global $hListView, $hStatus
;Local $sCursorFile = @WindowsDir & "\Cursors\stopwtch.ani"
Local $sCursorFile = @WindowsDir & "\Cursors\cross.cur"
Global $aCur = DllCall("user32.dll", "ptr", "LoadCursorFromFile", "str", $sCursorFile)
If $aCur[0] = 0 Then
    MsgBox(0, "Exception", "Can not find cursor file " & $sCursorFile)
    Exit
EndIf

Example_Internal()

Func Example_Internal()
    Local $hGUI
    
    $hGUI = GUICreate("(Internal) ListView Get Hot Item", 392, 322)

    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    $hListView = GUICtrlGetHandle($hListView)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_TRACKSELECT))
    $hStatus = _GUICtrlStatusBar_Create($hGUI)
    _GUICtrlStatusBar_SetSimple($hStatus, True)
    GUISetState()

    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 3", 100)

    ; Add items
    For $i = 0 To 20
        $j = "Row " & StringFormat("%.02u", $i)
        _GUICtrlListView_AddItem($hListView, $j & ": Col 1")
        _GUICtrlListView_AddSubItem($hListView, $i, $j & ": Col 2", 1)
        _GUICtrlListView_AddSubItem($hListView, $i, $j & ": Col 3", 2)
    Next
    ;Register WM_NOTIFY  events
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    DllCall("user32.dll", "int", "DestroyCursor", "ptr", $aCur[0])
EndFunc   ;==>Example_Internal

Func ListView_HOTTRACK($iItem, $iSubItem)
    Local $HotItem = _GUICtrlListView_GetHotItem($hListView)
    If $HotItem <> -1 Then _GUICtrlStatusBar_SetText($hStatus, "Hot Item: " & $HotItem & " SubItem: " & $iSubItem)
EndFunc   ;==>ListView_HOTTRACK

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode & @LF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ; No return value
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode & @LF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ; No return value
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode & @LF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ;Return 1 ; not to allow the default processing
                    Return 0 ; allow the default processing
                Case $LVN_HOTTRACK Or $NM_LDOWN ; Sent by a list-view control when the user moves the mouse over an item
                    DllCall("user32.dll", "int", "SetCursor", "int", $aCur[0])
                    If $iCode = $LVN_HOTTRACK Then
                        Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                        ListView_HOTTRACK(DllStructGetData($tInfo, "Item"), DllStructGetData($tInfo, "SubItem"))
                        Return 0
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint
Edited by picaxe

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