Sign in to follow this  
Followers 0
caram1992

Problems with $Form1, $button e etc...

6 posts in this topic

I'm trying to improve a script that I made using "InputBox", I now use form1 (Koda).

But I'm having problems when the time to make the button linking to the script that activates another form2

That part I always get confused

whenever I try to use ...

look at all the code (one is missing for me to do, Which is what the case shows all user accounts, but does not influence the desire to learn.)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#Region ### START Koda GUI section ### Form=


 Opt("guioneventmode", 1)

$Form1 = GUICreate("User Creator - by Bode", 328, 210, 192, 124)
GUISetCursor (3)
$nFileMenu = GUICtrlCreateMenu("File")
    $nHelpitem2 = GUICtrlCreateMenuItem("Help", $nFileMenu)
        GUICtrlSetOnEvent(-2, "help")
    $nAboutitem = GUICtrlCreateMenuItem("About", $nFileMenu)
        GUICtrlSetOnEvent(-3, "about")
$Group1 = GUICtrlCreateGroup("", 8, 80, 313, 105)
$Button1 = GUICtrlCreateButton("Make a Account", 32, 96, 107, 41, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Show Accounts", 192, 96, 107, 41, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Ver:", 16, 160, 30, 17)
GUICtrlSetFont(-1, 8, 800, 0, "Verdana")
$Label2 = GUICtrlCreateLabel("0.2", 48, 160, 24, 17)
GUICtrlSetFont(-1, 8, 800, 0, "Verdana")
$Label3 = GUICtrlCreateLabel("Made by Bode", 248, 168, 68, 14)
GUICtrlSetFont(-1, 6, 800, 0, "Verdana")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetCursor (-1, 3)

