Jump to content

Using an additional Form...


TSO
 Share

Recommended Posts

I have a 'Case' that I want to use to open a new form (I'm guessing I don't have a choice to do this within the same form) with an input box, and 2 buttons.

Two questions...

1) Where in my script do I write the code for the additional Form? Or do I need to link it somehow to a separate AU3?

2) What syntax do I use to launch form2 in my form1 'Case' statement?

Thanks again,

TSO

Link to comment
Share on other sites

It's very easy:

Opt("GUIOnEventMode",1)
$parent=GUICreate("Parent")
GUICtrlCreateButton("Show child",10,10)
GUICtrlSetOnEvent(-1,"_ShowChild")
GUISetOnEvent(-3,"close")

$child=GUICreate("Child",300,300,-1,-1,-1,-1,$parent)
GUISetOnEvent(-3,"_HideChild")


GUISetState(@SW_SHOW,$parent)

Do
    Sleep(10)
Until False




Func _ShowChild()
    GUISetState(@SW_SHOW,$child)
EndFunc

Func _HideChild()
    GUISetSTate(@SW_HIDE,$child)
EndFunc


Func close ()
    Exit
EndFunc

I choosed to give you an example with OnEvent code even though I know your code is in GUIGetMsg() mode because IMHO GUIGetMsg() mode code becomes messy when you try to make something more than just an example.

Good Luck! :)

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Unfortunately it's still all Greek to me; I am using GUIGetMsg()... I'm completely new to AutoIt, and just-about programming in general. Here is my code, look towards the bottom to see my note of where I'm trying to add this item.

;xxx
;
; AutoIt Version: 3.x
; Language:    English
; Platform:    Win 2000/XP
; Author:        xxx
;
; Script Function:
;   This script will use technician interface to populate the 'Registered Organization' Windows registry key 
;   with the support organization determined to be appropriate for the computer the script is run on.
;    The result of this populated key will be a notation under 'My Computer' properties, and the ability
;    for the computer's designated support group to be inventoried by Altiris.

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colSMBIOS = $objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
$wmi = ObjGet("winmgmts:")
$wql = "select * from win32_computersystem"
$results = $wmi.execquery($wql)
$secStat = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSector")
$busStat = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedBusinessUnit")
$supStat = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSupportGroup")

If $secStat = "" Then
    $secStat = "Undefined"
EndIf
If $busStat = "" Then
    $busStat = "Undefined"
EndIf
If $supStat = "" Then
    $supStat = "Undefined"
EndIf

For $objSMBIOS in $colSMBIOS
  ;ConsoleWrite("Serial Number: " & $objSMBIOS.SerialNumber & @CRLF)
  ;ConsoleWrite("Asset Tag: " & $objSMBIOS.SMBIOSAssetTag & @CRLF)
Next

For $compsys in $results
  ConsoleWrite("Domain:  " & $compsys.domain & @CRLF)
Next

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\s830829\Desktop\koda_1.7.0.1\Forms\EUSGUI3.kxf

