Sign in to follow this  
Followers 0
BlackHoleSun

Keep window hidden before @SW_HIDE

9 posts in this topic

I have an about window and while the program loads you can see it flash while it goes through the code before getting to GUISetState(@SW_HIDE). My question is, how to I keep the window hidden from the beginning? Some of the code is below:

$aboutWindow = GUICreate("About", 200, 225)
$aboutClose = GUICtrlCreateButton("&OK", 75, 200, 50, 20)
GUISetState(@SW_HIDE)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I threw it into it's own function, and that works.

Edited by BlackHoleSun

Share this post


Link to post
Share on other sites

Now that it has it's own function, when I close the window I can't close the main window without using the Task Manager.

Share this post


Link to post
Share on other sites

Give me detail about your problem, post the full code?

Share this post


Link to post
Share on other sites

Here's the full code:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $msg
    
    ;Main Program
    Local $programWindow
    
    Local $fileMenu, $openMenu, $seperatorBar, $exitMenu
    Local $helpMenu, $aboutMenu
    
    $programWindow = GUICreate("My Program", 300, 300, (@DesktopWidth - 300) / 2, (@DesktopHeight - 300) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
    
    $fileMenu = GUICtrlCreateMenu("&File")
    $openMenu = GUICtrlCreateMenuItem("Open &Notepad", $fileMenu)
    $seperatorBar = GUICtrlCreateMenuItem("", $fileMenu)
    $exitMenu = GUICtrlCreateMenuItem("E&xit", $fileMenu)
    
    $helpMenu = GUICtrlCreateMenu("&Help")
    $aboutMenu = GUICtrlCreateMenuItem("&About", $helpmenu)
    GUISetState(@SW_SHOW)
    
    While 1
        $msg = GUIGetMsg(1)
        
        Select
            Case $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $exitMenu
                GUISwitch($aboutWindow)
                GUIDelete()
                GUISwitch($programWindow)
                GUIDelete()
                Exit
            
            Case $msg[0] = $openMenu
                Run("notepad.exe")
                ProcessWaitClose("notepad.exe")
                MsgBox(0, "Notepad", "The notepad should be closed")
                
            Case $msg[0] = $aboutMenu
                _About()
                
        EndSelect
    WEnd
    
    GUISetState()

    GUIDelete()
    Exit
EndFunc   ;==>_Main

Func _About()
    ;About Window
    Local $aboutWindow, $msg
    Local $aboutLabel, $aboutClose
    
    $aboutWindow = GUICreate("About", 200, 225, (@DesktopWidth - 200) / 2, (@DesktopHeight - 225) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
    $aboutLabel = GUICtrlCreateLabel("Version", 0, 0, 200, 17)
    GUICtrlCreateLabel("Developed by Me", 0, 102, 200, 17)
    GUICtrlSetBkColor($aboutLabel, 0xffffff)
    $aboutClose = GUICtrlCreateButton("&OK", 75, 200, 50, 20)
    
    GUISetState()
    
    While 1
        $msg = GUIGetMsg()
        
        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $aboutClose
                GUISetState(@SW_HIDE)
                
        EndSelect
    WEnd
    Exit
EndFunc    ;==>_About

Share this post


Link to post
Share on other sites

BlackHoleSun,

You were not returning from the _About() function. ;)

I have made a few more changes - take a look: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $msg

    ;Main Program
    Local $programWindow

    Local $fileMenu, $openMenu, $seperatorBar, $exitMenu
    Local $helpMenu, $aboutMenu

    $programWindow = GUICreate("My Program", 300, 300, (@DesktopWidth - 300) / 2, (@DesktopHeight - 300) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

    $fileMenu = GUICtrlCreateMenu("&File")
    $openMenu = GUICtrlCreateMenuItem("Open &Notepad", $fileMenu)
    GUICtrlCreateMenuItem("", $fileMenu)
    $exitMenu = GUICtrlCreateMenuItem("E&xit", $fileMenu)

    $helpMenu = GUICtrlCreateMenu("&Help")
    $aboutMenu = GUICtrlCreateMenuItem("&About", $helpMenu)
    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg() ; No need for the advanced parameter

        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $exitMenu
                Exit ; <<<<<<<<<<<<<<<< No need to delete the GUIs (and certainly not GUISwitch to them) - just exit!

            Case $msg = $openMenu
                Run("notepad.exe")
                ProcessWaitClose("notepad.exe")
                MsgBox(0, "Notepad", "The notepad should be closed")

            Case $msg = $aboutMenu
                _About()

        EndSelect
    WEnd

EndFunc   ;==>_Main

Func _About()
    ;About Window
    Local $aboutWindow, $msg
    Local $aboutLabel, $aboutClose

    Local $aboutWindow = GUICreate("About", 200, 225, (@DesktopWidth - 200) / 2, (@DesktopHeight - 225) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
    $aboutLabel = GUICtrlCreateLabel("Version", 0, 0, 200, 17)
    GUICtrlCreateLabel("Developed by Me", 0, 102, 200, 17)
    GUICtrlSetBkColor($aboutLabel, 0xffffff)
    $aboutClose = GUICtrlCreateButton("&OK", 75, 200, 50, 20)

    GUISetState()

    While 1
        $msg = GUIGetMsg()

        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $aboutClose
                GUIDelete($aboutWindow) ; <<<<<<<<<<<<<<<<<<<< Delete it or you waste resources by keeping the old one each time
                Return ; <<<<<<<<<<<<<<<<< You need to return the main function
        EndSelect
    WEnd
    Exit
EndFunc   ;==>_About

You might find the Managing Multiple GUIs tutorial in the Wiki of interest - it shows how you do use the "advanced" parameter with GUIGetMsg. :P

Please ask if you have any questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Case $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $exitMenu
  ;              GUISwitch($aboutWindow) <<<<<<<<<<<< you don't need these lines, when you close the 
  ;             GUIDelete()              <<<<<<<<<<<< main window, it closes both at the same time
                GUISwitch($programWindow)
                GUIDelete()
                Exit

See the changes to your window close code above.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

BlackHoleSun,

I have created this a while ago for another program of mine and it looks like it is exactly what you want... ;)

Try this:

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#NoTrayIcon

Opt("TrayMenuMode", 1)
Opt('MustDeclareVars', 0)
Opt("GUICloseOnESC", 1)     ;1=ESC closes window when ESC is pressed
;main window global variables
    Global $msgMain, $mainWindow, $mainWidth = 460, $mainHeight = 350 ;main window width & height
    Local $fileMenu, $openMenu, $seperatorBar, $exitMenu
    Local $helpMenu, $aboutMenu
    Global $childOpen ;Group Pro Version
;child window global positioning variables
Global $childWidth = 300    ;reg window width
Global $childHeight = 150 ;reg window height
Global $childLeft = ($mainWidth - $childWidth)/2 ;child left position from main window
Global $childTop = ($mainHeight - $childHeight)/2 ;child top position from main window

MainGui()

Func MainGui()
    $mainWindow = GUICreate("Main Window", $mainWidth, $mainHeight) ; will create a dialog box that when displayed is centered
    GUISetBkColor(0xE0FFFF) ; will change background color
    $fileMenu = GUICtrlCreateMenu("&File")
    $openMenu = GUICtrlCreateMenuItem("Open &Notepad", $fileMenu)
    GUICtrlCreateMenuItem("", $fileMenu)
    $exitMenu = GUICtrlCreateMenuItem("E&xit", $fileMenu)
    $helpMenu = GUICtrlCreateMenu("&Help")
    $aboutMenu = GUICtrlCreateMenuItem("&About", $helpMenu)

    GUISetState(@SW_SHOW)

    ; Run the GUI until the window is closed
    While 1
    $msgMain = GUIGetMsg()
    Select
    Case $msgMain = $GUI_EVENT_CLOSE
    ExitLoop
    Case $msgMain = $aboutMenu
    About_Window()
    
    EndSelect
    WEnd
    GUIDelete()
    Exit    
EndFunc ;==>MainGui


Func About_Window()
Local $pos = WinGetPos("Main Window") ;get position of main window
    Local $x = $pos[0] + $childLeft ;set child x position
    Local $y = $pos[1] + $childTop ;set child y position
Global $childWindow = GUICreate("Child Window", $childWidth, $childHeight, $x, $y, $GUI_SS_DEFAULT_GUI, $WS_EX_TOOLWINDOW, $mainWindow)
GUISetBkColor(0xE0FFbb) ; will change background color
 
$aboutLabel = GUICtrlCreateLabel("Version", 0, 0, 200, 17)
    GUICtrlCreateLabel("Developed by Me", 0, 50, 200, 17)
    GUICtrlSetBkColor($aboutLabel, 0xffffff)

Global $cmdCancel = GUICtrlCreateButton("&Cancel" , 125, 115, 80, 25)

    GUISetState(@SW_DISABLE, $childWindow)
    GUISetState(@SW_SHOW, $childWindow)
    _GUICtrlButton_Enable($cmdCancel, True)
    GUISetState(@SW_ENABLE, $childWindow) 
    While 1
        $msgChild = GuiGetMsg($childWindow)
        Select
        Case $msgChild = $GUI_EVENT_CLOSE
        GUISetState(@SW_HIDE, $childWindow)
        ExitLoop
        Case $msgChild = $cmdCancel
        GUISetState(@SW_HIDE, $childWindow)
        ExitLoop

        EndSelect
    WEnd
EndFunc ;==>Child window

Share this post


Link to post
Share on other sites

BlackHoleSun,

You were not returning from the _About() function. ;)

I have made a few more changes - take a look: ;)

You might find the Managing Multiple GUIs tutorial in the Wiki of interest - it shows how you do use the "advanced" parameter with GUIGetMsg. :P

Please ask if you have any questions. :)

M23

The return did it, and I cleaned up some of the other code. Thanks!!

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