Jump to content

Creating Multiple Windows


MooglePower
 Share

Recommended Posts

I am trying to create one window after another. So, for example, there would be one window in which users type in information, and then there would be another window that pops up after some actions have been accomplished with another option (actually, just one button that you can click that "cleans up" and then closes everything).

So far, what seems to happen is that the program works fine until I get to the second window. When I call GUISwitch($logoutwin) and then GUISetState(@SW_SHOW), it creates two windows. One is the first window and the other is the second. Neither of the windows do anything. I have to force quit.

Can someone help me out and tell me what I'm doing wrong? I define both windows close to the beginning, but I've tried it out by defining one window inside of the other's button's action function and the same thing happens. Please let me know if you can help out at all.

Link to comment
Share on other sites

As I don't see any code I'll just speculate. Perhaps you need to use GUIDelete to really get rid of a window -- if that's what you want. Also, GUISetState accepts an additional parameter, the window handle. So to be sure you might want to use GUISetState(@SW_SHOW, $logoutwin).

Link to comment
Share on other sites

Great, thanks for the GUIDelete function. That's what I was looking for.

Unfortunately, the button still doesn't work as scripted. I still have to force quit the program. I can't show all of the source code, but I can show a bit.

;Logout window
$logoutwin = GUICreate("XRDS Logout",100,100)
GUISetOnEvent($GUI_EVENT_CLOSE,"LogoutButton")
$logoutbutton = GUICtrlCreateButton("Logout",0,0,100,100)
GUICtrlSetOnEvent($logoutbutton,"LogoutButton")

GUIDelete($loginwin)
GUISetState(@SW_SHOW,$logoutwin)

Func LogoutButton()
    Exit
EndFunc

As I don't see any code I'll just speculate. Perhaps you need to use GUIDelete to really get rid of a window -- if that's what you want. Also, GUISetState accepts an additional parameter, the window handle. So to be sure you might want to use GUISetState(@SW_SHOW, $logoutwin).

Link to comment
Share on other sites

  • Moderators

MooglePower,

A slightly belated welcome to the Autoit forum.

You need to set OnEvent mode and then hang around long enough to wait for it - like this: :mellow:

#include <GUIConstantsEx.au3>

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

;Logout window
$logoutwin = GUICreate("XRDS Logout",100,100)
GUISetOnEvent($GUI_EVENT_CLOSE,"LogoutButton")
$logoutbutton = GUICtrlCreateButton("Logout",0,0,100,100)
GUICtrlSetOnEvent($logoutbutton,"LogoutButton")

;GUIDelete($loginwin)
GUISetState(@SW_SHOW,$logoutwin)

While 1
    Sleep(10)
WEnd

Func LogoutButton()
    Exit
EndFunc

As you obvoiusly have very little idea about coding in AutoIt (nothing wrong there - we all started at that point! :lol: ) reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here. There are even video tutorials on YouTube if you prefer watching to reading.

