Jump to content

New User Needs Help!


Nexus
 Share

Recommended Posts

Hi I am trying to run a menu that runs multiple windows but can't seem to get the newly opened windoe to function. maybe I'm putting the functions in the wrong place. Please help!!

This is the main menu:

#include <GUIConstants.au3>


Opt("GUIOnEventMode", 1); Change to OnEvent mode 
$mainwindow = GUICreate("Menu", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEWINDOW")
GUICtrlCreateLabel("Please choose an option", 40, 10)
$NewID = GUICtrlCreateButton("Create New User", 50, 50, 100)
GUICtrlSetOnEvent($NEWID, "NewID")
$Change = GUICtrlCreateButton("Change Password", 50, 100, 100)
GUICtrlSetOnEvent($CHANGE, "Change")
$Login = GUICtrlCreateButton("Login", 50, 150, 100)
GUICtrlSetOnEvent($LOGIN, "Login")
GUISetState(@SW_SHOW)

While 1
  Sleep(1000); Idle around
WEnd

Func CLOSEWINDOW()
;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, 
;and @GUI_WINHANDLE would equal $mainwindow 
  MsgBox(0, "Goodbye", "Thank you!")
  Exit
EndFunc

Func NEWID()
;Note: at this point @GUI_CTRLID would equal $okbutton,
;and @GUI_WINHANDLE would equal $mainwindow
  MsgBox(0, "GUI Event", "You pressed Create New User!")
EndFunc

Func CHANGE()
;Note: at this point @GUI_CTRLID would equal $okbutton,
;and @GUI_WINHANDLE would equal $mainwindow
  MsgBox(0, "GUI Event", "You pressed Change Password!")
EndFunc

Func Login()
;Note: at this point @GUI_CTRLID would equal $okbutton,
;and @GUI_WINHANDLE would equal $mainwindow
  MsgBox(0, "GUI Event", "You pressed Login!")
EndFunc

The first button "Create New User" is suppose to open up another window with the code below:

#include <GUIConstants.au3>


Opt("GUIOnEventMode", 1); Change to OnEvent mode 
$Newidwindow = GUICreate("New UserID and Password", 300, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSENEWID")
GuiCtrlCreateLabel("Please enter your new UserID and Password", 40, 10, 300)
GuiCtrlCreateLabel("UserID", 70, 50)
$CreateNewID = GuiCtrlCreateInput("", 130, 50, 100)
GuiCtrlCreateLabel("Password", 70, 100)
$CreateNewPW = GuiCtrlCreateInput("", 130, 100, 100)
$Create = GUICtrlCreateButton("Create", 50, 150, 100)
GUICtrlSetOnEvent($Create, "CREATE")
$Cancelcreate = GUICtrlCreateButton("Cancel", 170, 150, 100)
GUICtrlSetOnEvent($Cancelcreate, "CANCELCREATE")
GUISetState(@SW_SHOW)

While 1
  Sleep(1000); Idle around
WEnd

Func CLOSENEWID()
;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, 
;and @GUI_WINHANDLE would equal $mainwindow 
  Exit
EndFunc

Func CANCELCREATE()
;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, 
;and @GUI_WINHANDLE would equal $mainwindow 
  Exit
EndFunc

Func CREATE()
;Note: at this point @GUI_CTRLID would equal $okbutton,
;and @GUI_WINHANDLE would equal $mainwindow
  MsgBox(0, "GUI Event", "You pressed Create!")
EndFunc

How do I get them to work?

Thanks in advance for any help you can offer me

Edited by Nexus
Link to comment
Share on other sites

I'm not sure but i think you have to use #include<path to your 2nd window file> in the first part ( or combine the two ). Then keep the 2nd window hidden. Only use the command GUISetState(@SW_SHOW) for your 2nd window only when the user clicks the button.

Edited by steveR
AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.
Link to comment
Share on other sites

Thanks for trying pal.

I've tried to combine the 2 and the code as follows:

#include <GUIConstants.au3>


Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 
$mainwindow = GUICreate("Menu", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEWINDOW")
GUICtrlCreateLabel("Please choose an option", 40, 10)
$NewID = GUICtrlCreateButton("Create New User", 50, 50, 100)
GUICtrlSetOnEvent($NEWID, "NewID")
$Change = GUICtrlCreateButton("Change Password", 50, 100, 100)
GUICtrlSetOnEvent($CHANGE, "Change")
$Login = GUICtrlCreateButton("Login", 50, 150, 100)
GUICtrlSetOnEvent($LOGIN, "Login")
GUISetState(@SW_SHOW)

While 1
  Sleep(1000) ; Idle around
WEnd

Func CLOSEWINDOW()
 ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, 
 ;and @GUI_WINHANDLE would equal $mainwindow 
  MsgBox(0, "Goodbye", "Thank you!")
  Exit
EndFunc

Func NEWID()
 ;Note: at this point @GUI_CTRLID would equal $okbutton,
 ;and @GUI_WINHANDLE would equal $mainwindow
  Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 
  $Newidwindow = GUICreate("New UserID and Password", 300, 200)
  GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSENEWID")
  GuiCtrlCreateLabel("Please enter your new UserID and Password", 40, 10, 300)
  GuiCtrlCreateLabel("UserID", 70, 50)
  $CreateNewID = GuiCtrlCreateInput("", 130, 50, 100)
  GuiCtrlCreateLabel("Password", 70, 100)
  $CreateNewPW = GuiCtrlCreateInput("", 130, 100, 100)
  $Create = GUICtrlCreateButton("Create", 50, 150, 100)
  GUICtrlSetOnEvent($Create, "CREATE")
  $Cancelcreate = GUICtrlCreateButton("Cancel", 170, 150, 100)
  GUICtrlSetOnEvent($Cancelcreate, "CANCELCREATE")
  GUISetState(@SW_SHOW)

  While 1
    Sleep(1000) ; Idle around
  WEnd

  Func CLOSENEWID()
   ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, 
   ;and @GUI_WINHANDLE would equal $mainwindow 
    Exit
  EndFunc

  Func CANCELCREATE()
   ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, 
   ;and @GUI_WINHANDLE would equal $mainwindow 
    Exit
  EndFunc

  Func CREATE()
   ;Note: at this point @GUI_CTRLID would equal $okbutton,
   ;and @GUI_WINHANDLE would equal $mainwindow
    MsgBox(0, "GUI Event", "You pressed Create!")
  EndFunc
EndFunc

Func CHANGE()
 ;Note: at this point @GUI_CTRLID would equal $okbutton,
 ;and @GUI_WINHANDLE would equal $mainwindow
  MsgBox(0, "GUI Event", "You pressed Change Password!")
EndFunc

Func Login()
 ;Note: at this point @GUI_CTRLID would equal $okbutton,
 ;and @GUI_WINHANDLE would equal $mainwindow
  MsgBox(0, "GUI Event", "You pressed Login!")
EndFunc

but I can't seem to run the code, it always says that there is no matching "EndFunc". Is it that you can't call a function in a function?

How do you use the GUISetState(@SW_SHOW) to how the specific window you want if there are going to be many windows?

Link to comment
Share on other sites

Guest Guidosoft

@Nexus:

Welcome to AutoIt Forums,

May your rotten skills of AutoIt condemn you to the firey depths of hell.

I hope your time here is a horrible misserable one, and that we will get to know each other quite well. :lmao:o:):)

JK. THis is how I greet all newbies. HAHAHAHAHAHA!!!

Link to comment
Share on other sites

Yeah you can't have functions within other functions. But you can call functions from withen other functions.

GUISetState ( @SW_SHOW, $winhandle )

where $winhandle = the Windows handle as returned by GUICreate (default is the previously used window).

AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.
Link to comment
Share on other sites

Thank you phillip123adams & steveR for the help and Guidosoft for the warm welcome. My skills are indeed rotten :lmao: . Ok so this is the code I have gathered so far, I've did some cleaning up, moved the functions out and placed the GUISetState ( @SW_SHOW, $Newidwindow ) in Func NEWID():

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1); Change to OnEvent mode 
$mainwindow = GUICreate("Menu", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEWINDOW")
GUICtrlCreateLabel("Please choose an option", 40, 10)
$NewID = GUICtrlCreateButton("Create New User", 50, 50, 100)
GUICtrlSetOnEvent($NEWID, "NewID")
$Change = GUICtrlCreateButton("Change Password", 50, 100, 100)
GUICtrlSetOnEvent($CHANGE, "Change")
$Login = GUICtrlCreateButton("Login", 50, 150, 100)
GUICtrlSetOnEvent($LOGIN, "Login")
GUISetState(@SW_SHOW)

While 1
  Sleep(1000); Idle around
WEnd

Func CLOSEWINDOW()
  MsgBox(0, "Goodbye", "Thank you!")
  Exit
EndFunc

Func NEWID()
  Opt("GUIOnEventMode", 1); Change to OnEvent mode 
  $Newidwindow = GUICreate("New UserID and Password", 300, 200)
  GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSENEWID")
  GuiCtrlCreateLabel("Please enter your new UserID and Password", 40, 10, 300)
  GuiCtrlCreateLabel("UserID", 70, 50)
  $CreateNewID = GuiCtrlCreateInput("", 130, 50, 100)
  GuiCtrlCreateLabel("Password", 70, 100)
  $CreateNewPW = GuiCtrlCreateInput("", 130, 100, 100)
  $Create = GUICtrlCreateButton("Create", 50, 150, 100)
  GUICtrlSetOnEvent($Create, "CREATE")
  $Cancelcreate = GUICtrlCreateButton("Cancel", 170, 150, 100)
  GUICtrlSetOnEvent($Cancelcreate, "CANCELCREATE")
  GUISetState ( @SW_SHOW, $Newidwindow ) 

  While 1
    Sleep(1000); Idle around
  WEnd

EndFunc

Func CHANGE()
  MsgBox(0, "GUI Event", "You pressed Change Password!")
EndFunc

Func Login()
  MsgBox(0, "GUI Event", "You pressed Login!")
EndFunc

Func CLOSENEWID()
  Exit
EndFunc

Func CANCELCREATE()
  Exit
EndFunc

Func CREATE()
  MsgBox(0, "GUI Event", "You pressed Create!")
EndFunc

The program runs now, but after I open the NewID window, I can't get any of the buttons to function. I can't even close the new window to go back to the previous window. Sorry to trouble you guys time and time again but I really couldn't find any codes out there similar to what I wanna do. If you guys can help me correct the code or direct me to something similar to it, that will be awesome!

Link to comment
Share on other sites

I suggest you use the height parameter for all the controls.

It's possible that the default height is overlapping other controls.

<{POST_SNAPBACK}>

Height parameter? Can you give me more details please?
Link to comment
Share on other sites

get rid of

While 1
    Sleep(1000); Idle around
  WEnd
in the NewID() function, it's an infinite loop.

Also you only need to declare the guiOnEventMode once in your program ( keep the one at the top )

And lower your Sleep() parameter, it can sometimes cause your gui to be sluggish if its high.

here it is corrected:

CODE

;

#include <GUIConstants.au3>

;

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

;

$mainwindow = GUICreate("Menu", 200, 200)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEWINDOW")

;

GUICtrlCreateLabel("Please choose an option", 40, 10)

$NewID = GUICtrlCreateButton("Create New User", 50, 50, 100)

GUICtrlSetOnEvent($NewID, "NewID")

;

$Change = GUICtrlCreateButton("Change Password", 50, 100, 100)

GUICtrlSetOnEvent($Change, "Change")

;

$Login = GUICtrlCreateButton("Login", 50, 150, 100)

GUICtrlSetOnEvent($Login, "Login")

;

GUISetState(@SW_SHOW)

;

While 1

Sleep(100); Idle around

WEnd

;

Func CLOSEWINDOW()

MsgBox(0, "Goodbye", "Thank you!")

Exit

EndFunc ;==>CLOSEWINDOW

;

Func NEWID()

$Newidwindow = GUICreate("New UserID and Password", 300, 200)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSENEWID")

;

GUICtrlCreateLabel("Please enter your new UserID and Password", 40, 10, 300)

GUICtrlCreateLabel("UserID", 70, 50)

;

$CreateNewID = GUICtrlCreateInput("", 130, 50, 100)

GUICtrlCreateLabel("Password", 70, 100)

;

$CreateNewPW = GUICtrlCreateInput("", 130, 100, 100)

$Create = GUICtrlCreateButton("Create", 50, 150, 100)

GUICtrlSetOnEvent($Create, "CREATE")

;

$Cancelcreate = GUICtrlCreateButton("Cancel", 170, 150, 100)

GUICtrlSetOnEvent($Cancelcreate, "CANCELCREATE")

;

GUISetState(@SW_SHOW, $Newidwindow)

EndFunc ;==>NEWID

;

Func CHANGE()

MsgBox(0, "GUI Event", "You pressed Change Password!")

EndFunc ;==>CHANGE

;

Func Login()

MsgBox(0, "GUI Event", "You pressed Login!")

EndFunc ;==>Login

;

Func CLOSENEWID()

Exit

EndFunc ;==>CLOSENEWID

;

Func CANCELCREATE()

Exit

EndFunc ;==>CANCELCREATE

;

Func CREATE()

MsgBox(0, "GUI Event", "You pressed Create!")

EndFunc ;==>CREATE

;

Edited by steveR
AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.
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...