Jump to content
DrJohn

Puzzling behavior with WM_NOTIFY/NM_DBLCLK

Recommended Posts

I have been using (more or less) the same code to catch double-clicks in a ListView for some time, and all of a sudden, it now seems not to work correctly (or possibly it was not all along and I just didn't notice?)

Representative code is below:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <SendMessage.au3>

    global $g_GUI = GUICreate("Test", 520, 360, 300, 50)
    global $g_LV = CreateListView()
    global $g_Dummy = GUICtrlCreateDummy()
    GUISetState(@sw_show)

    GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)

    while True
        $msg = GUIGetMsg()
        switch $msg
            case $g_Dummy
                ConsoleWrite('DBLCLK> ' & @HOUR & ':' & @MIN & ':' & @SEC & @CRLF)
            case $GUI_EVENT_CLOSE
                Exit
        endswitch
    wend


    ; --------------------------
    func CreateListView()

        $style = BitOR($LVS_DEFAULT, $WS_BORDER)
        $lv = _GUICtrlListView_Create($g_GUI, "", 10, 10, 500, 300, $style)
        $ex_style = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($lv, $ex_style)

        _GUICtrlListView_InsertColumn($lv, 0, "A", 60)
        _GUICtrlListView_InsertColumn($lv, 1, "B", 60)
        _GUICtrlListView_JustifyColumn($lv, 1, 2)
        _GUICtrlListView_InsertColumn($lv, 2, "C", 100)
        _GUICtrlListView_InsertColumn($lv, 3, "D", 274)
        _GUICtrlListView_SetTextBkColor($lv, 0xebefe4)

        local $a[] = ["Foo", "Bar", "Baz"]
        for $i = 0 to ubound($a) - 1
            _GUICtrlListView_AddItem($lv, $a[$i], $i)
            for $j = 1 to 3
                _GUICtrlListView_AddSubItem($lv, $i, "---", $j)
            next
        next

        return $lv
    endfunc


    ; --------------------------
    func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

        local $hdr   = DllStructCreate($tagNMHDR, $lParam)
        local $from  = HWnd(DllStructGetData($hdr, "hWndFrom"))
        local $ctrl  = DllStructGetData($hdr, "IDFrom")
        local $event = DllStructGetData($hdr, "Code")

        switch $event
            case $NM_DBLCLK
                GUICtrlSendToDummy($g_Dummy)
        endswitch

        return $GUI_RUNDEFMSG

    endfunc

Observed behavior is that the double-click seems to get caught sporadically.  The ConsoleWrite() call executes some of the time, and not some of the time.  If I sit and double-click on the ListView repeatedly over and over, it will seemingly go for short stretches of a few seconds where it catches nearly every one, then for periods (up to 10 or 15 seconds) where it doesn't catch a single one.

Am I missing something?  I've looked at lots of examples, and I thought this was the right way.

Thanks.

/John

Share this post


Link to post
Share on other sites

I also tested with 100 double click and all was good. add a counter to be sure. $iCount+=1 and print it.

 

Saludos

 

Share this post


Link to post
Share on other sites

Thank you @Danyfirex and @mikell for checking it out.  It's good to know there's nothing obvious wrong with the code.  (Counter was a good idea, BTW; better than a timestamp for tracking whether any double-clicks are missed or not ...)

I don't know what to say.  Today I'm not seeing what I was last night.  I am on a laptop, so 'double-clicking' means double-tapping a touchpad.  It's possible my touchpad was flaking out, although a) I did reboot once in the middle of the testing I was doing, and b) I wasn't observing the intermittent misses when double-clicking in other applications, only this one.

At this point, I wouldn't bet the farm (if I had one) that I wasn't delirious.  It was late -- maybe it was my touchpad's way of telling me I should hang it up for the evening.

Anyway, thanks again for looking.  If I see this again, at least I'll be reasonably sure it isn't because it's coded wrong, but because my laptop is losing its grip (or I am).

/John

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...