tommeke228 Posted October 23, 2010 Share Posted October 23, 2010 I want to know the code to let my program react on a double mouse click on an item in the listbox and uh the code for if you click right that a menu shows hmm that should be all ^^ hope somebody can help me xD Link to comment Share on other sites More sharing options...
Tvern Posted October 23, 2010 Share Posted October 23, 2010 Study this a bit: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <GuiListView.au3> GUICreate("ListView Test",800,600) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;this allows you to capture all window messages. Global $GuiCtrlListView = GUICtrlCreateListView("Column0|Column1|Column2",10,10,700,500) Global $hListView = GUICtrlGetHandle($GuiCtrlListView) ;we'll need the handle later. For $i = 0 To 99 GUICtrlCreateListViewItem("Item0." & $i & "|Item1." & $i & "|Item2." & $i,$GuiCtrlListView) Next GUISetState() While GUIGetMsg() <> -3 WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ;there are a lot of window messages and they fire all the time. ;We'll need to filter the ones we want. Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) ;this should give us the handle of the control that triggered the event. $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView ;Only react to messages from the listview Switch $iCode ;check the type of message Case $NM_DBLCLK ;double click message $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) Case $NM_RCLICK ;right click message $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) EndSwitch EndSwitch ; if you don't return $GUI_RUNDEFMSG, or 0 the rest of the messages won't be handles as they should. Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) EndFunc ;==>_DebugPrint Func _Exit() Exit EndFunc Looks like some of that isn't my code (at least _DebugPrint doesn't look like something I'd write), but I found it in another example script in my test folder, so I don't know the author. Thanks though! This is just the code that captures the events. When you write the functions to handle them, keep in mind that WM_NOTIFY is supposed to return quickly, so if you plan on triggering a time-consuming function, set a flag in WM_NOTIFY that triggers the function after WM_NOTIFY returns. Link to comment Share on other sites More sharing options...
guinness Posted October 23, 2010 Share Posted October 23, 2010 _DebugPrint() is from the HelpFile UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
tommeke228 Posted October 23, 2010 Author Share Posted October 23, 2010 (edited) thx i will try this ^^ edit works with a listview but not on my listbox maybe you got it for listbox or else i need to change alot of code for just the listview seeya thx Edited October 23, 2010 by tommeke228 Link to comment Share on other sites More sharing options...
Tvern Posted October 24, 2010 Share Posted October 24, 2010 (edited) _DebugPrint() is from the HelpFile Well then the helpfile deserves credit! works with a listview but not on my listbox I might have gotten a little ListView obsessed the last few days because of a script I'm making. I could have sworn you asked for a ListView.I have tried adjusting the code to work for a listbox instead, but it doesn't seem to trigger any WM_NOTIFY messages at all. There are some message codes specified in ListBoxConstants.au3 though. I'll try a few things if and when I have some spare time, but I'm pretty much stabbing in the dark.Edit:Actually the example in the helpfile shows an example capturing WM_COMMAND which triggers when an item is double clicked, but it appears the wParam and lParam don't hold indformation about the item clicked. I think I'm out of my league. Edited October 24, 2010 by Tvern Link to comment Share on other sites More sharing options...
taietel Posted October 24, 2010 Share Posted October 24, 2010 Try this: expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> GUICreate("Form1", 200, 350) $hListBox = GUICtrlCreateList("", 5, 5, 190, 340) Local $t For $i=1 To 10 $t &="Item no."&$i&"|" Next GUICtrlSetData(-1,$t) $mnuLBContext = GUICtrlCreateContextMenu($hListBox) GUICtrlCreateMenuItem("MenuItem3", $mnuLBContext) GUICtrlCreateMenuItem("MenuItem2", $mnuLBContext) GUICtrlCreateMenuItem("MenuItem1", $mnuLBContext) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState(@SW_SHOW) While 1 Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox) $hWndFrom = $ilParam $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word $iCode = BitShift($iwParam, 16) ; Hi Word Switch $hWndFrom Case $hListBox, $hWndListBox Switch $iCode Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box ConsoleWrite("Item "& _GUICtrlListBox_GetCurSel($hListBox)&@CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
tommeke228 Posted October 24, 2010 Author Share Posted October 24, 2010 (edited) omg thx it works but uhm it only works for 1 listbox not 2 maybe you know how to fix it i don't have a clue xD Tvern thx for your help also ^^ Case $list1 GUIRegisterMsg($WM_COMMAND, "WM_COMMAND1") Case $list2 GUIRegisterMsg($WM_COMMAND, "WM_COMMAND2") expandcollapse popupFunc WM_COMMAND1($hWnd1, $iMsg1, $iwParam1, $ilParam1) #forceref $hWnd1, $iMsg1 Local $hWndFrom1, $iIDFrom1, $iCode1, $hWndListBox1 If Not IsHWnd($list1) Then $hWndListBox1 = GUICtrlGetHandle($list1) $hWndFrom1 = $ilParam1 $iIDFrom1 = BitAND($iwParam1, 0xFFFF) ; Low Word $iCode1 = BitShift($iwParam1, 16) ; Hi Word Switch $hWndFrom1 Case $list1, $hWndListBox1 Switch $iCode1 Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box $id = WinGetState(_GUICtrlListBox_GetText($list1, _GUICtrlListBox_GetCurSel($list1))) If $id = "5" Or $id = "37" Then WinSetState(_GUICtrlListBox_GetText($list1, _GUICtrlListBox_GetCurSel($list1)), "", @SW_SHOW) ElseIf $id = "7" Or $id = "39" Then WinSetState(_GUICtrlListBox_GetText($list1, _GUICtrlListBox_GetCurSel($list1)), "", @SW_HIDE) Else WinSetState(_GUICtrlListBox_GetText($list1, _GUICtrlListBox_GetCurSel($list1)), "", @SW_SHOW) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND1 Func WM_COMMAND2($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox If Not IsHWnd($list2) Then $hWndListBox = GUICtrlGetHandle($list2) $hWndFrom = $ilParam $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word $iCode = BitShift($iwParam, 16) ; Hi Word Switch $hWndFrom Case $list2, $hWndListBox Switch $iCode Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box $id = WinGetState(_GUICtrlListBox_GetText($list2, _GUICtrlListBox_GetCurSel($list2))) If $id = "5" Or $id = "37" Then WinSetState(_GUICtrlListBox_GetText($list2, _GUICtrlListBox_GetCurSel($list2)), "", @SW_SHOW) ElseIf $id = "7" Or $id = "39" Then WinSetState(_GUICtrlListBox_GetText($list2, _GUICtrlListBox_GetCurSel($list2)), "", @SW_HIDE) Else WinSetState(_GUICtrlListBox_GetText($list2, _GUICtrlListBox_GetCurSel($list2)), "", @SW_SHOW) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND2 thankyou guys Edited October 24, 2010 by tommeke228 Link to comment Share on other sites More sharing options...
Tvern Posted October 24, 2010 Share Posted October 24, 2010 You register the WM_COMMAND message for all controls in the GUI, so you only have to register it once, after which you can check in the function what listbox triggered the event. ($hWndFrom contains the handle to the control triggering the event) Link to comment Share on other sites More sharing options...
Developers Jos Posted June 7, 2023 Developers Share Posted June 7, 2023 Are you trying to answer this 13 years old thread or are you misusing it to post your question? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
littlebigman Posted June 8, 2023 Share Posted June 8, 2023 I generally don't like creating a new thread when a similar problem has been asked before — and when I do create a new thread, some people complain just as well. Link to comment Share on other sites More sharing options...
Developers Jos Posted June 9, 2023 Developers Share Posted June 9, 2023 (edited) Ok then I won't complain anymore and simply lock it. ... but I did create a new topic for you this time! Edited June 9, 2023 by Jos littlebigman 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts