Jump to content

Double click mouse option in tree view


upendk
 Share

Recommended Posts

Hi,

I am new to AutoIt Scripting, I have created a Tree View, Just want to add Double Mouse Click Funtion (Like if user double click on the option it, the scripts redirects it to the corresponding path as mentioned in the script) for the Child option. If anyone could help me out in this.

Regards,

Upendk

Link to comment
Share on other sites

Demo detects double click on either the GUI or the treeview:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $hGUI, $idTV

$hGUI = GUICreate("Test", 300, 300)
$idTV = GUICtrlCreateTreeView(20, 20, 260, 100)
For $i = 1 To 5
    $idItem = GUICtrlCreateTreeViewItem("Item " & $i, $idTV)
    For $c = 1 To 5
        $idChild = GUICtrlCreateTreeViewItem("Child " & $c, $idItem)
    Next
Next

GUIRegisterMsg($WM_LBUTTONDBLCLK, "_WM_LBUTTONDBLCLK")
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tagNMHDR = "int hwndFrom; int idFrom; int code"
    Switch $wParam
        Case $idTV
            Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
            If @error Then Return
            If DllStructGetData($tNMHDR, "code") = $NM_DBLCLK Then
                ConsoleWrite("Double click on TreeView:  Hwnd = " & DllStructGetData($tNMHDR, "hwndFrom") & _
                        "; ID = " & DllStructGetData($tNMHDR, "idFrom") & @LF)
            EndIf
    EndSwitch
    $tNMHDR = 0
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