I know you want to start coding NOW, but a little study will save you a lot of trouble later on, believe me. :(

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

*chuckles* I know what you mean. Unfortunately, it's for work, so I'm kinda trying to learn as I go.

I had already included the following code into my script:

While 1
Sleep(1000)
Wend

I'm still not sure quite what's up. All of this (except for the GUI definition code) is in the LoginButton() function and that function is called from a button on the first window.

I'm going to start going through the tutorials now.

MooglePower,

A slightly belated welcome to the Autoit forum.

You need to set OnEvent mode and then hang around long enough to wait for it - like this: :mellow:

#include <GUIConstantsEx.au3>

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

;Logout window
$logoutwin = GUICreate("XRDS Logout",100,100)
GUISetOnEvent($GUI_EVENT_CLOSE,"LogoutButton")
$logoutbutton = GUICtrlCreateButton("Logout",0,0,100,100)
GUICtrlSetOnEvent($logoutbutton,"LogoutButton")

;GUIDelete($loginwin)
GUISetState(@SW_SHOW,$logoutwin)

While 1
    Sleep(10)
WEnd

Func LogoutButton()
    Exit
EndFunc

As you obvoiusly have very little idea about coding in AutoIt (nothing wrong there - we all started at that point! :lol: ) reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here. There are even video tutorials on YouTube if you prefer watching to reading.

I know you want to start coding NOW, but a little study will save you a lot of trouble later on, believe me. :(

M23

Link to comment
Share on other sites

  • Moderators

MooglePower,

If you get stuck, just post your code - we are here to help if we can! Just do not post 100s of lines and say "It does not work!" - that tends to get a pretty frosty response. :mellow:

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

Thanks! Here is what I can show of the code without giving away too much info.

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>

Opt("GUIOnEventMode",1)
;Login window
$loginwin = GUICreate("Login",250,125)
GUISetOnEvent($GUI_EVENT_CLOSE,"ExitFunc")
GUICtrlCreateLabel("Login",20,10)
GUICtrlCreateLabel("Username:",20,35)
GUICtrlCreateLabel("Password:",20,60)
$loginbutton = GUICtrlCreateButton("&Login",180,90,60)
$theusernamein = GUICtrlCreateInput("",75,35,150,20)
$thepasswordin = GUICtrlCreateInput("",75,60,150,20,$ES_PASSWORD)
GUICtrlSetOnEvent($loginbutton,"LoginButton")

;Logout window
$logoutwin = GUICreate("Logout",100,100)
GUISetOnEvent($GUI_EVENT_CLOSE,"LogoutButton")
$logoutbutton = GUICtrlCreateButton("Logout",0,0,100,100)
GUICtrlSetOnEvent($logoutbutton,"LogoutButton")
    
GUISetState(@SW_SHOW,$loginwin)
Send("+{TAB}")
Send("+{TAB}")
While 1
    Sleep(1000)
Wend

Func ExitFunc()
    Exit
EndFunc

Func WinPlusD()
    Send("{LWINDOWN}")
    Send("d")
    Send("{LWINUP}")
EndFunc

Func LoginButton()
    ;@DesktopDir returns the location of the desktop
    $theusername = GUICtrlRead($theusernamein)
    $thepassword = GUICtrlRead($thepasswordin)
    WinPlusD()
    Sleep(1000)
    Send($theusername)
    Send("{ENTER}")
    ;WinWaitActive("") ;This is the window of the login prompt
    ;Send($theusername)
    ;Send(@TAB)
    ;Send($thepassword)
    ;Send(@TAB)
    ;Send("{ENTER}") ;Login info has been entered into the window at this point
    GUIDelete($loginwin)
    GUISetState(@SW_SHOW,$logoutwin)
    ;GUISetState(@SW_SHOW,$logoutwin)
    ;@GUI_WINHANDLE = $logoutwin
    While 1
        Sleep(1000)
    Wend
EndFunc

Func LogoutButton()
    Exit
EndFunc

Stuff that's been commented out hasn't been implemented yet. Thank you again!

MooglePower,

If you get stuck, just post your code - we are here to help if we can! Just do not post 100s of lines and say "It does not work!" - that tends to get a pretty frosty response. :mellow:

M23

Edited by MooglePower
Link to comment
Share on other sites

I forgot to mention that the code I posted above does everything except execute the LogoutButton function when you click on Logout. Does anyone have any clue as to what's going on here?

You trap the script in that infinite loop in LoginButton(), you have to fix that :mellow:
Link to comment
Share on other sites

  • Moderators

MooglePower,

As the Admiral has already pointed out, you are trapping your script in the infinite loop at the end of the LoginButton() function - just remove the While...WEnd loop in the final 3 lines.

You only need the one idle loop in a script. AutoIt functions run consecutively, so you have to let one finish before the next can begin (with a few exceptions like HotKeys and Adlib). So putting an infinite loop in a function is a pretty good way of hanging the script. A good tip: use Opt("TrayIconDebug", 1) to get the current line appearing in the tray icon tooltip - that often leads to a "Eureka" moment when a script starts becoming unresponsive! :mellow:

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

Great, thanks so much! That fixed it up. I'll let you know if any more problems arise. Thanks again for being such a big help.

MooglePower,

As the Admiral has already pointed out, you are trapping your script in the infinite loop at the end of the LoginButton() function - just remove the While...WEnd loop in the final 3 lines.

You only need the one idle loop in a script. AutoIt functions run consecutively, so you have to let one finish before the next can begin (with a few exceptions like HotKeys and Adlib). So putting an infinite loop in a function is a pretty good way of hanging the script. A good tip: use Opt("TrayIconDebug", 1) to get the current line appearing in the tray icon tooltip - that often leads to a "Eureka" moment when a script starts becoming unresponsive! :mellow:

M23

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