Jump to content

2 Form GUI Issue[Solved]


Zacam
 Share

Recommended Posts

K. I have the Primary form, which launches (via a button control) a secondary Form GUI (hiding the first) to show a device status.

The problem is, the button that I have (on Form2) that is supposed to launch the external EXE for re-installing (or Installing depending on the case) does not actually launch the exe.

If I directly copy the button and case data to the Form1 window though, it does launch it.

????

Edited by Zacam
Link to comment
Share on other sites

  • Moderators

Zacam,

Please post some code - my crystal ball is frosted over! ;)

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

Zacam,

May be you want somethink like this?

#include <GUIConstants.au3>


$Form1_1 = GUICreate("Form2", 597, 332, 278, 155)
$Button1 = GUICtrlCreateButton("Execute", 72, 248, 129, 41, 0)
$Button2 = GUICtrlCreateButton("CALL SECOND GUI.", 368, 248, 145, 41, 0)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            GUIDelete($Form1_1) ;deleting first GUI
            Run("cmd.exe /c notepad.exe",@ScriptDir,@SW_HIDE)   ;execute notepad.exe
            second()    ;calling second gui
        Case $Button2
            GUIDelete($Form1_1) ;deleting first GUI
            second() 

    EndSwitch
WEnd


func second()
#include <GUIConstants.au3>


$Form1 = GUICreate("Form2", 597, 189, 293, 153)
$Button2 = GUICtrlCreateButton("Exit", 208, 96, 145, 41, 0)
$Label1 = GUICtrlCreateLabel("SECOND GUI!", 240, 16, 74, 17)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            Exit
    EndSwitch
WEnd
EndFunc; ==>second()
Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

.... Right, I forget that conceptual understanding is for the fail.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <RestrictControlRegExp.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$FORM1 = GUICreate("Test Window", 140, 100, 300, 230)
GUISetBkColor(16776176)
$CLOSE = GUICtrlCreateButton("Close", 50, 75, 75, 25, BitOR($BS_PUSHLIKE, $WS_GROUP))
GUICtrlSetCursor(-1, 0)

$DEVSTAT = GuiCtrlCreateButton("Device Status", 10, 5, 120, 25, BitOR($BS_CENTER, $WS_GROUP))
GUICtrlSetCursor($DEVSTAT, 0)
$INSTDEV = GuiCtrlCreateButton("Install Device", 10, 35, 120, 25, BitOR($BS_CENTER, $WS_GROUP))
GUICtrlSetCursor($INSTDEV, 0)
GUISetState(@SW_SHOW, $FORM1)

$FORM2 = GUICreate("Device Status", 140, 100, 300, 230)
GUISetBkColor(16776176)
$Return1 = GUICtrlCreateButton("Return", 5, 40, 75, 25, BitOR($BS_PUSHLIKE, $WS_GROUP))
GUICtrlSetCursor($Return1, 0)
$INSTDEV = GuiCtrlCreateButton("Install Device", 5, 10, 120, 25, BitOR($BS_CENTER, $WS_GROUP))
GUICtrlSetCursor($INSTDEV, 0)
GUISetState(@SW_HIDE, $FORM2)

While 1
    $NMSG = GUIGetMsg()
    Switch $NMSG
        Case $GUI_EVENT_CLOSE
            Exit
        Case $INSTDEV
            Local $EXEPATH = "C:\Drivers\D1\DRIVER.EXE"
            ShellExecute($EXEPATH,"","")
        Case $DEVSTAT
            _Form2()
        Case $CLOSE
            Exit
    EndSwitch
WEnd

Func _Form2()
    GUISetState(@SW_HIDE, $Form1)
    GUISetState(@SW_SHOW, $Form2)
    While 1
    $NMSG = GUIGetMsg()
        Switch $NMSG
            Case $INSTDEV
                Local $EXEPATH = "C:\Drivers\D1\DRIVER.EXE"
                ShellExecute($EXEPATH,"","")
            Case $GUI_EVENT_CLOSE
                GUISetState(@SW_HIDE, $Form2)
                GUISetState(@SW_SHOW, $Form1)
                Return
            Case $Return1
                GUISetState(@SW_HIDE, $Form2)
                GUISetState(@SW_SHOW, $Form1)
                Return
        EndSwitch
    WEnd
EndFunc

When drafting this example, the reverse happened, the button in Form1 for Install does not work, but the one in Form2 does. The _only_ reason why I put the button on Form1 was to make sure I wasn't screwing something up on the commands for the button, it's meant to launch from Form2.

Unfortunately, I cannot post the actual application code that I'm working on, only a conceptual example.

Edited by Zacam
Link to comment
Share on other sites

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.2.0
 Author:    myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>

#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$FORM1 = GUICreate("Test Window", 140, 100, 300, 230)
GUISetBkColor(16776176)
$CLOSE = GUICtrlCreateButton("Close", 50, 75, 75, 25, BitOR($BS_PUSHLIKE, $WS_GROUP))
GUICtrlSetCursor(-1, 0)

$DEVSTAT = GuiCtrlCreateButton("Device Status", 10, 5, 120, 25, BitOR($BS_CENTER, $WS_GROUP))
GUICtrlSetCursor($DEVSTAT, 0)
$INSTDEV = GuiCtrlCreateButton("Install Device", 10, 35, 120, 25, BitOR($BS_CENTER, $WS_GROUP))
GUICtrlSetCursor($INSTDEV, 0)
GUISetState(@SW_SHOW, $FORM1)

$FORM2 = GUICreate("Device Status", 140, 100, 300, 230)
GUISetBkColor(16776176)
$Return1 = GUICtrlCreateButton("Return", 5, 40, 75, 25, BitOR($BS_PUSHLIKE, $WS_GROUP))
GUICtrlSetCursor($Return1, 0)
$nope = GuiCtrlCreateButton("Install Device", 5, 10, 120, 25, BitOR($BS_CENTER, $WS_GROUP))
GUICtrlSetCursor($INSTDEV, 0)
GUISetState(@SW_HIDE, $FORM2)

While 1
    $NMSG = GUIGetMsg()
    Switch $NMSG
    Case $GUI_EVENT_CLOSE
    Exit
    Case $INSTDEV
    Run("cmd.exe /c " & @WindowsDir&"\system32\calc.exe","",@SW_HIDE)
    Case $DEVSTAT
    _Form2()
    Case $CLOSE
    Exit
    EndSwitch
WEnd

Func _Form2()
    GUISetState(@SW_HIDE, $Form1)
    GUISetState(@SW_SHOW, $Form2)
    While 1
    $NMSG = GUIGetMsg()
    Switch $NMSG
    Case $nope
    Run("cmd.exe /c " & @WindowsDir&"\system32\calc.exe","",@SW_HIDE)
    Case $GUI_EVENT_CLOSE
    GUISetState(@SW_HIDE, $Form2)
    GUISetState(@SW_SHOW, $Form1)
    Return
    Case $Return1
    GUISetState(@SW_HIDE, $Form2)
    GUISetState(@SW_SHOW, $Form1)
    Return
    EndSwitch
    WEnd
EndFunc

[size="5"] [/size]
Link to comment
Share on other sites

Okay, the actual stupid issue was a Refresh() function that was misplaced. Still rather interesting that the test example though has to have a change in the Button case function name (and btw, you missed changing the GUICtrlSetCursor to $nope).

Anyway, stupidity resolved.

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...