Jump to content

Recommended Posts

Posted

Hi, I'm hoping someone can point me in the direction, I've created basic AutoIT scripts in the past and now trying to create something more advanced for work.

Originally I created a single GUI for creating XML to use for router auto provisioning, this GUI had various Input boxes, Combo boxes and used UDF input's such as _GUICtrlIpAddress_Create, and the combo boxes populated from arrays, I had the background set to one of the company colours and could tab through in order the various fields and this GUI has worked fine for the last couple of years.

I'm now trying to create a GUI with multiple tabs for 2 different types of routers (different manufacturers) and an access point.

I had varying success at this and have found loads of posts on the forums of examples but couldn't really find one that did everything I wanted, I then found an example from @Melba23 on the thread below which seemed todo everything I wanted, so have taken that as my base to build from however I've now stumbled across a few issues which I just cant figure out.

My code below run's and creates the GUI I desire (minus a number of the input fields which I'm yet to add), in that I have 3 tab's all of which have a background colour matching the parent gui, I can hide the UDF created functions in the child GUI'S and the "router 1" tab is set as focused on start up and tabbing through the fields did work, however the issues I'm now facing are the following :

Tabbing trough the fields in the child GUI's no longer works and I cant make the "Create Button" on the first tab actually function. I already have a working function from my first single pane GUI which will take the variables and populate the relevant fields for creating the XML output which I'd like to use if possible, but in my example below which I removed any company specific stuff for testing I'm just trying to get the create button to pop up a message box so I know it's working rather than calling my xml function.

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiIPAddress.au3>
#include <GUIConstants.au3>
#include <GuiTab.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <ListViewConstants.au3>
#include <GDIPlus.au3>
#include <WinAPIFiles.au3>
#include <Array.au3>
#include <GuiComboBox.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>


Opt('MustDeclareVars', 1)
Global $hImage, $hGraphic, $dGraphic, $dImage, $hH, $hW, $dH, $dW


Example()

