﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
243	ListView control on Tab and WM_NOTIFY Event error + reproduction.	Shlomikalfa@…		"'''[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
}}}"	Bug	closed		AutoIt	3.2.11.10	None	No Bug		
