mattw112 Posted September 2, 2010 Share Posted September 2, 2010 (edited) I want to add a button to a Windows application that simply checks some boxes when pressed. I got the code working that checks the boxes. Now the buttons... I tried Anygui but couldn't get it working. But using _GUICtrlButton_Create I added the buttons I wanted. ok so now in my While loop the GUIGetMsg doesn't seem to be picking up the event of my button being pressed? I've put in some msgbox's after each GUIGetMsg and only get 0's. Event Mode is not enabled... I'm wondering if maybe because this isn't a AutoIt created GUI (just buttons) if my script can get Events back from those buttons being pressed? Or should it be able to? Thanks, Terry Edited September 2, 2010 by mattw112 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 2, 2010 Moderators Share Posted September 2, 2010 mattw112, Take a look at this thread from a while ago where I showed how to do read added menu items and buttons in another GUI. 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...
mattw112 Posted September 2, 2010 Author Share Posted September 2, 2010 (edited) So I took a look, very interesting. I copied your code in one of the examples and have tried to modify it to work with what I'm trying to do. It creates the buttons where I want them, but when I press the buttons nothing happens and I don't get a msgbox? expandcollapse popup#include <WindowsConstants.au3> #include <SendMessage.au3> #include <GuiMenu.au3> #include <GuiListView.au3> #include <GuiButton.au3> #include <GuiConstants.au3> ; Windows User Messages Global Const $UM_ADDMESSAGE = $WM_USER + 0x100, $BS_PUSHBUTTON = 0x0 Global $hWndTarget, $sButtonPressed = "" Global $aCmdID_Button[2][2] = [ _ ["Button 1", 0x3000], _ ["Button 2", 0x3001], _ ; Insert button into SUM _InsertButton() ; Gather information... $iPIDTarget = WinGetProcess($hWndTarget) $iThreadIdTarget = _WinAPI_GetWindowThreadProcessId($hWndTarget, $iPIDTarget) ; Install Filter(s) FileInstall(".\Files\Hook.dll", @SystemDir & "\Hook.dll", 0) $hDll_hook = DllOpen("hook.dll") ;helper dll DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_CALLWNDPROC, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_GETMESSAGE, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok ; Register WM_COMMAND $hWndLocal = GUICreate("") ;Needed to receive Messages _SendMessage($hWndTarget, $UM_ADDMESSAGE, $WM_COMMAND, $hWndLocal) GUIRegisterMsg($WM_COMMAND, "_Filter") ; Keep running while target exists While WinExists($hWndTarget) If $sButtonPressed <> "" Then MsgBox(0, "TEST", "You clicked " & $sButtonPressed) $sButtonPressed = "" EndIf Sleep(10) WEnd ; Uninstall Filter DllCall($hDll_hook, "int", "UnInstallFilterDLL", "long", $iThreadIdTarget, "hwnd", $hWndTarget, "hwnd", $hWndLocal); 0 = ok DllClose($hDll_hook) Exit(0) ; Process Callback Func _Filter($hGUI, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_COMMAND $iCmdID = _WinAPI_LoWord($wParam) For $i = 0 To 2 If $aCmdID_Button[$i][1] = $iCmdID Then $sButtonPressed = $aCmdID_Button[$i][0] EndIf Next EndSwitch EndFunc ;==>_Filter Func _InsertButton() ; Look for SUM Window WinWait("Configuration Manager - Available Software Updates", "&Schedule Installation") $hWndTarget = WinGetHandle("Configuration Manager - Available Software Updates", "&Schedule Installation") ; Get current Button Positions $ButtonPos = ControlGetPos("Configuration Manager - Available Software Updates", "&Schedule Installation", "[CLASS:Button; INSTANCE:3]") $X = $ButtonPos[0] - 130 $Y = $ButtonPos[1] ; Create Button on Form $btnUnchecked = _GUICtrlButton_Create($hWndTarget, "Uncheck All", $X, $Y, 60, 24) $btnChecked = _GUICtrlButton_Create($hWndTarget, "Check All", $X + 65, $Y, 60, 24) EndFunc Edited September 3, 2010 by mattw112 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 3, 2010 Moderators Share Posted September 3, 2010 mattw112,If you look at the code in the thread I linked to, I used _WinAPI_CreateWindowEx to create the buttons, not _GUICtrlButton_Create. This allows the setting of the CmdID value which is what you need to ID the button press.Try replacing your button creation code with this: ; Create Buttons on Form Local $hButton For $i = 0 To UBound($aCmdID_Button) - 1 $hButton = _WinAPI_CreateWindowEx(0, "Button", $aCmdID_Button[$i][0], BitOR($BS_PUSHBUTTON, $WS_CHILD, $WS_VISIBLE), _ $X, $Y, 60, 24, $hWndTarget, $aCmdID_Button[$i][1]) _SendMessage($hButton, $__BUTTONCONSTANT_WM_SETFONT, _WinAPI_GetStockObject($__BUTTONCONSTANT_DEFAULT_GUI_FONT), True) $X += 65 NextYou will also need to amend the CmdID array to read:Global $aCmdID_Button[2][2] = [["Uncheck All", 0x3000], ["Check All", 0x3001]]You are currently missing a closing "]" by the way. Try that and see how you get on. 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...
mattw112 Posted September 3, 2010 Author Share Posted September 3, 2010 I made the suggestions changes shown below and it creates the buttons, but when I press either of them I get an error: "Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded" As far as I can tell it looks fine the way you sent it to me though? expandcollapse popup#include <WindowsConstants.au3> #include <SendMessage.au3> #include <GuiMenu.au3> #include <GuiListView.au3> #include <GuiButton.au3> #include <GuiConstants.au3> ; Windows User Messages Global Const $UM_ADDMESSAGE = $WM_USER + 0x100, $BS_PUSHBUTTON = 0x0 Global $hWndTarget, $sButtonPressed = "" Global $aCmdID_Button[2][2] = [["Uncheck All", 0x3000], ["Check All", 0x3001]] ; Insert Buttons into SUM _InsertButton() ; Gather information... $iPIDTarget = WinGetProcess($hWndTarget) $iThreadIdTarget = _WinAPI_GetWindowThreadProcessId($hWndTarget, $iPIDTarget) ; Install Filter(s) FileInstall(".\Files\Hook.dll", @SystemDir & "\Hook.dll", 0) $hDll_hook = DllOpen("hook.dll") ;helper dll DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_CALLWNDPROC, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok DllCall($hDll_hook, "int", "InstallFilterDLL", "long", $WH_GETMESSAGE, "long", $iThreadIdTarget, "hwnd", $hWndTarget) ; 0 = Ok ; Register WM_COMMAND $hWndLocal = GUICreate("") ;Needed to receive Messages _SendMessage($hWndTarget, $UM_ADDMESSAGE, $WM_COMMAND, $hWndLocal) GUIRegisterMsg($WM_COMMAND, "_Filter") ; Keep running while target exists While WinExists($hWndTarget) If $sButtonPressed <> "" Then MsgBox(0, "TEST", "You clicked " & $sButtonPressed) $sButtonPressed = "" EndIf Sleep(10) WEnd ; Uninstall Filter DllCall($hDll_hook, "int", "UnInstallFilterDLL", "long", $iThreadIdTarget, "hwnd", $hWndTarget, "hwnd", $hWndLocal); 0 = ok DllClose($hDll_hook) Exit(0) ; Process Callback Func _Filter($hGUI, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_COMMAND $iCmdID = _WinAPI_LoWord($wParam) For $i = 0 To 2 If $aCmdID_Button[$i][1] = $iCmdID Then $sButtonPressed = $aCmdID_Button[$i][0] EndIf Next EndSwitch EndFunc ;==>_Filter Func _InsertButton() ; Look for SUM Window WinWait("Configuration Manager - Available Software Updates", "&Schedule Installation") $hWndTarget = WinGetHandle("Configuration Manager - Available Software Updates", "&Schedule Installation") ; Get current Button Positions $ButtonPos = ControlGetPos("Configuration Manager - Available Software Updates", "&Schedule Installation", "[CLASS:Button; INSTANCE:3]") $X = $ButtonPos[0] - 130 $Y = $ButtonPos[1] ; Create Button on Form Local $hButton For $i = 0 To UBound($aCmdID_Button) - 1 $hButton = _WinAPI_CreateWindowEx(0, "Button", $aCmdID_Button[$i][0], BitOR($BS_PUSHBUTTON, $WS_CHILD, $WS_VISIBLE), _ $X, $Y, 60, 24, $hWndTarget, $aCmdID_Button[$i][1]) _SendMessage($hButton, $__BUTTONCONSTANT_WM_SETFONT, _WinAPI_GetStockObject($__BUTTONCONSTANT_DEFAULT_GUI_FONT), True) $X += 65 Next EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 3, 2010 Moderators Share Posted September 3, 2010 mattw112,If you look at the line number that SciTE gives you for the error, you see that it is in the _Filter function where the count was not set correctly.Change it to this:; Process Callback Func _Filter($hGUI, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_COMMAND $iCmdID = _WinAPI_LoWord($wParam) For $i = 0 To UBound($aCmdID_Button) - 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If $aCmdID_Button[$i][1] = $iCmdID Then $sButtonPressed = $aCmdID_Button[$i][0] EndIf Next EndSwitch EndFunc ;==>_FilterLet me know how you get on this time. 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...
mattw112 Posted September 3, 2010 Author Share Posted September 3, 2010 Perfect! Thanks. The line number was from the compiled version which was like 8983 or some high number like that... Thanks for your help. Terry Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 3, 2010 Moderators Share Posted September 3, 2010 mattw112, Glad we got it working. 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...
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