Func Example()
    Local $hGUI, $hGUI_Child, $hGUI_Child0, $hGUI_Child1
    Local $tab, $tab0, $tab1, $tab2
    Local $hIPAddress, $aMsg, $R1CreateButton
    Global $R1mac, $R1pass, $R1Name, $R1LAN, $R1RIPLabel, $R1RouterIP, $R1DHCP_1, $R1DHCP_2, $R1DHCPStart, $R1DHCPEnd, $R1SUBLabel, $R1Subnet
    Global $R2Mac, $R2Name, $R2Pass
    Global $RMAC, $Password, $Rname, $SDHCP, $EDHCP, $Sub, $RIP

    ; Create main GUI
    $hGUI = GUICreate("Auto Provisioning XML Creator",920,820)
    GUISetBkColor(0xbfe1c9)
    GUICtrlCreateLabel("Red fields must be changed to unique values for each site, black fields apart from AZ01/AZ02 NAT IP fields should only be changed if you know what you are doing.", 10, 54, 900, 16)
    GUICtrlSetFont(-1, 9)
    ;GUISetState(@SW_HIDE)


        ; Load and draw logo 1
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile("C:\AutoIT\logo1.png")
    $hH = _GDIPlus_ImageGetHeight($hImage)
    $hW = _GDIPlus_ImageGetWidth($hImage)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    ;                _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 10, 10)

    ; Load and draw logo 2
    $dImage = _GDIPlus_ImageLoadFromFile("C:\AutoIT\Logo2.png")
    $dH = _GDIPlus_ImageGetHeight($dImage)
    $dW = _GDIPlus_ImageGetWidth($dImage)
    $dGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    ;                _GDIPlus_GraphicsDrawImage($dGraphic, $dImage, 530, 10)

    GUISetState(@SW_SHOW, $hGUI) ; set the GUI as Visible.
    Repaint()
    GUIRegisterMsg($WM_PAINT, "WM_PAINT")



    ; Create a child window that will be incorparated into the main GUI
    $hGUI_Child = GUICreate("", 920, 730, 0, 90, BitOR($WS_CHILD, $WS_TABSTOP), -1, $hGUI)
    GUISetBkColor(0xbfe1c9, $hGUI_Child)

    ;Basic Settings
    GUICtrlCreateLabel("Basic Settings:", 20, 50, 120, 20)
    GUICtrlSetFont(-1, 9.5, 700)
    $R1Mac = GUICtrlCreateInput("0000AAAAAAAA", 90, 80, 90, 20)
    GUICtrlCreateLabel("Router MAC:", 20, 85, 70, 20)
    GUICtrlSetLimit($R1Mac, 12, 12)
    GUICtrlSetColor($R1Mac, 0xFF0000)
    $R1Pass = GUICtrlCreateInput("Password", 90, 110, 90, 20)
    GUICtrlCreateLabel("Password:", 20, 115, 70, 20)
    $R1Name = GUICtrlCreateInput("Name", 90, 140, 90, 20)
    GUICtrlCreateLabel("Router Name:", 20, 145, 70, 20)
    GUICtrlSetColor($R1Name, 0xFF0000) ; Red

    ;Lan Settings
    $R1LAN = GUICtrlCreateLabel("LAN Configuration Settings:", 20, 180, 160, 20)
    GUICtrlSetFont(-1, 9.5, 700)
    $R1RIPLabel = GUICtrlCreateLabel("Enter the Router IP below :", 20, 210, 160, 18)
    $R1RouterIP = _GUICtrlIpAddress_Create($hGUI_Child, 20, 225, 160, 20)
    _GUICtrlIpAddress_Set($R1RouterIP, "172.17.0.1")
    $R1DHCP_1 = GUICtrlCreateLabel("Enter first DHCP address below :", 20, 255, 160, 18)
    $R1DHCPStart = _GUICtrlIpAddress_Create($hGUI_Child, 20, 270, 160, 20)
    _GUICtrlIpAddress_Set($R1DHCPStart, "172.17.0.5")
    $R1DHCP_2 = GUICtrlCreateLabel("Enter last DHCP address below :", 20, 300, 160, 18)
    $R1DHCPEnd = _GUICtrlIpAddress_Create($hGUI_Child, 20, 315, 160, 20)
    _GUICtrlIpAddress_Set($R1DHCPEnd, "172.17.0.30")
    $R1SUBLabel = GUICtrlCreateLabel("Enter the subnet mask below :", 20, 345, 160, 18)
    $R1Subnet = _GUICtrlIpAddress_Create($hGUI_Child, 20, 360, 160, 20)
    _GUICtrlIpAddress_Set($R1Subnet, "255.255.255.224")


    ;VPN Settings
    Global $hVPNSettings = GUICtrlCreateLabel("VPN Settings:", 220, 50, 120, 20)
    GUICtrlSetFont(-1, 9.5, 700)
    GUICtrlCreateLabel("Pre Shared Key:", 220, 85, 85, 20)
    Global $hVPNPSK = GUICtrlCreateInput("PSK", 300, 80, 200, 20)
    GUICtrlSetColor(-1, 0xFF0000) ; Red
    GUICtrlCreateLabel("Local ID:", 220, 115, 60, 20)
    Global $hVPNLID = GUICtrlCreateInput("Local ID", 300, 110, 100, 20)
    GUICtrlSetLimit($hVPNLID, 13)
    GUICtrlSetColor(-1, 0xFF0000) ; Red
    GUICtrlCreateLabel("VPN1 NAT IP:", 220, 145, 70, 20)
    Global $hVPN1PH2ID = _GUICtrlIpAddress_Create($hGUI_Child, 300, 140, 100, 20)
    _GUICtrlIpAddress_Set($hVPN1PH2ID, "172.18.0.1")
    GUICtrlCreateLabel("VPN2 NAT IP:", 220, 175, 70, 20)
    Global $hVPN2PH2ID = _GUICtrlIpAddress_Create($hGUI_Child, 300, 170, 100, 20)
    _GUICtrlIpAddress_Set($hVPN2PH2ID, "172.19.0.0")
    Global $hVPNRIP = _GUICtrlIpAddress_Create($hGUI_Child, 300, 200, 100, 20)
    GUICtrlCreateLabel("Remote LAN IP:", 220, 205, 80, 20)
    Global $hVPNRSub = _GUICtrlIpAddress_Create($hGUI_Child, 300, 230, 100, 20)
    _GUICtrlIpAddress_Set($hVPNRSub, "255.255.255.255")
    GUICtrlCreateLabel("Rem Subnet IP:", 220, 235, 80, 20)



    $R1CreateButton = GUICtrlCreateButton("Create XML File", 760, 550, 96, 30)

    GUISetState(@SW_HIDE)


    $hGUI_Child0 = GUICreate("", 920, 730, 0, 90, BitOR($WS_CHILD, $WS_TABSTOP), -1, $hGUI)
    GUISetBkColor(0xbfe1c9, $hGUI_Child0)
    ;Basic Settings
    GUICtrlCreateLabel("Basic Settings:", 20, 50, 120, 20)
    GUICtrlSetFont(-1, 9.5, 700)
    $R2Mac = GUICtrlCreateInput("0000AAAAAAAA", 90, 80, 90, 20)
    GUICtrlCreateLabel("Router MAC:", 20, 85, 70, 20)
    GUICtrlSetLimit($R2Mac, 12, 12)
    GUICtrlSetColor($R2Mac, 0xFF0000)
    $R2Pass = GUICtrlCreateInput("Password", 90, 110, 90, 20)
    GUICtrlCreateLabel("Password:", 20, 115, 70, 20)
    $R2Name = GUICtrlCreateInput("Name", 90, 140, 90, 20)
    GUICtrlCreateLabel("Router Name:", 20, 145, 70, 20)
    GUICtrlSetColor($R2Name, 0xFF0000) ; Red
    $hIPAddress = _GUICtrlIpAddress_Create($hGUI_Child0, 10, 10)
    GUISetState(@SW_HIDE)

    $hGUI_Child1 = GUICreate("", 920, 730, 0, 90, BitOR($WS_CHILD, $WS_TABSTOP), -1, $hGUI)
    GUISetBkColor(0x257788, $hGUI_Child1)
    $hIPAddress = _GUICtrlIpAddress_Create($hGUI_Child1, 10, 10)
    GUISetState(@SW_HIDE)
    GUISetState()

    ; Go back to main GUI
    GUISwitch($hGui, $tab0)


    ; Create tab structure
    $tab = GUICtrlCreateTab(0, 70, 920, 820)



    $tab0 = GUICtrlCreateTabItem("Router Type 1")
    GUICtrlCreateLabel("Router Type 1",380, 100, 145, 40) ; No need to store ControlID if you never use it <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetFont(-1, 16, 700)




    $tab1 = GUICtrlCreateTabItem("Router Type 2")
    GUICtrlCreateLabel("Router Type 2", 380, 100, 180, 40) ; No need to store ControlID if you never use it <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetFont(-1, 16, 700)

    $tab2 = GUICtrlCreateTabItem("Access Point")
    GUICtrlCreateLabel("Access Point", 380, 100, 145, 40) ; No need to store ControlID if you never use it <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetFont(-1, 16, 700)

    GUICtrlCreateTabItem("") ; end tabitem definition
    _GUICtrlTab_SetCurFocus($Tab, 0)
    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1

        $aMsg = GUIGetMsg(1)
        Switch $aMsg[0]
            Case $GUI_EVENT_CLOSE
                _Exit()
            Case $tab
                ; Show/Hide the child GUI as required
                Switch GUICtrlRead($tab)
                    Case 0
                        GUISetState(@SW_HIDE, $hGUI_Child0)
                        GUISetState(@SW_HIDE, $hGUI_Child1)
                        GUISetState(@SW_SHOW, $hGUI_Child)
                    Case 1
                        GUISetState(@SW_SHOW, $hGUI_Child0)
                        GUISetState(@SW_HIDE, $hGUI_Child)
                        GUISetState(@SW_HIDE, $hGUI_Child1)
                    Case 2
                        GUISetState(@SW_HIDE, $hGUI_Child)
                        GUISetState(@SW_HIDE, $hGUI_Child0)
                        GUISetState(@SW_SHOW, $hGUI_Child1)
                EndSwitch
                    Switch $aMsg[0]
                        Case $hGUI_Child
                            Case $R1CreateButton
                            MsgBox($MB_ICONQUESTION, "Create XML", "This is a test box to check button function")
                    EndSwitch
        EndSwitch
    WEnd
    _Exit()
