Jump to content
tatane

[SOLVED] TreeView : NM_CLICK and NM_DBLCLK

Recommended Posts

tatane
Posted (edited)

Hi,

I'm trying to generate a Dir/Files treeview and I've got a problem handling the left click and left double click on items.

I handle the 2 clicks In my WM_NOTIFY function but the NM_CLICK is also triggered when I double click.

Is there a way to trigger NM_DBLCLK without triggering NM_CLICK ? I've 2 different processings attached to the clicks so I dont want the one for the single click be triggered when it should be the one for the double click.

 

Thanks.

Edited by tatane

Share this post


Link to post
Share on other sites
spudw2k

Doing some brief google-ing, this seems to be a standard Windows behavior.  You can't get a double-click event without two clicks.  Essentially, a double-click is two clicks within a period of time set; I know this is not saying anything un-obvious, but think about it...how can you have the latter without the prior?

You might want to consider a different approach.  More details on what you are trying to accomplish will give us a bigger picture and may give us more ideas.

Share this post


Link to post
Share on other sites
tatane

I understand. It's logical indeed.

I can't easily put a snippet because it's a tcp client/server programm. Basically, I'm getting files & folders tree from a remote computer.

So when I simple click on a folder item in my left treeview (server console), I send a request to the client to get the list of files and folders. I get them back and fill my left treeview with it. The problem is that I use double click to send a different request to expand the selected folder in the left tree so it will send one request for the single click and a second (the one I need) for the double click.

Share this post


Link to post
Share on other sites
Melba23

tatane,

When you detect a single click set a flag and start an Adlib check for a suitable time later (it must be a longer interval than the Windows limit for double clicks). If you then get a double click and the flag is set for a single, clear the flag and action the doubleclick code. When the Adlib fires if the flag is set, action the single click code. I have to go out shortly - I will try and produce something to show this in action when I return this afternoon.

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
tatane
Posted (edited)

Ok thanks, I will try your solution and if I'm not able to do it, I'll wait your "something" :)

I think I produce your solution (example) :

Global $iTreeView_Flag = false

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    Local $hWndDirTree = $DirTree
    If Not IsHWnd($DirTree) Then $hWndDirTree = GUICtrlGetHandle($DirTree)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndDirTree
            Switch $iCode
                Case $NM_DBLCLK
                    If $iTreeView_Flag Then
                        $iTreeView_Flag = False
                        AdlibUnRegister("checkclick")
                        ; _TreeView_DBLCLK($hWndDirTree)
                    EndIf

                Case $NM_CLICK
                     $iTreeView_Flag = True
                     AdlibRegister("checkclick", 550)
            EndSwitch

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func checkclick()
    If $iTreeView_Flag Then
         ConsoleWrite('simple clic' & @CRLF)
         AdlibUnRegister("checkclick")
        ; _TreeView_CLICK($DirTree)
    EndIf
EndFunc

 

Edited by tatane

Share this post


Link to post
Share on other sites
Melba23

tatane,

Looks good to me. You can determine the currently set doubleclick delay using:

RegRead("HKCU\Control Panel\Mouse","DoubleClickSpeed"

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
tatane

I found 500ms on msdn. But getting the value from registry is better. Thanks Melba.

Share this post


Link to post
Share on other sites
Andreik

Actually you don't need any kind of flag, you can do it with a simple adlib.

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

Global $hTreeView, $iDoubleClickSpeed = DllCall('user32.dll','uint','GetDoubleClickTime')[0]

$hMain = GUICreate('Example')
$hTreeView = GUICtrlCreateTreeView(10,10,380,380)
For $i = 1 To 10
    GUICtrlCreateTreeViewItem('Item ' & $i,$hTreeView)
Next
GUISetState(@SW_SHOW, $hMain)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

Do
    Sleep(10)
Until GUIGetMsg() = -3


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = GUICtrlGetHandle($hTreeView)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_CLICK
                    AdlibRegister('LeftClickEvent',$iDoubleClickSpeed)
                    Return 0
                Case $NM_DBLCLK
                    DoubleLeftClickEvent()
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func LeftClickEvent()
    AdlibUnRegister('LeftClickEvent')
    ConsoleWrite('Left click' & @CRLF)
EndFunc

Func DoubleLeftClickEvent()
    AdlibUnRegister('LeftClickEvent')
    ConsoleWrite('Double left click' & @CRLF)
EndFunc

 

  • Like 1

When the words fail... music speaks

Share this post


Link to post
Share on other sites
tatane

Yep it works. Thank you.

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

×