Jump to content

[SOLVED] TreeView : NM_CLICK and NM_DBLCLK


Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

tatane,

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

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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

 

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