Jump to content

GUIGetMsg not working?


mattw112
 Share

Recommended Posts

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 by mattw112
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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?

#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 by mattw112
Link to comment
Share on other sites

  • Moderators

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
Next

You 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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?

#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

  • Moderators

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   ;==>_Filter

Let me know how you get on this time. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

mattw112,

Glad we got it working. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...