Modify

Opened 17 years ago

Closed 17 years ago

#243 closed Bug (No Bug)

ListView control on Tab and WM_NOTIFY Event error + reproduction.

Reported by: Shlomikalfa@… Owned by:
Milestone: Component: AutoIt
Version: 3.2.11.10 Severity: None
Keywords: Cc:

Description (last modified by Valik)

[Description]

I have a listview obj, created using the built-in inside a TAB at the 2nd TAB.
the items are inserted using a _UDF someone has donated in the forum...
it is being monitored by WM_Notify [just like in the help file].
when i click on entry #3, Row #4 of the listview, the TAB always switches to it's first TAB item.

[Reproduction]

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

;$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

_Main()

Func _Main()

    Local $GUI, $hImage
    $GUI = GUICreate("(UDF Created) ListView Create", 500, 400)
    GUISetOnEvent($GUI_EVENT_CLOSE, "ExitProg")
    $TAB = GUICtrlCreateTab(0, 0, 498, 398)
    ;GUICtrlSetOnEvent(-1, "TabsChanger")  ; UNTICK ME IF U WANT TO SEE THE MSG.
    $Tab0 = GUICtrlCreateTabItem("ItemNumber0")
    GUICtrlSetOnEvent(-1, "TabsChanger")
    $Tab1 = GUICtrlCreateTabItem("ItemNumber1")
    GUICtrlSetOnEvent(-1, "TabsChanger")
   
    $hListView = GUICtrlCreateListView("#|A|B|C|D|E|F|G|H|I|J|K|L|M", 2, 22, 394, 268)
    ;$hListView = _GUICtrlListView_Create($GUI, "#|A|B|C|D|E|F|G|H|I|J|K|L|M", 2, 2, 394, 268)
    ;;;>> Doesn't create the listview on the tab required but for entire $GUI. [However, if this is used the issue is gone, maybe because of the Listview location...]
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Load items
    For $i = 0 To 20
        MyGUICtrlCreateListViewItem($i&"|BLAA|ASDA|ASDASD|ASDASD|ASDASD|ASDASD", $hListView)
        ;;; USING THIS FUNCTION >>
        ;;;       because of _UDF lack of ability to support unicode properly.
        ;;;       because of built-in flickering property, [it just flashes like a milion times during the updates].
    Next
   
   
    $Tab2 = GUICtrlCreateTabItem("ItemNumber2")
    GUICtrlSetOnEvent(-1, "TabsChanger")
    GUICtrlCreateTabItem("")
    GUISetState()

    ; Loop until user exits
    While 1
    WEnd
EndFunc   ;==>_Main

Func ExitProg()
    Exit
EndFunc


Func TabsChanger()
    MsgBox(0, "IF I AM HERE??", "HERE IS THE BUG")
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
;~  Local $tBuffer
    $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
                    $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"))
            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
       
; #FUNCTION# ====================================================================================================
================
; Name...........: MyGUICtrlCreateListViewItem
; Description ...: Create and insert items directly into the listview, Unicode supported!
; Syntax.........: MyGUICtrlCreateListViewItem($sText, $nCtrlID[, $nIndex = -1])
; Parameters ....: $sText       - Text of the item and subitems seperated by seperation char. [Default "|"]
;                  $nCtrlID     - Listview control ID.
;                  $nIndex      - Item's index. [Default -1, will add at last location]
; Return values .: Nothing.
; Author ........: Unknown, Supplied by: ChrisL @ http://www.autoitscript.com/forum/index.ph...st&p=515453
; Modified.......: Armand. {Unicode support}
; ====================================================================================================
===========================
Func MyGUICtrlCreateListViewItem($sText, $nCtrlID, $nIndex = -1)
    Local $stLvItem = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int;")
    Local $stText = DllStructCreate("wchar[260]")
    Local $arText = StringSplit($sText, "|")

    If $nIndex = -1 Then $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_GETITEMCOUNT, 0, 0)

    DllStructSetData($stText, 1, $arText[1]); Save the item text in the struct

    DllStructSetData($stLvItem, 1, BitOR($LVIF_TEXT, $LVIF_PARAM))
    DllStructSetData($stLvItem, 2, $nIndex)
    DllStructSetData($stLvItem, 6, DllStructGetPtr($stText))
    ; Set the lParam of the struct to the line index - unique within the listview
    DllStructSetData($stLvItem, 9, $nIndex)

    $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_INSERTITEMW, 0, DllStructGetPtr($stLvItem))

    If $nIndex > -1 Then
        ; Insert now the rest of the column text
        For $i = 2 To $arText[0]
            DllStructSetData($stText, 1, $arText[$i])
            DllStructSetData($stLvItem, 3, $i - 1); Store the subitem index

            GUICtrlSendMsg($nCtrlID, $LVM_SETITEMTEXTW, $nIndex, DllStructGetPtr($stLvItem))
        Next
    EndIf

    $stText = 0
    $stLvItem = 0

EndFunc   ;==>MyGUICtrlCreateListViewItem

Attachments (0)

Change History (4)

comment:1 follow-up: Changed 17 years ago by Valik

The problem is likely related to issue #222.

comment:2 Changed 17 years ago by Valik

  • Description modified (diff)

comment:3 in reply to: ↑ 1 Changed 17 years ago by Valik

Replying to Valik:

The problem is likely related to issue #222.

This is likely due to mixing native and non-native (to AutoIt) control manipulation. You create a native list-view control but then you populate it in a non-native way so AutoIt is confused by what's going on and has unpredictable results. I'll leave it to Gary or JPM to diagnose further, however.

For what it's worth, you can put Return 1 in your $NM_CLICK handler and things will work since it causes AutoIt to skip default handling of the message which prevents it from becoming confused.

comment:4 Changed 17 years ago by Gary

  • Resolution set to No Bug
  • Status changed from new to closed

It's due to the user function setting the param value to low, needs to be something that the autoit internal numbering won't use.

No Bug.

Just comment out

DllStructSetData($stLvItem, 9, $nIndex)

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.