Sign in to follow this  
Followers 0
Nahuel

ListView onEventMode?

4 posts in this topic

#1 ·  Posted (edited)

Simple. All I want is that when the user clicks on ANY item of the first list, it enables the second one.

Here's my code:

#include <GUIconstants.au3>
GUICreate("Resistor Color-2-Ohm",450,400)
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")
GUISetState()
Opt ("GUIOnEventMode",1)
$Lista1=GUICtrlCreateListView ("Primer Color    ",10,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)
GUICtrlSetOnEvent(-1,"habilitar2")
$Lista2=GUICtrlCreateListView ("Segundo Color",100,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)
GUICtrlSetOnEvent(-1,"habilitar3")
$Lista3=GUICtrlCreateListView ("Tercer Color    ",190,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)
GUICtrlSetOnEvent(-1,"habilitar4")
$Lista4=GUICtrlCreateListView ("Cuarto Color    ",280,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)

GUICtrlSetState($lista2,$GUI_DISABLE)
GUICtrlSetState($lista3,$GUI_DISABLE)
GUICtrlSetState($lista4,$GUI_DISABLE)

GUICtrlCreateListViewItem("Item",$Lista1)
GUICtrlCreateListViewItem("Item",$Lista1)
GUICtrlCreateListViewItem("Item",$Lista1)

GUICtrlCreateListViewItem("Item",$Lista2)
GUICtrlCreateListViewItem("Item",$Lista2)
GUICtrlCreateListViewItem("Item",$Lista2)

GUICtrlCreateListViewItem("Item",$Lista3)
GUICtrlCreateListViewItem("Item",$Lista3)
GUICtrlCreateListViewItem("Item",$Lista3)
While 1
    Sleep(50)
WEnd


;Funciones:
Func _exit()
    Exit
EndFunc

Func habilitar2()
    GUICtrlSetState($lista2,$GUI_ENABLE)
EndFunc
Func habilitar3()
    GUICtrlSetState($lista3,$GUI_ENABLE)
EndFunc
Func habilitar4()
    GUICtrlSetState($lista4,$GUI_ENABLE)
EndFunc

It doesn't work like this, but if I use the CtrlSetOnEvent with some item, it works:

#include <GUIconstants.au3>
GUICreate("Resistor Color-2-Ohm",450,400)
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")
GUISetState()
Opt ("GUIOnEventMode",1)
$Lista1=GUICtrlCreateListView ("Primer Color    ",10,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)

$Lista2=GUICtrlCreateListView ("Segundo Color",100,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)

$Lista3=GUICtrlCreateListView ("Tercer Color    ",190,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)

$Lista4=GUICtrlCreateListView ("Cuarto Color    ",280,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)

GUICtrlSetState($lista2,$GUI_DISABLE)
GUICtrlSetState($lista3,$GUI_DISABLE)
GUICtrlSetState($lista4,$GUI_DISABLE)

GUICtrlCreateListViewItem("Click here",$Lista1)
GUICtrlSetOnEvent(-1,"habilitar2")
GUICtrlCreateListViewItem("Item",$Lista1)
GUICtrlCreateListViewItem("Item",$Lista1)

GUICtrlCreateListViewItem("Item",$Lista2)
GUICtrlCreateListViewItem("Click here",$Lista2)
GUICtrlSetOnEvent(-1,"habilitar3")
GUICtrlCreateListViewItem("Item",$Lista2)

GUICtrlCreateListViewItem("Item",$Lista3)
GUICtrlCreateListViewItem("Item",$Lista3)
GUICtrlCreateListViewItem("Item",$Lista3)
While 1
    Sleep(50)
WEnd


;Funciones:
Func _exit()
    Exit
EndFunc

Func habilitar2()
    GUICtrlSetState($lista2,$GUI_ENABLE)
EndFunc
Func habilitar3()
    GUICtrlSetState($lista3,$GUI_ENABLE)
EndFunc
Func habilitar4()
    GUICtrlSetState($lista4,$GUI_ENABLE)
EndFunc

The problem is that I need it to enable the next list when the user clicks any item, not a specific one. Why doesn't this work?

Edited by Nahuel

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This should work

#include <GUIconstants.au3>
Global Const $WM_NOTIFY = 0x004E;

GUICreate("Resistor Color-2-Ohm",450,400)
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")

Opt ("GUIOnEventMode",1)

Global $Lista1=GUICtrlCreateListView ("Primer Color ",10,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)
Global $Lista2=GUICtrlCreateListView ("Segundo Color",100,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)
Global $Lista3=GUICtrlCreateListView ("Tercer Color ",190,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)
Global $Lista4=GUICtrlCreateListView ("Cuarto Color ",280,10,90,205,$LVS_SINGLESEL+$LVS_NOSORTHEADER)

GUICtrlSetState($lista2,$GUI_DISABLE)
GUICtrlSetState($lista3,$GUI_DISABLE)
GUICtrlSetState($lista4,$GUI_DISABLE)

GUICtrlCreateListViewItem("Click here",$Lista1)
GUICtrlCreateListViewItem("Item",$Lista1)
GUICtrlCreateListViewItem("Item",$Lista1)

GUICtrlCreateListViewItem("Item",$Lista2)
GUICtrlCreateListViewItem("Click here",$Lista2)
GUICtrlCreateListViewItem("Item",$Lista2)

GUICtrlCreateListViewItem("Item",$Lista3)
GUICtrlCreateListViewItem("Item",$Lista3)
GUICtrlCreateListViewItem("Item",$Lista3)

GUISetState()

While 1
    Sleep(50)
WEnd


;Funciones:
Func _exit()
    Exit
EndFunc

Func habilitar2()
   GUICtrlSetState($lista2,$GUI_ENABLE)
    GUICtrlSetState($lista3,$GUI_DISABLE)
    GUICtrlSetState($lista4,$GUI_DISABLE)
EndFunc
Func habilitar3()
    GUICtrlSetState($lista3,$GUI_ENABLE)
    GUICtrlSetState($lista4,$GUI_DISABLE)
EndFunc
Func habilitar4()
    GUICtrlSetState($lista4,$GUI_ENABLE)
EndFunc

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event
    Local Const $NM_FIRST = 0
    Local Const $NM_CLICK = ($NM_FIRST - 2)
    Local Const $NM_DBLCLK = ($NM_FIRST - 3)
    
    Switch $wParam 
        Case $Lista1,$Lista2,$Lista3,$Lista4
            $tagNMHDR = DllStructCreate("int;int;int", $lParam)
            If @error Then Return
            $event = DllStructGetData($tagNMHDR, 3)
            If $event = $NM_CLICK or $event = $NM_DBLCLK then 
                
                Switch $wParam
                    Case $Lista1 
                         habilitar2()
                    Case $Lista2
                         habilitar3()
                    Case $lista3
                         habilitar4()   
                    Case $lista4
                         ConsoleWrite("Additional one" & @crlf) 
                EndSwitch

            EndIf
            
    EndSwitch
        
EndFunc

Edit: Added a bit which if you go backwards it disables the correct one. so for example if you had gone all the way to the end then click back on the first one it disables 3 and 4

Edited by ChrisL

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