$Form1 = GUICreate("RoS", 332, 470, 214, 139)
$Label1 = GUICtrlCreateLabel("Select Business Unit:", 144, 224, 130, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Select Sector:", 144, 168, 85, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Select Support Group:", 144, 280, 130, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Group2 = GUICtrlCreateGroup("Change Service:", 136, 144, 185, 185)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label7 = GUICtrlCreateLabel("Redirection of Service", 75, 0, 180, 25)
GUICtrlSetFont(-1, 12, 800, 4, "Arial Unicode MS")
GUICtrlSetColor(-1, 0x000080)
$Button1 = GUICtrlCreateButton("Change", 32, 424, 115, 33, 0)
$Button2 = GUICtrlCreateButton("Cancel", 184, 424, 115, 33, 0)
$Label4 = GUICtrlCreateLabel("Support Group:", 16, 280, 90, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("Sector:", 16, 168, 45, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("Business Unit:", 16, 224, 85, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Group1 = GUICtrlCreateGroup("Current Status:", 8, 144, 121, 185)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$secInf = GUICtrlCreateInput($secStat, 16, 184, 105, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$busInf = GUICtrlCreateInput($busStat, 16, 240, 105, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$supInf = GUICtrlCreateInput($supStat, 16, 296, 105, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$Label8 = GUICtrlCreateLabel("Host Name:", 72, 64, 70, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label9 = GUICtrlCreateLabel("Domain:", 88, 88, 50, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label10 = GUICtrlCreateLabel("Serial Number:", 56, 112, 87, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$hostName = GUICtrlCreateInput(@ComputerName, 152, 56, 121, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$Domain = GUICtrlCreateInput($compsys.domain, 152, 80, 121, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$sNum = GUICtrlCreateInput($objSMBIOS.SerialNumber, 152, 104, 121, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$Group3 = GUICtrlCreateGroup("This Computer Information:", 48, 32, 233, 105)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Radio1 = GUICtrlCreateRadio("New Deployment", 56, 368, 113, 17)
$Radio2 = GUICtrlCreateRadio("Refresh Upgrade", 56, 384, 113, 17)
$Radio3 = GUICtrlCreateRadio("Asset Removal", 176, 368, 97, 17)
$Radio4 = GUICtrlCreateRadio("Existing Asset", 176, 384, 97, 17)
$Group4 = GUICtrlCreateGroup("This Computer is a...", 48, 344, 233, 65)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
$Combo1 = GUICtrlCreateCombo("", 144, 184, 97, 200,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData($Combo1, "SECTOR1|SECTOR2|SECTOR3")
$Combo3 = GUICtrlCreateCombo("", 144, 296, 161, 200,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData($Combo3, "SUPPORT1|SUPPORT2|SUPPORT3")
$Combo2 = GUICtrlCreateCombo("", 144, 240, 161, 200,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData($Combo2, "BUSINESS1|BUSINESS2|BUSINESS3")

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

    EndSwitch
Select
    Case $nMsg = $Button2
    Exit
    Case $nMsg = $Button1 AND GUICtrlRead($Combo1) = "" 
    MsgBox(0, "Information Required", "Please choose a Sector")
    Case $nMsg = $Button1 AND GUICtrlRead($Radio2) = $GUI_CHECKED

;   ^^^^^^^^^
;****RIGHT HERE IS WHERE I WANT TO OPEN AN INPUT BOX WITH AN "OK" AND "CANCEL BUTTON*****


    Case $nMsg = $Button1 AND GUICtrlRead($Radio3) = $GUI_CHECKED
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RegisteredOrganization", "REG_SZ", "Asset Removed")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSupportGroup", "REG_SZ", "Asset Removed")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedBusinessUnit", "REG_SZ", "Asset Removed")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSector", "REG_SZ", "Asset Removed")
    MsgBox(0, "Updated", "This asset has been removed from the database")
    Exit
    Case $nMsg = $Button1
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RegisteredOrganization", "REG_SZ", GUICtrlRead($Combo3))
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSupportGroup", "REG_SZ", GUICtrlRead($Combo3))
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedBusinessUnit", "REG_SZ", GUICtrlRead($Combo2))
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSector", "REG_SZ", GUICtrlRead($Combo1))
    MsgBox(0, "Updated", "Support information has been updated")
    Exit    
    


       EndSelect
WEnd
#EndRegion ### END Koda GUI section ###

Thanks again!

Edited by TSO
Link to comment
Share on other sites

  • 4 weeks later...

Hi Guys,

just a quick question on that matter.

I have had a few issues with GUIOnEventMode, like functions beeing executed out of the blue(probably some bug in my code but still).

My question is, is it better to go with GUIGetMsg or GUIOnEventMode.

concidering the fact that GUIOnEventMode would be overkill in smaller GUI's

[font="Century Gothic"]quisnam est quantum stultus , balatro vel balatro quisnam insistovolubilis in solum rideo risi risum----------------------------------------------------------------------------------------------------------------------------Portable Command Line Tool[/font]

Link to comment
Share on other sites

Hi Guys,

just a quick question on that matter.

I have had a few issues with GUIOnEventMode, like functions beeing executed out of the blue(probably some bug in my code but still).

My question is, is it better to go with GUIGetMsg or GUIOnEventMode.

concidering the fact that GUIOnEventMode would be overkill in smaller GUI's

Up to you, create your own topic if you want to discuss it further.

@OP, let me have a look, and we'll see muttley

Ok. Can't say I liked all the $button1 cases and so forth, so I changed it. You'll find that actually assigning names to controls makes it a shitload easier to work out whats happening. Hope you understand what I did, if not ask and I will explain it to you! :)

;xxx
;
; AutoIt Version: 3.x
; Language:    English
; Platform:    Win 2000/XP
; Author:        xxx
;
; Script Function:
;   This script will use technician interface to populate the 'Registered Organization' Windows registry key
;   with the support organization determined to be appropriate for the computer the script is run on.
;    The result of this populated key will be a notation under 'My Computer' properties, and the ability
;    for the computer's designated support group to be inventoried by Altiris.

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colSMBIOS = $objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
$wmi = ObjGet("winmgmts:")
$wql = "select * from win32_computersystem" 
$results = $wmi.execquery ($wql)
$secStat = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSector")
$busStat = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedBusinessUnit")
$supStat = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSupportGroup")

If $secStat = "" Then
    $secStat = "Undefined" 
EndIf
If $busStat = "" Then
    $busStat = "Undefined" 
EndIf
If $supStat = "" Then
    $supStat = "Undefined" 
EndIf

For $objSMBIOS In $colSMBIOS
;ConsoleWrite("Serial Number: " & $objSMBIOS.SerialNumber & @CRLF)
;ConsoleWrite("Asset Tag: " & $objSMBIOS.SMBIOSAssetTag & @CRLF)
Next

For $compsys In $results
    ConsoleWrite("Domain:  " & $compsys.domain & @CRLF)
Next

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\s830829\Desktop\koda_1.7.0.1\Forms\EUSGUI3.kxf

$Form1 = GUICreate("RoS", 332, 470, 214, 139)
$Label1 = GUICtrlCreateLabel("Select Business Unit:", 144, 224, 130, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Select Sector:", 144, 168, 85, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Select Support Group:", 144, 280, 130, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Group2 = GUICtrlCreateGroup("Change Service:", 136, 144, 185, 185)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label7 = GUICtrlCreateLabel("Redirection of Service", 75, 0, 180, 25)
GUICtrlSetFont(-1, 12, 800, 4, "Arial Unicode MS")
GUICtrlSetColor(-1, 0x000080)
$Button1 = GUICtrlCreateButton("Change", 32, 424, 115, 33, 0)
$Button2 = GUICtrlCreateButton("Cancel", 184, 424, 115, 33, 0)
$Label4 = GUICtrlCreateLabel("Support Group:", 16, 280, 90, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("Sector:", 16, 168, 45, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("Business Unit:", 16, 224, 85, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Group1 = GUICtrlCreateGroup("Current Status:", 8, 144, 121, 185)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$secInf = GUICtrlCreateInput($secStat, 16, 184, 105, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$busInf = GUICtrlCreateInput($busStat, 16, 240, 105, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$supInf = GUICtrlCreateInput($supStat, 16, 296, 105, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$Label8 = GUICtrlCreateLabel("Host Name:", 72, 64, 70, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label9 = GUICtrlCreateLabel("Domain:", 88, 88, 50, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label10 = GUICtrlCreateLabel("Serial Number:", 56, 112, 87, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$hostName = GUICtrlCreateInput(@ComputerName, 152, 56, 121, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$Domain = GUICtrlCreateInput($compsys.domain, 152, 80, 121, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$sNum = GUICtrlCreateInput($objSMBIOS.SerialNumber, 152, 104, 121, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$Group3 = GUICtrlCreateGroup("This Computer Information:", 48, 32, 233, 105)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Radio1 = GUICtrlCreateRadio("New Deployment", 56, 368, 113, 17)
$Radio2 = GUICtrlCreateRadio("Refresh Upgrade", 56, 384, 113, 17)
$Radio3 = GUICtrlCreateRadio("Asset Removal", 176, 368, 97, 17)
$Radio4 = GUICtrlCreateRadio("Existing Asset", 176, 384, 97, 17)
$Group4 = GUICtrlCreateGroup("This Computer is a...", 48, 344, 233, 65)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
$Combo1 = GUICtrlCreateCombo("", 144, 184, 97, 200, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData($Combo1, "SECTOR1|SECTOR2|SECTOR3")
$Combo3 = GUICtrlCreateCombo("", 144, 296, 161, 200, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData($Combo3, "SUPPORT1|SUPPORT2|SUPPORT3")
$Combo2 = GUICtrlCreateCombo("", 144, 240, 161, 200, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData($Combo2, "BUSINESS1|BUSINESS2|BUSINESS3")

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $Button2
            Exit
        Case $nMsg = $Button1
            If $Button1 And GUICtrlRead($Combo1) = "" Then
                MsgBox(0, "Information Required", "Please choose a Sector")
            ElseIf GUICtrlRead($Radio2) = $GUI_CHECKED Then
                $msgbox = MsgBox (17, "MsgBox Title", "Are You Sure?")
                If $msgbox = 1 Then
                    MsgBox (0, "", "OK WAS PRESSED!")
                ElseIf $msgbox = 2 Then
                    MsgBox (0, "", "CANCEL WAS PRESSED!")
                Else
                    MsgBox (0, "", "SOMETHING IS REALLY REALLY REALLLLLYYYYY WRONG!!!!!!! =O")
                EndIf
            ElseIf GUICtrlRead($Radio3) = $GUI_CHECKED Then
            ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RegisteredOrganization", "REG_SZ", "Asset Removed")
            ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSupportGroup", "REG_SZ", "Asset Removed")
            ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedBusinessUnit", "REG_SZ", "Asset Removed")
            ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSector", "REG_SZ", "Asset Removed")
                MsgBox(0, "Updated", "This asset has been removed from the database")
            ;Exit
            Else
            ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RegisteredOrganization", "REG_SZ", GUICtrlRead($Combo3))
            ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSupportGroup", "REG_SZ", GUICtrlRead($Combo3))
            ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedBusinessUnit", "REG_SZ", GUICtrlRead($Combo2))
            ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSector", "REG_SZ", GUICtrlRead($Combo1))
                MsgBox(0, "Updated", "Support information has been updated")
            ;Exit
            EndIf
    EndSelect
WEnd
#EndRegion ### END Koda GUI section ###
Edited by Bert
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...