Jump to content

Help neede: Gui not working when created minimized/hidden


Recommended Posts

Hello,

I hope you can help me out on this:

I tried to create a gui which also has a tray icon and which minimizes to tray,

Everything works just fine when i start the gui with @SW_SHOW and then minimze it by clicking on the _ button of the GUI.

But when i start it with @SW_MINIMIZED and then restore it from the tray, the GUI button does not work (the X Button still does work).

What am i doing wrong here?

Here is my minimal code to show the problem:

#include <GUIConstants.au3>
Opt("TrayMenuMode", 3)
TraySetIcon("Shell32.dll", -87)
TraySetClick(9)

$RestoreTray = TrayCreateItem("Show")
$ExitTray = TrayCreateItem("Close")
$guiname = "MyGUI"

$main_gui = GUICreate($guiname, 200, 200)
$idclosewin = GUICtrlCreateButton("Close", 10, 10)

;GUISetState(@SW_MINIMIZE, $main_gui)
GUISetState(@SW_SHOW, $main_gui)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_MINIMIZE
            $winstate = WinGetState($main_gui)
            If BitAND($winstate, 16) Or Not BitAND($winstate, 2) Then
                WinSetState($main_gui, "", @SW_HIDE)
            EndIf
        Case $GUI_EVENT_CLOSE, $idclosewin
            Exit
    EndSwitch

    Switch TrayGetMsg()
        Case $RestoreTray
            WinSetState($main_gui, "", @SW_RESTORE)
        Case $ExitTray
            Exit
    EndSwitch
WEnd

 

Link to comment
Share on other sites

  • Moderators

ESPUser,

Your script works fine for me - the button exits the script every time.

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

So if you uncomment GUISetState(@SW_MINIMIZE, $main_gui) and comment out GUISetState(@SW_SHOW, $main_gui)  the script starts with only a tray icon and you can then restore the gui from the tray icon with the Show command and you can then exit the gui with the X and the Close button as well?

When i do this, the GUI X works fine all the time, but the close button only works when i start the script with SW_SHOW

 

Link to comment
Share on other sites

I added some Console output to research the problem:

#include <GUIConstants.au3>
Opt("TrayMenuMode", 3)
TraySetIcon("Shell32.dll", -87)
TraySetClick(9)

$RestoreTray = TrayCreateItem("Show")
$ExitTray = TrayCreateItem("Close")
$guiname = "MyGUI"

$main_gui = GUICreate($guiname, 200, 200)
$idclosewin = GUICtrlCreateButton("Close", 10, 10)
ConsoleWrite("$idclosewin: " & $idclosewin & @CRLF)

GUISetState(@SW_MINIMIZE, $main_gui)
;GUISetState(@SW_SHOW, $main_gui)

While 1
    $msg = GUIGetMsg()
    If $msg <> 0 And $msg <> -11 Then ConsoleWrite("$msg: " & $msg & @CRLF)
    Switch $msg
        Case $GUI_EVENT_MINIMIZE
            $winstate = WinGetState($main_gui)
            If BitAND($winstate, 16) Or Not BitAND($winstate, 2) Then
                WinSetState($main_gui, "", @SW_HIDE)
            EndIf
        Case $GUI_EVENT_CLOSE, $idclosewin
            Exit
    EndSwitch

    Switch TrayGetMsg()
        Case $RestoreTray
            WinSetState($main_gui, "", @SW_RESTORE)
        Case $ExitTray
            Exit
    EndSwitch
WEnd

i will get -7 and -8 every time i click the close button after i started minimized. When i start with SW_show i will get -- and 3 vor ervery close button click

$idclosewin: 3
$msg: -7
$msg: -8
$msg: -7
$msg: -8
$msg: -7
$msg: -8
$msg: -3

Link to comment
Share on other sites

  • Moderators

ESPUser,

You are mixing GUISetState and WinSetState, which usually ends in tears. As you are dealing with your own GUI, stick with GUISetState like this:

#include <GUIConstants.au3>
Opt("TrayMenuMode", 3)
TraySetIcon("Shell32.dll", -87)
TraySetClick(9)

$RestoreTray = TrayCreateItem("Show")
$ExitTray = TrayCreateItem("Close")
$guiname = "MyGUI"

$main_gui = GUICreate($guiname, 200, 200)
$idclosewin = GUICtrlCreateButton("Close", 10, 10)
ConsoleWrite("$idclosewin: " & $idclosewin & @CRLF)

;GUISetState(@SW_SHOW, $main_gui)
GUISetState(@SW_MINIMIZE, $main_gui)

While 1
    $msg = GUIGetMsg()
    If $msg <> 0 And $msg <> -11 Then ConsoleWrite("$msg: " & $msg & @CRLF)
    Switch $msg
        ; Let AutoIt do the work for you <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        ;Case $GUI_EVENT_MINIMIZE
            ;$winstate = WinGetState($main_gui)
            ;If BitAND($winstate, $WIN_STATE_MINIMIZED) Or Not BitAND($winstate, $WIN_STATE_VISIBLE) Then
                ;GUISetState(@SW_HIDE, $main_gui)
            ;EndIf
        Case $GUI_EVENT_CLOSE, $idclosewin
            Exit
    EndSwitch

    Switch TrayGetMsg()
        Case $RestoreTray
            GUISetState(@SW_RESTORE, $main_gui) ; Restore the GUI <<<<<<<<<<<<<<<<
            GUISetState(@SW_SHOW, $main_gui) ; But the first time you have to show it as well! <<<<<<<<<<<
        Case $ExitTray
            Exit
    EndSwitch
WEnd

I have added comments to explain what I think is going on. Does it work for you too?

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 for the hint about wingetstate and guisetstate.

Does it work -well, almost.

Without the lines you commented out it starts up just fine and can be restored from the tray.

The close button also works, but i can no longer minimize to tray.

Any idea how to solve this?

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