EndFunc   ;==>Example



Func Repaint()
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 10, 06, $hW, $hH)
    _GDIPlus_GraphicsDrawImageRect($dGraphic, $dImage, 700, 06, $dW, $dH)
EndFunc   ;==>Repaint


Func WM_PAINT()
    Repaint()
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_PAINT


Func _Exit()
    GUIRegisterMsg($WM_PAINT, "")
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($dGraphic)
    _GDIPlus_ImageDispose($dImage)
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc   ;==>_Exit

 

  • Solution
Posted

Hello :)
With AutoIt, if you want to be able to use the Tab key through the controls of a child window created with $WS_CHILD style, then you got to do what follows (tested successfully on your script)

; $hGUI_Child = GUICreate("", 920, 730, 0, 90, BitOR($WS_CHILD, $WS_TABSTOP), -1, $hGUI)
$hGUI_Child = GUICreate("", 920, 730, 0, 90, $WS_CHILD, $WS_EX_CONTROLPARENT, $hGUI)

; $hGUI_Child0 = GUICreate("", 920, 730, 0, 90, BitOR($WS_CHILD, $WS_TABSTOP), -1, $hGUI)
$hGUI_Child0 = GUICreate("", 920, 730, 0, 90, $WS_CHILD, $WS_EX_CONTROLPARENT, $hGUI)

