Sign in to follow this  
Followers 0
youngxx

GUIOnEventMode not working on Child form

9 posts in this topic

#1 ·  Posted (edited)

So I am trying to make an app that allows you to set up a list of commands. My problem is when I toggle show/hide on a child form, the on event commands do not call the funtion at all for the child window.

This line of code does not execute the function. Found under ;keyinput window.

$ki_btn_add = GUICtrlCreateButton("   Add >>", 312, 88, 83, 25)
            GUICtrlSetOnEvent(-1, "_addkeyinput")
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiListBox.au3>

#region - GUI Creation / Settings

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode

;Parent Window
    #Region ### START Koda GUI section ### Form=C:\Users\Home\Desktop\Autoit\Scripts\CraftKey1.0\CraftkeyGUI.kxf
        $ParentWin = GUICreate("Form1", 458, 450, -1, -1, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
        GUISetBkColor(0xB4B4B4)
        $ParentWinPos = WinGetPos($ParentWin, "") ;Store x,y in an array.
        $List1 = GUICtrlCreateList("", 280, 72, 169, 253, BitOR($LBS_NOTIFY,$WS_VSCROLL,$WS_BORDER))
        GUICtrlSetData(-1, "Cycles = 1|Delay = 1000")

        $btn_exit = GUICtrlCreateButton("Exit [F10]", 352, 420, 99, 25)
            GUICtrlSetOnEvent(-1, "_EXIT")
        $btn_moveup = GUICtrlCreateButton("Move Up", 280, 328, 83, 25)
        $btn_movedown = GUICtrlCreateButton("Move Down", 368, 328, 83, 25)
        $btn_edit = GUICtrlCreateButton("Edit", 280, 352, 83, 25)
        $btn_delete = GUICtrlCreateButton("Delete", 368, 352, 83, 25)
            GUICtrlSetOnEvent(-1, "_removeCommandSel")
        $btn_keyinput = GUICtrlCreateButton("Key Input", 8, 72, 123, 25)
            GUICtrlSetOnEvent(-1,"_toggleKeyWin")
        $btn_cycles = GUICtrlCreateButton("Cycles", 8, 100, 123, 25)
        $btn_delay = GUICtrlCreateButton("Delay", 8, 128, 123, 25)
        $btn_waitkey = GUICtrlCreateButton("Wait for Key", 144, 72, 123, 25)
        $btn_beep = GUICtrlCreateButton("Beep", 144, 100, 123, 25)
        $btn_options = GUICtrlCreateButton("Options", 144, 128, 123, 25)
        $btn_load = GUICtrlCreateButton("Load", 7, 420, 99, 25)
        $btn_save = GUICtrlCreateButton("Save", 110, 420, 99, 25)

        $edit_infolog = GUICtrlCreateEdit("", 8, 160, 257, 233, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
        GUICtrlSetData(-1, "<--- Information Log --->")

        $Label1 = GUICtrlCreateLabel("_________________________________________________________________________", 8, 400, 442, 17)
        GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

;keyinput Window
    #Region ### START Koda GUI section ### Form=C:\Users\Home\Desktop\Autoit\Scripts\CraftKey1.0\keyinputGUI.kxf
        $KeyInputWin = GUICreate("KeyInput", 402, 120, $ParentWinPos[0] - 200, $ParentWinPos[1] + 240, -1, -1, $ParentWin)
        $ki_btn_add = GUICtrlCreateButton("   Add >>", 312, 88, 83, 25)
            GUICtrlSetOnEvent(-1, "_addkeyinput")
        $ki_mindelay = GUICtrlCreateInput("3000", 296, 32, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
        $ki_maxdelay = GUICtrlCreateInput("4000", 296, 56, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
        $Label1 = GUICtrlCreateLabel("Min:", 264, 36, 28, 17)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        $Label2 = GUICtrlCreateLabel("Max:", 264, 60, 31, 17)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        $Label3 = GUICtrlCreateLabel("Delay                      ", 264, 8, 133, 20)
        GUICtrlSetFont(-1, 10, 800, 4, "MS Sans Serif")
        $Label4 = GUICtrlCreateLabel("Key Selection:                                  ", 8, 8, 239, 20)
        GUICtrlSetFont(-1, 10, 800, 4, "MS Sans Serif")
        $Label5 = GUICtrlCreateLabel("m/s", 372, 36, 22, 17)
        $Label6 = GUICtrlCreateLabel("m/s", 372, 60, 22, 17)
        $ki_keyinput = GUICtrlCreateInput("Press A Key", 16, 32, 217, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_READONLY))
        GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
        GUICtrlSetBkColor(-1, 0xFFFFFF)
        GUISetState(@SW_HIDE)
    #EndRegion ### END Koda GUI section ###

;Switch to the parent window
GUISwitch($ParentWin)

#endregion

#region - Hot Keys

HotKeySet("{INS}","_start")
HotKeySet("{DEL}","_stop")
HotKeySet("{f10}","_EXIT")

#endregion

#region - Global Variables

    $VersionMSG = "-:: Version 0.1 Beta ::-"
    _GUICtrlEdit_AppendText($edit_infolog, @CRLF & $VersionMSG) ;Append to logs
    $isActive = False ;Check to see if program is active.

#endregion

;========================================================
;Main
;========================================================

While 1
    ;Sleep(100);Update in milisecondes.

WEnd

;========================================================
;Functions
;========================================================

Func _start()
    _addCommand("Input_Key: 0,1,1000,1000")
EndFunc

Func _stop()
    _removeCommandSel()
EndFunc

Func _EXIT()
    Exit
EndFunc

func _addCommand($listAdd) ;Commands to be used.
    ; Add strings
    _GUICtrlListBox_BeginUpdate($List1)

    _GUICtrlListBox_AddString($List1, random(1,100,1) & $listAdd)

    _GUICtrlListBox_UpdateHScroll($List1)
    _GUICtrlListBox_EndUpdate($List1)
EndFunc

func _removeCommandSel() ;Removes current selected command.
    Local $selected = _GUICtrlListBox_GetCurSel($List1)
    _GUICtrlListBox_DeleteString($List1, $selected)

EndFunc

Func _toggleKeyWin()
        Local $checkWin = WinGetState($KeyInputWin)

        if BitAND($checkWin, 2) Then ;check window state. 2 = visible.
            WinSetState($KeyInputWin, "", @SW_HIDE)
        Else
            WinSetState($KeyInputWin, "", @SW_SHOW)
        EndIf
    EndFunc

Func _addkeyinput() ;Check keyinput windows input box when add button is hit
    Local $checkinput = GUICtrlRead($ki_keyinput)
    if $checkinput == "Press A Key" Or $checkinput == "" Then
        MsgBox (43, "Error", "Error!" & @CRLF & "You must Select a key before hitting add button.")
    Else
        _addCommand($checkinput)
    EndIf
    MsgBox(0,"Test","Accessable!")
EndFunc
Edited by youngxx

Share this post


Link to post
Share on other sites



Don't use WinSetState to show/hide the child GUI. Use GUISetState (there is more going on internally that just showing/hiding the window).

Share this post


Link to post
Share on other sites

Also, don't use $ES_READONLY if you plan on someone entering a key in your input control.


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 Gude
How 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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

So winsetstate is the problem?

The input readonly is intentional.

Edit: the function is now called but the if statment doesnt work.

Edited by youngxx

Share this post


Link to post
Share on other sites

Are you planning on updating its contents yourself?


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 Gude
How 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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I will make a function that will detect what key is entered. The input box was just to display what is hit.

The problem now is that the if statment doesnt work in _addkeyinput, even with out the readonly.

Func _addkeyinput() ;Check keyinput windows input box when add button is hit
    Local $checkinput = GUICtrlRead($ki_keyinput)

    if $checkinput == "Press A Key" Then
        MsgBox(43, "Error", "Error!" & @CRLF & "You must Select a key before hitting add button.")
    Else
        _addCommand($checkinput)
    EndIf

    ;MsgBox(0,"Test","Accessable! - " & $checkinput)
EndFunc
Edited by youngxx

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

It looks like a bug in AutoIt to me but that is possibly a bit rash. However, if you make the child window visible to start with then it works as expected.

Ie

GuiSetState()

instead of

GuiSetState(@SW_HIDE)

EDIT:

BTW, the parent window hides the MsgBox so you need to move it away or maybe not use $WS_EX_TOPMOST.

EDT 2:

I see, a little late, that wraithdu's advise not to use WInSetState makes the difference to the script working or not.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Ok, it's all good atm. The if statement works fine too. I just put wrong number for first parameter for msgbox.

Thanks for help!

Edited by youngxx

Share this post


Link to post
Share on other sites

I was just going to mention the msgbox flag problem. You'll want to consider making it modal too, flag 4096, otherwise the message boxes are hidden behind your GUI since you've made it always on top.

Share this post


Link to post
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
Sign in to follow this  
Followers 0