Func _WM_LBUTTONDBLCLK($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iX = BitAND($ilParam, 0xFFFF)
    Local $iY = BitShift($ilParam, 16)
    ConsoleWrite("Double click on GUI:  Hwnd = " & $hWnd & "; X = " & $iX & "; Y = " & $iY & @CRLF)
EndFunc   ;==>_WM_LBUTTONDBLCLK

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Demo detects double click on either the GUI or the treeview:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $hGUI, $idTV

$hGUI = GUICreate("Test", 300, 300)
$idTV = GUICtrlCreateTreeView(20, 20, 260, 100)
For $i = 1 To 5
    $idItem = GUICtrlCreateTreeViewItem("Item " & $i, $idTV)
    For $c = 1 To 5
        $idChild = GUICtrlCreateTreeViewItem("Child " & $c, $idItem)
    Next
Next

GUIRegisterMsg($WM_LBUTTONDBLCLK, "_WM_LBUTTONDBLCLK")
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tagNMHDR = "int hwndFrom; int idFrom; int code"
    Switch $wParam
        Case $idTV
            Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
            If @error Then Return
            If DllStructGetData($tNMHDR, "code") = $NM_DBLCLK Then
                ConsoleWrite("Double click on TreeView:  Hwnd = " & DllStructGetData($tNMHDR, "hwndFrom") & _
                        "; ID = " & DllStructGetData($tNMHDR, "idFrom") & @LF)
            EndIf
    EndSwitch
    $tNMHDR = 0
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

Func _WM_LBUTTONDBLCLK($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iX = BitAND($ilParam, 0xFFFF)
    Local $iY = BitShift($ilParam, 16)
    ConsoleWrite("Double click on GUI:  Hwnd = " & $hWnd & "; X = " & $iX & "; Y = " & $iY & @CRLF)
EndFunc   ;==>_WM_LBUTTONDBLCLK

:D

Link to comment
Share on other sites

  • 6 months later...

Are you running it in SciTE? The console is the bottom pane of the SciTE window, not the CMD shell console.

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Of course it runs in Scite. The bottom pane does not display your "Double click on treeview..." output.

(I've been working with AutoIt/Scite for over 6 years now, so I'm not that kind of new guy... :blink: )

Here's the log created while running your script, double clicking and a few of the "child" TVI's:

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\Andreas\Desktop\demo_dblclick.au3" /autoit3dir "C:\Program Files (x86)\AutoIt3" /UserParams    
+>13:56:22 Starting AutoIt3Wrapper v.2.0.0.3    Environment(Language:0407  Keyboard:00000407  OS:WIN_VISTA/  CPU:X64 OS:X64)
>Running AU3Check (1.54.19.0)  from:C:\Program Files (x86)\AutoIt3
+>13:56:22 AU3Check ended.rc:0
>Running:(3.3.6.1):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\Andreas\Desktop\demo_dblclick.au3"    
Double click on GUI:  Hwnd = 0x00000000000106AA; X = 137; Y = 198
+>13:56:36 AutoIT3.exe ended.rc:0
+>13:56:37 AutoIt3Wrapper Finished
>Exit code: 0    Time: 15.401

My OS is Win7, not WinVista as stated in that log.

Link to comment
Share on other sites

Oh, wow. I'm getting weirdness on Vista SP2 32-bit. I was sure that used to work on the old XP load it was written on!

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Temp\Test1.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams    
+>12:08:23 Starting AutoIt3Wrapper v.2.0.1.22    Environment(Language:0409  Keyboard:00000409  OS:WIN_VISTA/Service Pack 2  CPU:X64 OS:X86)
>Running AU3Check (1.54.19.0)  from:C:\Program Files\AutoIt3
+>12:08:24 AU3Check ended.rc:0
>Running:(3.3.6.1):C:\Program Files\AutoIt3\autoit3.exe "C:\Temp\Test1.au3"    
Double click on TreeView:  Hwnd = 1443026; ID = 3
Double click on TreeView:  Hwnd = 1443026; ID = 3
Double click on TreeView:  Hwnd = 1443026; ID = 3
+>12:17:24 AutoIT3.exe ended.rc:0
>Exit code: 0    Time: 543.119

Notice I get the opposite failure: _WM_NOTIFY() triggers, but _WM_LBUTTONDBLCLK() does not. You seem to be seeing _WM_LBUTTonclick() because you're getting the X/Y coord (of the GUI) from lwparam instead of the ID.

:P

I'm confusing myself. ;)

I messed around with another version that works fine for both the GUI and treeview using the UDF functions, and can be run compiled:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <WinAPI.au3>

Global $hGUI, $hTV, $idTV, $idEdit, $hItem, $hChild

$hGUI = GUICreate("Test", 300, 400)
$hTV = _GUICtrlTreeView_Create($hGUI, 20, 20, 260, 100)
$idTV = _WinAPI_GetDlgCtrlID($hTV)

For $i = 1 To 5
    $hItem = _GUICtrlTreeView_Add($hTV, 0, "Item " & $i)
    For $c = 1 To 5
        $hChild = _GUICtrlTreeView_AddChild($hTV, $hItem, "Child " & $c)
    Next
Next

$idEdit = GUICtrlCreateEdit("", 20, 140, 260, 240)
ControlSetText($hGUI, "", $idEdit, ControlGetText($hGUI, "", $idEdit) & _
        "Initilize script:  " & @CRLF & _
        "$hGUI = " & $hGUI & @CRLF & _
        "$hTV = " & $hTV & "; $idTV = " & $idTV & @CRLF & _
        "$idEdit = " & $idEdit & @CRLF)

GUIRegisterMsg($WM_LBUTTONDBLCLK, "_WM_LBUTTONDBLCLK")
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tagNMHDR = "int hwndFrom; int idFrom; int code"
    Switch $wParam
        Case $idTV
            Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
            If @error Then Return
            If DllStructGetData($tNMHDR, "code") = $NM_DBLCLK Then
                ControlSetText($hGUI, "", $idEdit, ControlGetText($hGUI, "", $idEdit) & _
                        "Double click on TreeView:  Hwnd = " & DllStructGetData($tNMHDR, "hwndFrom") & _
                        "; ID = " & DllStructGetData($tNMHDR, "idFrom") & @CRLF)
            EndIf
    EndSwitch
    $tNMHDR = 0
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

Func _WM_LBUTTONDBLCLK($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iX = BitAND($ilParam, 0xFFFF)
    Local $iY = BitShift($ilParam, 16)
    ControlSetText($hGUI, "", $idEdit, ControlGetText($hGUI, "", $idEdit) & _
            "Double click on GUI:  Hwnd = " & $hWnd & "; X = " & $iX & "; Y = " & $iY & @CRLF)
EndFunc   ;==>_WM_LBUTTONDBLCLK

To compare, I went back and tried the original again and it also works fine for both (to the console). I think when I tried it a little while ago, I kept hitting the treeview and not the GUI.

All this is working on 32-bit Vista, maybe we have a 64-bit issue here? Don't have it to test on here.

:blink:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

When I run this script in 32-bit mode like

C:\Program Files\AutoIt3\AutoIt3.exe C:\temp\demo_dblclick.au3

TVI double clicks are working. In 64-bit, they are not.

I replaced ConsoleWrite() with MsgBox() for this test, because I don't have SciTE's console here.

So I reinstalled AutoIt3 without use of 64-bit tools and this seems to be the trick. The demo script works as intended.

Now SciTE runs the script with 32-bit version of AutoIt3.exe.

[...]
>Running:(3.3.6.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\Andreas\Desktop\demo_dblclick.au3"    
Double click on treeview:  Hwnd = 655774; ID = 3
Double click on GUI:  Hwnd = 0x000F0798; X = 176; Y = 236
[...]

But you are already running a 32-bit OS, so this makes your problem really strange. You could try, setting the compatibility mode for your AutoIt3.exe to WinXP, but I doubt it will change anything. Could be also a Vista thing, as it isn't that mature als Win7 :blink: .

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...