Sign in to follow this  
Followers 0
gseller

Double Click - Right Click In A List Example

21 posts in this topic

#1 ·  Posted (edited)

I made this example to have here when I need it and to share. I took some code from other examples and put together a new example of using doubleclick and rightclick in a list box in hopes someone might understand it better all layed out in one simple example. If you see your code hop in and post it as so. "It's All Good!"

double_click___right_click_in_a_list.au3

Only tested on Windows XP SP2... If your system is different please post is it works or not.

edited:Converted Code conform to Autoit build 3.2.10.0

#include <GuiConstants.au3>

;Global Const $WM_NOTIFY = 0x004E  ; removed to conform to Autoit build 3.2.10.0
Global $DoubleClicked   = False

GUICreate("Double Click/Right Click Demo", 400, 300)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

;create listboxt
$ListViewID = GuiCtrlCreateListView("List Column", 10, 20, 380, 250)


;******************Rightclick Menu*************
$menu1=GUICtrlCreateContextMenu ($ListViewID)
$delete=GUICtrlCreateMenuitem("Delete" , $menu1)
$play=GUICtrlCreateMenuitem("Play" , $menu1)
$info=GUICtrlCreateMenuitem("Info" ,$menu1)

;~~~~~~~~~~~~~~~Using Loop Method~~~~~~~~~~~~~~

;***************End Rightclick Menu************


For $i = 1 To 10
    GuiCtrlCreateListViewItem("Item " & $i, $ListViewID)
Next

GUISetState()

While 1
    $hGui = GUIGetMsg()
        Sleep(10)
            Switch $hGui
        Case $GUI_EVENT_CLOSE
            Exit
            EndSwitch
    If $DoubleClicked Then
        DoubleClickFunc()
        $DoubleClicked = False
    EndIf
    Select
    Case $hGui = $delete
    delete()
    Case $hGui = $play
    play()
    Case $hGui = $info
    info()
    EndSelect
WEnd

Func DoubleClickFunc()
    MsgBox(64, "OK ", "You Double Clicked: " & GUICtrlRead(GUICtrlRead($ListViewID)) & " ?")
EndFunc

Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $ListViewID And $code = -3 Then $DoubleClicked = True
    Return $GUI_RUNDEFMSG
EndFunc

Func play()
    MsgBox(64, "You Right Clicked ", "Play: " & GUICtrlRead(GUICtrlRead($ListViewID)) & " ?")
EndFunc

Func delete()
    MsgBox(64, "You Right Clicked ", "Delete: " & GUICtrlRead(GUICtrlRead($ListViewID)) & " ?")
EndFunc
   
Func info()
    MsgBox(64, "You Right Clicked ", "Info For: " & GUICtrlRead(GUICtrlRead($ListViewID)) & " ?")
EndFunc
Edited by gesller

Share this post


Link to post
Share on other sites



I made this example to have here when I need it and to share. I took some code from other examples and put together a new example of using doubleclick and rightclick in a list box in hopes someone might understand it better all layed out in one simple example. If you see your code hop in and post it as so. "It's All Good!"

Looks good :)

How come the doubleclick function is being called in the loop instead of in WM_Notify function after If $wParam = $ListViewID And $code = -3 Then ?

Is it just preference or are you trying to prevent an error or speed things up?


A decision is a powerful thing

Share this post


Link to post
Share on other sites

More of a preference. I have a searchable commandline script that will not work with OnEvent so I had to do everthing in loop. This also works better I think for ShellExecute.

Share this post


Link to post
Share on other sites

I made this example to have here when I need it and to share. I took some code from other examples and put together a new example of using doubleclick and rightclick in a list box in hopes someone might understand it better all layed out in one simple example. If you see your code hop in and post it as so. "It's All Good!"

Only tested on Windows XP SP2... If your system is different please post is it works or not.

I still use Win98 and it worked perfect for me. Thanks for sharing! :)

My AutoIT's:[topic="53958"]Personal Encyclopedia/Dictionary[/topic][topic="46311"]MS Access (Style) Database[/topic]"Some people are born on third base and go through life thinking they hit a triple."

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

How come the doubleclick function is being called in the loop instead of in WM_Notify function after If $wParam = $ListViewID And $code = -3 Then ?

This is the correct way, because if you call a function inside a WM_NOTIFY func (wich is registered func), then you mith expirience some problems...

From the help file:

Warning: blocking of running user functions which executes window messages with commands such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!

P.S

Good example gesller, and BTW, there is a diferents between a List Box and ListView :)

;create listboxt

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

This is the correct way, because if you call a function inside a WM_NOTIFY func (wich is registered func), then you mith expirience some problems...

From the help file:

P.S

Good example gesller, and BTW, there is a diferents between a List Box and ListView :)

WOW!!!! I never knew that!! Thank you for the explanation. I need to get busy on correcting this in my scripts and notify Eltorro in regards to his LV_EditInPlace

Thanks Gesller for the good example and the start of a powerful learning experience.

MSCreator, let me get this straight. I shouldn't call functions in Registered "functions" (eg. WM_Notify) or is this just an issue if the function called takes any "extended" period of time (eg. MsgBox() ) ?


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Thanks all.. I know it helped me a bunch.. Glad it helped others...

Share this post


Link to post
Share on other sites

I shouldn't call functions in Registered "functions" (eg. WM_Notify) or is this just an issue if the function called takes any "extended" period of time (eg. MsgBox() ) ?