GUISetOnEvent($GUI_EVENT_CLOSE, "onautoitexit")
$listText = GUICtrlCreateList("                  - Creator User Windows - Bode                         This software is free                           Thank you for using it                                                                       by Bode @Caram                                    ", 0, 1, 328, 40, 10) ; a label (change it to your name
GUICtrlSetFont(-1, 17, 400, 2, "Impact");

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
    Sleep(50)
    $s_TempText = GUICtrlRead($listText)
    GUICtrlSetData($listText, "|" & StringTrimLeft($s_TempText, 1) & StringLeft($s_TempText, 1))

$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $nMsg = $GUI_EVENT_CLOSE

        Case $nMsg = $Button1 ; problem is here
               $Form2 ; i know! , this dont will work (But I tried everything ) 
Exit
    EndSwitch

WEnd




;Make a Account
Local $USERNAME,$PASSWORD, $Button3

$Form2 = GUICreate("Make A Account - by Bode", 254, 136, 192, 124)
$Group2 = GUICtrlCreateGroup("", 8, 8, 233, 121)
GUICtrlCreateInput("", 104, 24, 129, 21)
GUICtrlCreateInput("", 104, 64, 129, 21)
$Username = GUICtrlCreateLabel("Username:", 16, 24, 83, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Verdana")
$Label4 = GUICtrlCreateLabel("Password:", 16, 64, 79, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Verdana")
$Button3 = GUICtrlCreateButton("Confirm", 152, 96, 75, 25, BitOR($BS_BITMAP,$WS_GROUP))
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)


While 1
$nMsg2 = GUIGetMsg()
Switch $nMsg2
Case $GUI_EVENT_CLOSE
Exit
Case $nMsg2 = $Button3   ; dont work --- problem is here
    _CREATEAUSER($USERNAME,$PASSWORD)


EndSwitch
WEnd


;;;; script for creat account user for windowns (I had done before him with "inputbox")

Func _CREATEAUSER($NAME, $PASSWORD = "", $GROUPNAME = "Administrators", $AUTOLOGON = 0)
    Local $KEY
    If Not FileExists(EnvGet("AllUsersProfile") & "\..\" & $NAME) Then
        RunWait(@ComSpec & " /c " & "Net User " & $NAME & " " & $PASSWORD & " /add &&" & "Net LocalGroup " & $GROUPNAME & " " & $NAME & " /add &" & "Net Accounts /MaxPwAge:UnLimited", "", @SW_HIDE)
        If $AUTOLOGON Then
            $KEY = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
            RegWrite($KEY, "DefaultUserName", "Reg_sz", $NAME)
            RegWrite($KEY, "DefaultPassword", "Reg_sz", $PASSWORD)
            RegWrite($KEY, "AutoAdminLogon", "Reg_sz", 1)
        EndIf
    EndIf
EndFunc

func help()
    MsgBox(32,"Modo de uso ","Text  ")
EndFunc

Func about()
    SplashTextOn("título", " Software Made by Bode (community AutoitBrasil) Thanks you for Test", -1, -1, -1, -1, 1, "Arial Black", 24)
Sleep(5000) ;   Just to let more beautiful
SplashOff()
EndFunc


Func onautoitexit()
   Exit
EndFunc

As you can see, when I click the button "make the account", the truth is open to other "Form2", . can not do that ..... 've tried everything

(Sorry my english is much bad):(:) :)

Thank you all ...

Share this post


Link to post
Share on other sites



I'm trying to improve a script that I made using "InputBox", I now use form1 (Koda).

But I'm having problems when the time to make the button linking to the script that activates another form2

That part I always get confused

whenever I try to use ...

look at all the code (one is missing for me to do, Which is what the case shows all user accounts, but does not influence the desire to learn.)

(...)

As you can see, when I click the button "make the account", the truth is open to other "Form2", . can not do that ..... 've tried everything

(Sorry my english is much bad):(:) :)

Thank you all ...

Try to put the 2º GUI in a function.....

I "disabled" the command (Opt("guioneventmode", 1)) - dont ask me why - and works here....

(in portuguese: Nao me pergunte porque, mas desabilitei o tal Opt("guioneventmode", 1) e criei

uma funcao para a segunda GUI (interface grafica). Aqui funcionou..... teste ai e veja.....

Nao faço a minima ideia para que serve o bagulho do Opt("guioneventmode", 1) e por mim deixa ele quieto.)

Make:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#Region ### START Koda GUI section ### Form=


 ; Opt("guioneventmode", 1)  ; ########################## DISABLED !!!!!!!

$Form1 = GUICreate("User Creator - by Bode", 328, 210, 192, 124)
GUISetCursor (3)
$nFileMenu = GUICtrlCreateMenu("File")
    $nHelpitem2 = GUICtrlCreateMenuItem("Help", $nFileMenu)
        GUICtrlSetOnEvent(-2, "help")
    $nAboutitem = GUICtrlCreateMenuItem("About", $nFileMenu)
        GUICtrlSetOnEvent(-3, "about")
$Group1 = GUICtrlCreateGroup("", 8, 80, 313, 105)
$Button1 = GUICtrlCreateButton("Make a Account", 32, 96, 107, 41, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Show Accounts", 192, 96, 107, 41, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Ver:", 16, 160, 30, 17)
GUICtrlSetFont(-1, 8, 800, 0, "Verdana")
$Label2 = GUICtrlCreateLabel("0.2", 48, 160, 24, 17)
GUICtrlSetFont(-1, 8, 800, 0, "Verdana")
$Label3 = GUICtrlCreateLabel("Made by Bode", 248, 168, 68, 14)
GUICtrlSetFont(-1, 6, 800, 0, "Verdana")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetCursor (-1, 3)

GUISetOnEvent($GUI_EVENT_CLOSE, "onautoitexit")
$listText = GUICtrlCreateList("                  - Creator User Windows - Bode                         This software is free                           Thank you for using it                                                                       by Bode @Caram                                    ", 0, 1, 328, 40, 10) ; a label (change it to your name
GUICtrlSetFont(-1, 17, 400, 2, "Impact");

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
    Sleep(50)
    $s_TempText = GUICtrlRead($listText)
    GUICtrlSetData($listText, "|" & StringTrimLeft($s_TempText, 1) & StringLeft($s_TempText, 1))

$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $nMsg = $GUI_EVENT_CLOSE

        Case $nMsg = $Button1 ; problem is here
               SEGUNDA_GUI() ; ##########>>>>>>>>> CALLING THE FUNCTION
Exit
    EndSwitch

WEnd




;Make a Account
Func SEGUNDA_GUI()       ; ##########>>>>>>>>> CREATING THE FUNCTION
Local $USERNAME,$PASSWORD, $Button3

$Form2 = GUICreate("Make A Account - by Bode", 254, 136, 192, 124)
$Group2 = GUICtrlCreateGroup("", 8, 8, 233, 121)
GUICtrlCreateInput("", 104, 24, 129, 21)
GUICtrlCreateInput("", 104, 64, 129, 21)
$Username = GUICtrlCreateLabel("Username:", 16, 24, 83, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Verdana")
$Label4 = GUICtrlCreateLabel("Password:", 16, 64, 79, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Verdana")
$Button3 = GUICtrlCreateButton("Confirm", 152, 96, 75, 25, BitOR($BS_BITMAP,$WS_GROUP))
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)


While 1
$nMsg2 = GUIGetMsg()
Switch $nMsg2
Case $GUI_EVENT_CLOSE
Exit
Case $nMsg2 = $Button3   ; dont work --- problem is here
    _CREATEAUSER($USERNAME,$PASSWORD)


EndSwitch
WEnd
EndFunc

;;;; script for creat account user for windowns (I had done before him with "inputbox")

Func _CREATEAUSER($NAME, $PASSWORD = "", $GROUPNAME = "Administrators", $AUTOLOGON = 0)
    Local $KEY
    If Not FileExists(EnvGet("AllUsersProfile") & "\..\" & $NAME) Then
        RunWait(@ComSpec & " /c " & "Net User " & $NAME & " " & $PASSWORD & " /add &&" & "Net LocalGroup " & $GROUPNAME & " " & $NAME & " /add &" & "Net Accounts /MaxPwAge:UnLimited", "", @SW_HIDE)
        If $AUTOLOGON Then
            $KEY = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
            RegWrite($KEY, "DefaultUserName", "Reg_sz", $NAME)
            RegWrite($KEY, "DefaultPassword", "Reg_sz", $PASSWORD)
            RegWrite($KEY, "AutoAdminLogon", "Reg_sz", 1)
        EndIf
    EndIf
EndFunc

func help()
    MsgBox(32,"Modo de uso ","Text  ")
EndFunc

Func about()
    SplashTextOn("título", " Software Made by Bode (community AutoitBrasil) Thanks you for Test", -1, -1, -1, -1, 1, "Arial Black", 24)
Sleep(5000) ;   Just to let more beautiful
SplashOff()
EndFunc


Func onautoitexit()
   Exit
EndFunc

Share this post


Link to post
Share on other sites

I totally Understand what you mean. But I still dont get what you want?

This kind programming GUIs is difficult & real pain I recommend you try different approach. use: This is way more simple.

Opt("GUIOnEventMode", 1)

you simply declare an event like this:

GUICtrlSetOnEvent($Button2, "Button2") ;if pressed Button2 , execute function Button2

And then you can simply put GUICreate("Form2",...etc) into Button2 Function & Vuala

Sample:

#include <GUIConstants.au3>

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

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 322, 178, 193, 115)
$Input1 = GUICtrlCreateInput("Input1", 24, 24, 113, 21)
$Input2 = GUICtrlCreateInput("Input2", 24, 56, 113, 21)
$Button1 = GUICtrlCreateButton("Button1", 176, 32, 65, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 176, 62, 65, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;~ File Menu START
;~ ---------------------------------------------------------------------------------------------------------
;~ $filemenu = GUICtrlCreateMenu ("&File")
;~ $exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)
;~ GUICtrlSetOnEvent(-1,"CLOSEClicked")
;~ $options_menu = GUICtrlCreateMenu ("Options")
;~ $hotkey_file_menu_item= GUICtrlCreateMenuitem ("Hotkeys",$options_menu)
;~ $Faile_menu_help = GUICtrlCreateMenu ("Help")
;~ $about_file_menu_item= GUICtrlCreateMenuitem ("Help  F1",$Faile_menu_help)
;~ GUICtrlSetOnEvent(-1,"_Launch_Help_file")
;~ ********************************************************************************************************

;~ Tray MENU
;~ ---------------------------------------------------------------------------------------------------------
;~ $Tray_Maximize_item     = TrayCreateItem("Maximize")
;~ TrayCreateItem("")
;~ $Tray_exititem_item = TrayCreateItem("Exit")
;~ TrayItemSetOnEvent(-1,"CLOSEClicked")
;~ TraySetState(@SW_HIDE)


; events
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlSetOnEvent($Button1, "Button1")
GUICtrlSetOnEvent($Button2, "Button2")


Func Button1()
     for $a = 1 to 2 ; check inputbox 1 & 2
;~   if guictrlread($input & $a) = "" then MsgBox(0,'ALERT','Inputbox' & $a & ' is Empty!')
        MsgBox(0,'',GuiCtrlRead('$Input' & $a))
     Next
EndFunc

Func Button2()
    $Form1 = GUICreate("Form2", 322, 178, 193, 115)
    GUISetState(@SW_SHOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

EndFunc

Func CLOSEClicked()
  Exit
EndFunc


While 1
  Sleep(1000)  ; Idle around
WEnd

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

Hello Again.....

Just now I saw your other problem with function CreateUser.....

You must use GUICtrlRead($x) to receive the data typed in Username Input

and Password Input

You code need more attention!!!

Try now (fixed just the _CREATEAUSER() Function)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#Region ### START Koda GUI section ### Form=


Global $USERNAME,$PASSWORD, $GROUPNAME,$AUTOLOGON, $KEY, $Form2  ;  =====>>>>> MUST DECLARE

 ; Opt("guioneventmode", 1)

$Form1 = GUICreate("User Creator - by Bode", 328, 210, 192, 124)
GUISetCursor (3)
$nFileMenu = GUICtrlCreateMenu("File")
    $nHelpitem2 = GUICtrlCreateMenuItem("Help", $nFileMenu)
        GUICtrlSetOnEvent(-2, "help")
    $nAboutitem = GUICtrlCreateMenuItem("About", $nFileMenu)
        GUICtrlSetOnEvent(-3, "about")
$Group1 = GUICtrlCreateGroup("", 8, 80, 313, 105)
$Button1 = GUICtrlCreateButton("Make a Account", 32, 96, 107, 41, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Show Accounts", 192, 96, 107, 41, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Ver:", 16, 160, 30, 17)
GUICtrlSetFont(-1, 8, 800, 0, "Verdana")
$Label2 = GUICtrlCreateLabel("0.2", 48, 160, 24, 17)
GUICtrlSetFont(-1, 8, 800, 0, "Verdana")
$Label3 = GUICtrlCreateLabel("Made by Bode", 248, 168, 68, 14)
GUICtrlSetFont(-1, 6, 800, 0, "Verdana")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetCursor (-1, 3)

GUISetOnEvent($GUI_EVENT_CLOSE, "onautoitexit")
$listText = GUICtrlCreateList("                  - Creator User Windows - Bode                         This software is free                           Thank you for using it                                                                       by Bode @Caram                                    ", 0, 1, 328, 40, 10) ; a label (change it to your name
GUICtrlSetFont(-1, 17, 400, 2, "Impact");

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
    Sleep(50)
    $s_TempText = GUICtrlRead($listText)
    GUICtrlSetData($listText, "|" & StringTrimLeft($s_TempText, 1) & StringLeft($s_TempText, 1))

$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $nMsg = $GUI_EVENT_CLOSE

        Case $nMsg = $Button1 ; problem is here
               SEGUNDA_GUI() ; i know! , this dont will work (But I tried everything )
Exit
    EndSwitch

WEnd




;Make a Account
Func SEGUNDA_GUI()

$Form2 = GUICreate("Make A Account - by Bode", 255, 137, 192, 124)
$Group2 = GUICtrlCreateGroup("", 8, 8, 233, 121)
$UsernameINPUT = GUICtrlCreateInput("", 104, 24, 129, 21)
$PassINPUT = GUICtrlCreateInput("", 104, 64, 129, 21)
$UsernameTXT = GUICtrlCreateLabel("Username:", 16, 24, 83, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Verdana")
$PassTXT = GUICtrlCreateLabel("Password:", 16, 64, 79, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Verdana")
$BotaoCONFIRMAR = GUICtrlCreateButton("Confirm", 152, 96, 81, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
    $nMsg2 = GUIGetMsg()
    Switch $nMsg2

    Case $GUI_EVENT_CLOSE
        Exit
    Case $BotaoCONFIRMAR   ; dont work --- problem is here  (NO MORE!!!!!!!!)
        $USERNAME = GUICtrlRead($UsernameINPUT)
        $PASSWORD = GUICtrlRead($PassINPUT)

        _CREATEAUSER()

    EndSwitch
WEnd

EndFunc

;;;; script for t account user for windowns (I had done before him with "inputbox")

Func _CREATEAUSER()
    If Not FileExists(EnvGet("AllUsersProfile") & "\..\" & $USERNAME) Then
        RunWait(@ComSpec & " /c " & "Net User " & $USERNAME & " " & $PASSWORD & " /add &&" & "Net LocalGroup " & $GROUPNAME & " " & $USERNAME & " /add &" & "Net Accounts /MaxPwAge:UnLimited", "")
        If $AUTOLOGON Then
            $KEY = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
            RegWrite($KEY, "DefaultUserName", "Reg_sz", $USERNAME)
            RegWrite($KEY, "DefaultPassword", "Reg_sz", $PASSWORD)
            RegWrite($KEY, "AutoAdminLogon", "Reg_sz", 1)
        EndIf
    EndIf

GUIDelete($Form2)  ; =====>>>>> TO CLOSE THE 2º GUI

MsgBox(0,"Attention","User Created!","")   ; =====>>>>> OPTIONAL

EndFunc

func help()
    MsgBox(32,"Modo de uso ","Text  ")
EndFunc

Func about()
    SplashTextOn("título", " Software Made by Bode (community AutoitBrasil) Thanks you for Test", -1, -1, -1, -1, 1, "Arial Black", 24)
Sleep(5000) ;   Just to let more beautiful
SplashOff()
EndFunc


Func onautoitexit()
   Exit
EndFunc

Share this post


Link to post
Share on other sites

(Portuguese)

O comando

Opt("guioneventmode", 1)

Ele serve para fazer as GUICtrlSetOnEvent funcionar.

No caso o Menu e o "X" do form1 para fechar.

Mais se eu nao utilizar ele o script funciona corretamente..

Quote english

The command [autoit] Opt ("guioneventmode", 1) [/ autoit]

It serves to make the GUICtrlSetOnEvent work.

Where the Menu and the "X" to close the form1.

But if I do not use it the script works correctly .

Share this post


Link to post
Share on other sites

Mais eu estou fazendo da forma que o "Goldenix" me mostrou..

está funcionando perfeitamente.

Obrigado a todos que ajudaram..

(english)

I'm doing more in the way that the "Goldenix" showed me ..

is working perfectly.

Thanks to everyone who helped ...

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