; $hGUI_Child1 = GUICreate("", 920, 730, 0, 90, BitOR($WS_CHILD, $WS_TABSTOP), -1, $hGUI)
$hGUI_Child1 = GUICreate("", 920, 730, 0, 90, $WS_CHILD, $WS_EX_CONTROLPARENT, $hGUI)

But this is not enough.
Though it works and you can Tab correctly now (which is the purpose of the extended style $WS_EX_CONTROLPARENT), you'll notice sooner or later that your 3 child gui's have become... draggable !

This is because an odd "functionality" was added a long time ago to AutoIt, hijacking the $WS_EX_CONTROLPARENT extended style, allowing it to also "drag a GUI without $WS_CAPTION by using $WS_EX_CONTROLPARENT in the exStyle parameter" (help file, topic GuiCreate)

So what should be done to prevent this draggable functionality, keeping only the correct use of the Tab key ?
You need to add this in your script :

Global $hGUI_Child, $hGUI_Child0, $hGUI_Child1
...
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND") ; just before the main loop While 1
...
Func WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam)
    If $hWnd = $hGUI_Child Or $hWnd = $hGUI_Child0 Or $hWnd = $hGUI_Child1 Then
        If BitAND($wParam, 0xFFF0) = 0xF010 Then Return False ; $SC_MOVE = 0xF010
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SYSCOMMAND

Now your 3 child GUI's aren't draggable... and the Tab key is functional.
Good luck

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted

Hi pixelsearch, thanks for your reply, I've implemented your code and it's fixed my tabbing issue, thank you so much , I would have never figured that out!

I see what you mean about the child GUI's being draggable without the second part of your, that is definitely some odd "functionality".

 

Just need to figure out what's going on with the child GUI button now, I'm sure it's something simple so I'll keep digging through the help files and forum.

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
×
×
  • Create New...