zone97 Posted April 24, 2018 Share Posted April 24, 2018 Working on a app, that uses more than 1 listbox, using the listview function. I am also using the Func WM_NOTIFY, which works fine for the first listbox, but I cannot figure out how to make this function work with the other listboxes. This bit of code is required $hWndListView = GUICtrlGetHandle($List1) and is coded just for the first list. Need to be able to tell when an item from any of the 3 list boxes is clicked. Spoiler WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ] Link to comment Share on other sites More sharing options...
BrewManNH Posted April 24, 2018 Share Posted April 24, 2018 Post your code, we're not going to guess, and at least for me, not a mind reader. 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 GudeHow 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 More sharing options...
zone97 Posted April 24, 2018 Author Share Posted April 24, 2018 (edited) expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Run_Tidy=y #Tidy_Parameters=/tc 0 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Opt("GUIDataSeparatorChar", "¦") ;"|" is the default #include "include\Json.au3" #include <Array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <INet.au3> ; needed for get source (hmtl) #include <String.au3> ; needed for stringbetween #include <MsgBoxConstants.au3> #include <File.au3> #include <GuiListView.au3> $path = IniRead("data.ini", "settings", "path", "C:\Application_Path") $updates = IniReadSection("data.ini", "updates") $serv = IniReadSection("data.ini", "servers") Local $file = FileRead($path & "\data.json") Local $data = Json_Decode($file) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 565, 235, -1, -1) $List1 = GUICtrlCreateListView("Servers¦ID", 10, 26, 239, 110, $LVS_SINGLESEL + $LVS_EX_ONECLICKACTIVATE + $LVS_SORTASCENDING) $Label1 = GUICtrlCreateLabel("Servers", 13, 8, 40, 17) $List2 = GUICtrlCreateListView("Name¦ID", 256, 26, 129, 110) $Label2 = GUICtrlCreateLabel("Assigned updates", 260, 8, 176, 17) $List3 = GUICtrlCreateListView("Name¦ID", 424, 26, 129, 110) $Label3 = GUICtrlCreateLabel("Available updates", 428, 8, 176, 17) $Button1 = GUICtrlCreateButton("->", 392, 27, 25, 25) $Button2 = GUICtrlCreateButton("->>", 392, 83, 25, 25) $Button3 = GUICtrlCreateButton("<-", 392, 55, 25, 25) $Button4 = GUICtrlCreateButton("<<-", 392, 111, 25, 25) $Label4 = GUICtrlCreateLabel("Add a new update by id#", 396, 148, 159, 17) $Input1 = GUICtrlCreateInput("", 396, 169, 159, 21) $Button5 = GUICtrlCreateButton("Add", 394, 196, 75, 25) $Button6 = GUICtrlCreateButton("Remove", 481, 196, 75, 25) $Button7 = GUICtrlCreateButton("Launch", 40, 157, 175, 53) #EndRegion ### END Koda GUI section ### GUISetBkColor(0xC0C0C0, $Form1) GUICtrlSendMsg($List1, $LVM_SETCOLUMNWIDTH, 0, 400) GUICtrlSendMsg($List2, $LVM_SETCOLUMNWIDTH, 0, 150) GUICtrlSendMsg($List3, $LVM_SETCOLUMNWIDTH, 0, 150) GetServer() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func GetServer() Local $i = 0 While 1 ; list of all servers $name = json_get($data, '.servers[' & $i & '].name') $id = json_get($data, '.servers[' & $i & '].id') If @error Then ExitLoop GUICtrlCreateListViewItem($name & "¦" & $id, $List1) $i += 1 WEnd EndFunc ;==>GetServer Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo ; Local $tBuffer $hWndListView = GUICtrlGetHandle($List1) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) $sItem1 = GUICtrlRead(GUICtrlRead($List1)) $sItem1 = StringTrimRight($sItem1, 1) ; Will remove the pipe "|" from the end of the string $sItems = StringSplit($sItem1, "¦") $sName = $sItems[1] $sId = $sItems[2] ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sId = ' & $sId & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Edited April 24, 2018 by zone97 Spoiler WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ] Link to comment Share on other sites More sharing options...
BrewManNH Posted April 24, 2018 Share Posted April 24, 2018 See if this code gives you any ideas, I can't run this script to go any further with it due to not having the json UDF or the file(s) you're working with. Look for the added comments. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Run_Tidy=y #Tidy_Parameters=/tc 0 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Opt("GUIDataSeparatorChar", "¦") ;"|" is the default #include "include\Json.au3" #include <Array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <INet.au3> ; needed for get source (hmtl) #include <String.au3> ; needed for stringbetween #include <MsgBoxConstants.au3> #include <File.au3> #include <GuiListView.au3> $path = IniRead("data.ini", "settings", "path", "C:\Application_Path") $updates = IniReadSection("data.ini", "updates") $serv = IniReadSection("data.ini", "servers") Local $file = FileRead($path & "\data.json") Local $data = Json_Decode($file) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 565, 235, -1, -1) $List1 = GUICtrlCreateListView("Servers¦ID", 10, 26, 239, 110, $LVS_SINGLESEL + $LVS_EX_ONECLICKACTIVATE + $LVS_SORTASCENDING) $hList1 = GUICtrlGetHandle($List1) ; <<<<<<<<<<<<<<<<<<<<<<<<<< Get the handles of the individual listviews here. $Label1 = GUICtrlCreateLabel("Servers", 13, 8, 40, 17) $List2 = GUICtrlCreateListView("Name¦ID", 256, 26, 129, 110) $hList2 = GUICtrlGetHandle($List2) ;<<<<<<<<<<<<<<<<<<<<<<< $Label2 = GUICtrlCreateLabel("Assigned updates", 260, 8, 176, 17) $List3 = GUICtrlCreateListView("Name¦ID", 424, 26, 129, 110) $hList3 = GUICtrlGetHandle($List3) ; <<<<<<<<<<<<<<<<<<<<<<<< $Label3 = GUICtrlCreateLabel("Available updates", 428, 8, 176, 17) $Button1 = GUICtrlCreateButton("->", 392, 27, 25, 25) $Button2 = GUICtrlCreateButton("->>", 392, 83, 25, 25) $Button3 = GUICtrlCreateButton("<-", 392, 55, 25, 25) $Button4 = GUICtrlCreateButton("<<-", 392, 111, 25, 25) $Label4 = GUICtrlCreateLabel("Add a new update by id#", 396, 148, 159, 17) $Input1 = GUICtrlCreateInput("", 396, 169, 159, 21) $Button5 = GUICtrlCreateButton("Add", 394, 196, 75, 25) $Button6 = GUICtrlCreateButton("Remove", 481, 196, 75, 25) $Button7 = GUICtrlCreateButton("Launch", 40, 157, 175, 53) #EndRegion ### END Koda GUI section ### GUISetBkColor(0xC0C0C0, $Form1) GUICtrlSendMsg($List1, $LVM_SETCOLUMNWIDTH, 0, 400) GUICtrlSendMsg($List2, $LVM_SETCOLUMNWIDTH, 0, 150) GUICtrlSendMsg($List3, $LVM_SETCOLUMNWIDTH, 0, 150) GetServer() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func GetServer() Local $i = 0 While 1 ; list of all servers $name = json_get($data, '.servers[' & $i & '].name') $id = json_get($data, '.servers[' & $i & '].id') If @error Then ExitLoop GUICtrlCreateListViewItem($name & "¦" & $id, $List1) $i += 1 WEnd EndFunc ;==>GetServer Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; $hwnd is the handle of the control that triggered the message #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo ; Local $tBuffer $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWnd ; you can use the handle of the listviews here to tell you which control sent the message Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) $sItem1 = GUICtrlRead(GUICtrlRead($List1)) $sItem1 = StringTrimRight($sItem1, 1) ; Will remove the pipe "|" from the end of the string $sItems = StringSplit($sItem1, "¦") $sName = $sItems[1] $sId = $sItems[2] ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sId = ' & $sId & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY 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 GudeHow 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 More sharing options...
zone97 Posted April 24, 2018 Author Share Posted April 24, 2018 I applied your suggestions and no joy.. I did debug it to console to see what values each gave. $hWnd = 0x01E006D6 $hList1 = 0x00A90164 would appear that hWnd may be passing the control ID of the form not the active control being clicked? Spoiler WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ] Link to comment Share on other sites More sharing options...
BrewManNH Posted April 24, 2018 Share Posted April 24, 2018 Sorry, my mistake. The HWND is the window that sent the message, the $hWndFrom is the control that sent it. 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 GudeHow 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 More sharing options...
zone97 Posted April 24, 2018 Author Share Posted April 24, 2018 Switch $hWndFrom Case $hWndFrom Switch $iCode doing this did the trick.. Thank you. Spoiler WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ] Link to comment Share on other sites More sharing options...
BrewManNH Posted April 24, 2018 Share Posted April 24, 2018 You should use the handles of the listviews to see which one triggered the message. 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 GudeHow 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now