nullschritt Posted October 24, 2013 Share Posted October 24, 2013 (edited) Thanks! Hello all, I am trying to make my WM_NOTIFY function recognize when a listbox is clicked, however, I can't seem to get any events from the list box. Below is my code: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $tagNMHDR = "struct; hwnd hWndFrom;uint_ptr IDFrom;INT Code; endstruct" Global Const $tagNMITEMACTIVATE = $tagNMHDR & ";int Index;int SubItem;int NewState;int OldState;" & _ "int Changed;int X;int Y;int lParam;int KeyFlags" maingui() while 1 $msg = GUIGetMsg() if $msg = $GUI_EVENT_CLOSE then Exit EndIf sleep(5) WEnd func maingui() global $hgui = guicreate("Test", 200, 500) Global $convolist = GUICtrlCreateList("Test", 14, 10, 160, 475) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() endfunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo ;~ Local $tBuffer $hWndList = $convolist If Not IsHWnd($convolist) Then $hWndList = GUICtrlGetHandle($convolist) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndList Switch $iCode Case $NM_CLICK $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) ConsoleWrite("Click Detected"&@CRLF) endswitch endswitch endfunc Can anyone see what I am doing wrong? Edited October 24, 2013 by nullschritt Link to comment Share on other sites More sharing options...
Mharsy Posted October 24, 2013 Share Posted October 24, 2013 Check >this. It should inspire you. Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted October 24, 2013 Moderators Solution Share Posted October 24, 2013 nullschritt,Listboxes are funny beasts and you intercept what messages they do send via WM_COMMAND: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Global $convolist ; Best not to declare Global variables in functions maingui() While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit EndIf ; Sleep(5) ; Not needed - GUIGetMSg has a built-in Sleep WEnd Func maingui() $hgui = GUICreate("Test", 200, 500) $convolist = GUICtrlCreateList("Test", 14, 10, 160, 475) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUISetState() EndFunc ;==>maingui Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg ; Check it is the correct list If $lParam = GUICtrlGetHandle($convolist) Then ; If item selected If BitShift($wParam, 16) = $LBN_SELCHANGE Then ConsoleWrite("Click Detected" & @CRLF) EndIf EndIf EndFunc ;==>_WM_COMMANDM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 24, 2013 Moderators Share Posted October 24, 2013 Mharsy,The code to which you linked deals with ListViews - they are very different to ListBoxes which is what we are dealing with here. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mharsy Posted October 24, 2013 Share Posted October 24, 2013 Melba23, I didn't say that they are the same. I only linked to example with working input events. But point for you! Link to comment Share on other sites More sharing options...
kylomas Posted October 24, 2013 Share Posted October 24, 2013 (edited) nullscritt, To expand on M23's example...The following retrieves whatever row is selected from the appropriate listbox. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Global $lb1,$lb2 maingui() While 1 switch guigetmsg() case $GUI_EVENT_CLOSE Exit endswitch WEnd Func maingui() $hgui = GUICreate("Test", 220, 500) $lb1 = GUICtrlCreateList('', 10, 10, 100, 475) $lb2 = GUICtrlCreateList('', 110, 10, 100, 475) ; populate the listboxes for $0 = 1 to 2 for $1 = 1 to 15 guictrlsetdata(eval('lb' & $0),'LB # ' & $0 & ' Item - ' & stringformat('%02i',$1)) next next GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUISetState() EndFunc ;==>maingui Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg switch $lParam case guictrlgethandle($lb1) switch BitShift($wParam, 16) case $LBN_SELCHANGE ConsoleWrite('Item = ' & guictrlread($lb1) & ' selected' & @CRLF) EndSwitch case guictrlgethandle($lb2) switch BitShift($wParam, 16) case $LBN_SELCHANGE ConsoleWrite('Item = ' & guictrlread($lb2) & ' selected' & @CRLF) EndSwitch endswitch EndFunc ;==>_WM_COMMAND Also, there is a rich compliment of Listbox UDF's you may be interested in (_guictrllistbox_*). kylomas edit additional info This piece of code by AZJIO shows how to manipulate/communicate with a listbox thorough messages (sorry, could'nt find the thread). expandcollapse popup#include <ListBoxConstants.au3> #include <GUIConstantsEx.au3> Local $Message = "The following buttons are pressed" Local $hGUI, $add, $clear, $mylist, $msg, $index, $read, $setsel, $count, $select, $find_string, $del_item, $insert, $color, $tmp $hGUI = GUICreate("GUI ? ????????? ?????? - list") ; ??????? ???? ? ?????? ?????? $read = GUICtrlCreateButton("Item", 40, 30, 121, 25) $index = GUICtrlCreateButton("Index of the selected", 40, 60, 121, 25) $setsel = GUICtrlCreateButton("Select item 4", 40, 90, 121, 25) $select = GUICtrlCreateButton("Select ""Item1""", 40, 120, 121, 25) $find_string = GUICtrlCreateButton("Find the string Item 3", 40, 150, 121, 25) $del_item = GUICtrlCreateButton("Delete row 3", 40, 180, 121, 25) $count = GUICtrlCreateButton("The number of items", 40, 210, 121, 25) $add = GUICtrlCreateButton("Add item", 40, 240, 121, 25) $insert = GUICtrlCreateButton("Insert in position", 40, 270, 121, 25) $color = GUICtrlCreateButton("Change the color", 40, 300, 121, 25) $clear = GUICtrlCreateButton("Clear list", 40, 330, 121, 25) $mylist = GUICtrlCreateList("Zero based index of the item", 180, 30, 190, 100, $GUI_SS_DEFAULT_LIST + $LBS_NOINTEGRALHEIGHT) ; style LBS_NOINTEGRALHEIGHT ; style $WS_BORDER+$WS_VSCROLL+$LBS_NOINTEGRALHEIGHT ; GUICtrlSetLimit(-1, 200) GUICtrlSetData(-1, $Message) GUICtrlSetData(-1, 'Item 1|Item 2|Item 3|Item', 'Item 2') GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $add GUICtrlSetData($mylist, "Clicked ""add""|") Case $clear GUICtrlSetData($mylist, "") Case $index $tmp = GUICtrlSendMsg($mylist, $LB_GETCURSEL, 0, 0) MsgBox(4096, 'The text of the selected item', $tmp, 0, $hGUI) Case $read $tmp = GUICtrlRead($mylist) MsgBox(4096, 'The text of the selected item in the list', $tmp, 0, $hGUI) Case $setsel GUICtrlSendMsg($mylist, $LB_SETCURSEL, 4, 0) Case $count $tmp = GUICtrlSendMsg($mylist, $LB_GETCOUNT, 0, 0) MsgBox(4096, 'The number of items in the list', $tmp, 0, $hGUI) Case $select GUICtrlSendMsg($mylist, $LB_SELECTSTRING, 0, 'Item 1') Case $find_string $tmp = GUICtrlSendMsg($mylist, $LB_FINDSTRINGEXACT, 0, 'Item 3') MsgBox(4096, 'Found the exact string in the list: Item 3', 'Index = ' & $tmp, 0, $hGUI) Case $del_item $tmp = GUICtrlSendMsg($mylist, $LB_DELETESTRING, 3, 0) Case $insert GUICtrlSendMsg($mylist, $LB_INSERTSTRING, 3, 'Inserted at position 3') Case $color GUICtrlSetBkColor($mylist, 0xCCCC99) EndSwitch WEnd Edited October 24, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
nullschritt Posted October 25, 2013 Author Share Posted October 25, 2013 Thanks for the help guys! 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