Jump to content

guictrlsetonevent with doubleclick?


Hawkwing
 Share

Recommended Posts

I'm trying to write a script where I can double click on a listview item and have it run a function. I suppose I could just do guictrlsetonevent and then have it check for another click for about half a second, but I'd rather not since I want to be able to do other stuff at the same time.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Well, uh, errm, do you have an example without the dll stuff? I have absolutely no idea how to do that stuff :)

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Thanks, I got it working now, but I have no idea why it works, so hopefully someone will explain a few of the things to me.

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
;~  Local $tBuffer
    $hWndListView = $listview
    If Not IsHWnd($listview) Then $hWndListView = GUICtrlGetHandle($listview)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK
;~                  Now I need the handle of the listviewitem
            EndSwitch
    EndSwitch
EndFunc

First, what exactly do the dll things do?

And second, what does #forceref do?

And third, how do I get the handle of the listviewitem I double click?

Edit: Congrats on becoming an MVP :)

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

1) The dll structs are used for data passed between the system andthe your application. This message for example (WM_NOTIFY) will call your handler with $ilparam set to a pointer to a structure or nothing if it's not used as in some notifications. When you handle a notification you first need to read what data it sent on the notification such as $tagLVITEM which contains information about the list view item in question. You can read about it in MSDN with examples about many controls and their messages/structure/notifications/styles/etc.. (sorry for long boring...)

2) Refer to this topic about #forceref.

3) If you'll see the example of _GUICtrlListView_Create() you'll see that in this select case $ilParam contains a pointer to $tagNMITEMACTIVATE, go to the help file, search for this struct and you'll see all the data that you need. For example, the index of the item in question is held by the Index field of the struct so it should be something like:

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo

;~  Local $tBuffer
    $hWndListView = $listview
    If Not IsHWnd($listview) Then $hWndListView = GUICtrlGetHandle($listview)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    
                    Local $iIndex = DllStructGetData($tInfo, "Index")
                    Local $sItemText = _GUICtrlListView_GetItemText($listview, $iIndex)
                    MsgBox(0x40, $iIndex, $sItemText)
            EndSwitch
    EndSwitch
EndFunc

Edit: Heh, thank you. :)

Edited by Authenticity
Link to comment
Share on other sites

Thanks! It works completely now, and I think I understand it.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

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