CraigA Posted December 6, 2007 Share Posted December 6, 2007 How can a script intercept (and then pass on) a LB_ADDSTRING message that is sent to a listbox on a AutoIt GUI. The script just needs to be notified when the messages arrives and it will get the string that was placed in the listbox. I am pretty sure both of the following function calls should generate this message: ControlCommand($ScriptName, "", "[CLASS:ListBox; INSTANCE:1]", "AddString", "1") or _GUICtrlListBox_AddString($handle, "1") I have found a few examples that handle listbox notification messages, send a LB_ADDSTRING message but none that process LB_ADDSTRING. In C:\Program Files\AutoIt3\Include\ListBoxConstants.au3: Global Const $LB_ADDSTRING = 0x0180 A "click" of the listbox or another button will not work since the GUI is hidden. With Opt("GUIOnEventMode", 1), a loop to check the number of items in a list box is not possible since the script calls WinWaitActive() within a loop. And besides, it would be cool to learn how to intercept this message. Link to comment Share on other sites More sharing options...
Zedna Posted December 6, 2007 Share Posted December 6, 2007 (edited) I haven't working solution but here are my quick attempts, so you can get it as start point to your observations: expandcollapse popup#include <GUIConstants.au3> #include <GuiList.au3> ;~ Global Const $LB_ADDSTRING = 0x0180 Global Const $WM_NOTIFY = 0x004E Global Const $WM_COMMAND = 0x0111 $GUI = GuiCreate("List",270,400,-1,-1) $list = GUICtrlCreateList("", 45, 50, 200, 310) GUISetState(@SW_SHOW,$gui) GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") GUIRegisterMsg($LB_ADDSTRING, "MY_WM_ADDSTRING") ;~ GUIRegisterMsg ($WM_COMMAND, "MY_WM_COMMAND") ;~ _GUICtrlListBox_AddString($list, "1") GUICtrlSendMsg($List, $LB_ADDSTRING, 0, '123') While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case Else EndSelect WEnd Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) ;NMHDR (hwndFrom, idFrom, code) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $list Select ;~ Case $event = $LB_ADDSTRING Case $MsgID = $LB_ADDSTRING ConsoleWrite('123') EndSelect EndSelect EndFunc Func MY_WM_ADDSTRING($hWnd, $Msg, $wParam, $lParam) ConsoleWrite('123') EndFunc Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam) $nNotifyCode = _HiWord($wParam) $nID = _LoWord($wParam) $hCtrl = $lParam If $nID = $list Then Switch $nNotifyCode Case $LB_ADDSTRING ConsoleWrite('123') EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc Func _HiWord($x) Return BitShift($x, 16) EndFunc Func _LoWord($x) Return BitAND($x, 0xFFFF) EndFunc Edited December 6, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
CraigA Posted December 12, 2007 Author Share Posted December 12, 2007 Zedna, thanks so much for your reply. I gave it a go, making a few changes to your code, and testing with a visible window. I used another script, that added a string to the listBox with: $rc = ControlCommand("List", "", "[CLASS:ListBox; INSTANCE:1]", "AddString", "777") Adding a string fired no events that were detected by any of the three event procs. MY_WM_COMMAND did capture events related to the GUI gaining or losing focus as shown by this output: ==> my_wm_command:: ==> my_wm_command:: our $list. ==> my_wm_command:: our $list, Case Else, $nNotifyCode: 5 ==> my_wm_command:: ==> my_wm_command:: our $list. ==> my_wm_command:: our $list, Case Else, $nNotifyCode: 4 *** Some Code Not Shown *** expandcollapse popup#include <GUIConstants.au3> #include <GuiListBox.au3> #include <ListBoxConstants.au3> ;~ Global Const $LB_ADDSTRING = 0x0180 ;Global Const $WM_NOTIFY = 0x004E ;Global Const $WM_COMMAND = 0x0111 $GUI = GuiCreate("List",270,400,-1,-1) $list = GUICtrlCreateList("", 45, 50, 200, 310) GUISetState(@SW_SHOW,$gui) GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") GUIRegisterMsg($LB_ADDSTRING, "MY_WM_ADDSTRING") GUIRegisterMsg ($WM_COMMAND, "MY_WM_COMMAND") ;~ _GUICtrlListBox_AddString($list, "1") GUICtrlSendMsg($List, $LB_ADDSTRING, 0, '123') While 1 $msg = GuiGetMsg() Select Case $msg = 0 Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = 110 Case Else ConsoleWrite(@LF + "msgLoop:: Case Else, $msg: " & $msg) EndSelect WEnd Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam) $nNotifyCode = _HiWord($wParam) $nID = _LoWord($wParam) $hCtrl = $lParam ConsoleWrite(@LF & "==> my_wm_command::") If $nID = $list Then ConsoleWrite(@LF & "==> my_wm_command:: our $list.") Switch $nNotifyCode Case $LB_ADDSTRING MsgBox(0,"","my_wm_command:: case $lb_addstring") ConsoleWrite('123') Case Else ConsoleWrite(@LF & "==> my_wm_command:: our $list, Case Else, $nNotifyCode: " & $nNotifyCode & @LF) EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc Perhaps I can find a solution using the NamedPipes Management UDF's. 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