Yes, if you pause the registered function (not return), then when user will execute some option that causing this event (a func) to be called again, you might get some stucks, or even hangs of your script :)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Updated Post # 1

Converted Code conform to Autoit build 3.2.10.0

Share this post


Link to post
Share on other sites

Hello mate:) Since you did the "Right-click function", Got any idea on how to when you click Delete that it removes the thing you selected from the list?:) Would be grateful for it

PS: Using GuiCtrlCreateList instead of GuiCtrlCreateListView:)


Never argue with an idiot, he will just bring you down to his own level and beat you with experience! :D

Share this post


Link to post
Share on other sites

Hello mate:) Since you did the "Right-click function", Got any idea on how to when you click Delete that it removes the thing you selected from the list? :D Would be grateful for it

PS: Using GuiCtrlCreateList instead of GuiCtrlCreateListView:)

Sure.. Use this

_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($Listview1))

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Sure.. Use this

_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($Listview1))oÝ÷ Ûú®¢×jx¬6§êÃjx­h¥{(Ú-j
(v'^i·¢ax^Ì­ç+y«^vë"ay»¢Ø§~éܶ*'ʬ¥vë趹CzW­z'íæî[bû§rب¬ºÇ¶+y«^¶¥Ëoì"µé¬!ü¨ºIèÂØ^צ³«yÊÞj׺ȧ»¢Ø§~éܶ*'¶§Ê¢é]v(ëax%GºÚ"µÍ[ÈÛXØ]ÛØÛXÚÙY

BSØØ[ ÌÍØÝQQÜ    ÌÍÚ[^HÑÕRPÝÝY]×ÑÙ]][PÛÝ[
    ÌÍÛÝY]ÊHHHÈÝLBBIÌÍØÝQHÑÕRPÝÝY]×ÑÙ]][T[J   ÌÍÛÝY]Ë    ÌÍÚ[^
BBRY    ÌÍØÝQ[ÕRPÝ[]J ÌÍØÝQ
BS^[[ÈÏOIÝÐÛXØ]ÛØÛXÚÙY
Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Sorry, didn't realize it was that big a difference..

Share this post


Link to post
Share on other sites

Hello.....

I use this to remove a single item from the list.

Func delete()
    Local $ret = MsgBox(48 + 1, "You Right Clicked ", "Delete: " & GUICtrlRead(GUICtrlRead($ListViewID)) & " ?", 10)
    ;# Remove a single item from the list
    If $ret = 1 Then GUICtrlDelete(GUICtrlRead($ListViewID))
EndFunc   ;==>deleteoÝ÷ ÚÚºÚ"µÍ[È[]J
BSØØ[ ÌÍÜ]HÙÐÞ

ÈK ][ÝÖ[ÝHYÚÛXÚÙY   ][ÝË  ][ÝÑ[]N   ][ÝÈ  [ÈÕRPÝXY
ÕRPÝXY
    ÌÍÓÝY]ÒQ
JH  [È ][ÝÈÉ][ÝËL
BNÈÈ[[ÝHHÚ[ÛH][HÛHHÝRY   ÌÍÜ]HH[ÛXØ]ÛØÛXÚÙY

B[[ÈÏOIÝÙ[]B[ÈÛXØ]ÛØÛXÚÙY

BSØØ[ ÌÍØÝQQÜ    ÌÍÚ[^HÑÕRPÝÝY]×ÑÙ]][PÛÝ[
    ÌÍÓÝY]ÒQ
HHHÈÝHBBIÌÍØÝQHÑÕRPÝÝY]×ÑÙ]][T[J   ÌÍÓÝY]ÒQ   ÌÍÚ[^
BBRY    ÌÍØÝQHÕRPÝXY
    ÌÍÓÝY]ÒQ
H[ÕRPÝ[]J ÌÍØÝQ
BS^[[ÈÏOIÝÐÛXØ]ÛØÛXÚÙY

Nice example, i needed yet. It gives me some good ideas for my actual project.

Share this post


Link to post
Share on other sites

Nice code !

Can anyone tell me how to detect when an item is selected (simply clicked or selected by using the arrows on the keyboard) - not doubleclicked ?

This would be great ! :)

Thanks,

Peter

Share this post


Link to post
Share on other sites

Can't remember who wrote it: You could add hotkeys for the keys part...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.10.0
 Author:         myName

 Script Function:
 Template AutoIt script.

#ce ----------------------------------------------------------------------------


#Include <GuiListView.au3>

Global $iDx = -1

$Gui = GUICreate("Listview Click",185,250,-1,-1)
$ListView = GUICtrlCreateListView("Col 1   |Col 2",0,0,500,500)
For $i = 0 To 8
    GUICtrlCreateListViewItem("Item " & $i & "|SubItem " & $i,$listview)
Next
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    If GUIGetMsg() = -3 Then Exit
    If $iDx <> -1 Then
        MsgBox(0, "", "Index: " & $iDx)
        $iDx = -1
    EndIf
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = GUICtrlGetHandle($ListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    If $hWndFrom = $hWndListView And $iCode = $NM_CLICK Then
        Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
        If DllStructGetData($tInfo, "Index") <> - 1 Then $iDx = DllStructGetData($tInfo, "Index")
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites

You made my day, gesller!

Just what I needed to get on with my script!! Thanks a lot!

Share this post


Link to post
Share on other sites

Chobby - Very Glad to be of assistance... :)

Share this post


Link to post
Share on other sites

Nice one gesller :)

Share this post


Link to post
Share on other sites

Thank You Sir!

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
Sign in to follow this  
Followers 0