Jump to content

double click in listview


JAFN
 Share

Recommended Posts

Every time the answer to a problem involves WM_Notify it does not work for me.

I figure there is something I am completely misunderstanding.

So I have taken yesterday's answer on making a double click for a listview and built the needed support to make it run.

Double click, no beep.

#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

$GUIid = GUICreate("TestWindow", 400, 700, 20, 100)
$LVid = GUICtrlCreateListView("Title|Price|Test|Genre", 10, 40, 380,640, $LVS_SINGLESEL )
$hListView = GUICtrlGetHandle($LVid)

Dim $Data[30][4]
for $a=0 to 29
    for $b=0 to 3
        $data[$a][$b] = random(0,400)
    Next
Next
_GUICtrlListView_AddArray($LVid, $Data)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1

    ; Look for GUI events
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            exit
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ; Windows message function used to call the double click function
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $lParam
    $hWndListView = $LVid
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_ITEMACTIVATE
                    Local $nmia = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    Local $I = DllStructGetData($nmia, "Index")
                    ;~ Do something at this point with the double click
            Beep(900,300(
            EndSwitch
    EndSwitch
    Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

What is my confusion?

Edited by JAFN
[size="2"]The second mouse gets the cheese[/size]
Link to comment
Share on other sites

Change the line marked below with the "<<<<<<<<<<<<<<<<<"

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ; Windows message function used to call the double click function
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $lParam
    $hWndListView = $hListView ;<<<<<<<<<<<<<<<<<
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

Your code was taking the $LVid variable and assigning it to the $hWndListView variable, but you did the check in the next line to the listview's handle so $hWndListView would never get set to the handle of the listview, only the ControlID.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Change the line marked below with the "<<<<<<<<<<<<<<<<<"

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ; Windows message function used to call the double click function
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $lParam
    $hWndListView = $hListView ;<<<<<<<<<<<<<<<<<
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

Your code was taking the $LVid variable and assigning it to the $hWndListView variable, but you did the check in the next line to the listview's handle so $hWndListView would never get set to the handle of the listview, only the ControlID.

You got my hopes up. But I made the change and still no double click action. :unsure:
[size="2"]The second mouse gets the cheese[/size]
Link to comment
Share on other sites

Sorry, I forgot there were two other errors in the script, the first is in this line "GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")", you need to change the function name, either in this line or the function itself, as you forgot the leading underscore on _WM_NOTIFY here. Also, you have a backwards parentheses in your beep command so. Both of these should have shown up in Scite if you are running it from there because they're both obvious errors to Au3Check.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Sorry, I forgot there were two other errors in the script, the first is in this line "GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")", you need to change the function name, either in this line or the function itself, as you forgot the leading underscore on _WM_NOTIFY here. Also, you have a backwards parentheses in your beep command so. Both of these should have shown up in Scite if you are running it from there because they're both obvious errors to Au3Check.

It is scary that I did not notice the beep error given how much I looked at this script :|

But it worked!!!!!!1

Is there something analogous to WM_notify for Dummies? I'd really like to understand the workings as it is all cut and paste beyond the header.

And thanks again.

Now have to place it back into my code without breaking it :unsure:

[size="2"]The second mouse gets the cheese[/size]
Link to comment
Share on other sites

Unbelievable, I cut and paste the working routine and line into my code.

The result:

---------------------------

AutoIt Error

---------------------------

Line 130 (File "C:\Users\Judith\AutoItFiles\Jaguar\JaGuaR.au3"):

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUIRegisterMsg(^ ERROR

Error: Variable used without being declared.

---------------------------

OK

---------------------------

Hopefully the last I bother you folks with this problem.

[size="2"]The second mouse gets the cheese[/size]
Link to comment
Share on other sites

Hey! Got there on my own. easy once I( thought about it.

Thanks

And other than hopefully pointers to a remedial tutorial for $WM_Notify. I consider this thread over.

[size="2"]The second mouse gets the cheese[/size]
Link to comment
Share on other sites

Hey! Got there on my own. easy once I( thought about it.

Thanks

And other than hopefully pointers to a remedial tutorial for $WM_Notify. I consider this thread over.

Take a look at the example script for _GUICtrlListView_Create in the help file, you'll notice there's about a dozen different messages you can import into a script for ListViews. That's where I find most of the code I use for windows messages. :unsure:

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 1 month later...

You need edit some line under:

Func _WM_NOTIFY >>> Func WM_NOTIFY

If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

>>>>>>>

If Not IsHWnd($LVid) Then $hWndListView = GUICtrlGetHandle($LVid)

Beep(900,300( >>>>> Beep(900,300)

I tested your code work

Edited by chandoi
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...