Jump to content

Minimized to Tray Doesn Not Work


Recommended Posts

I have a working code here which Im having a problem:

#include <GUIConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode",1)

$title = "Untitled - Notepad"
$text=""
$fullTest = WinExistsExact($title, $text)
$PASSWORD = "password"
$retryCount = 0
$stop = 1

; Prevent standard Windows events
;Opt("GUIEventOptions", 1)

; Remove standard tray menu items
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)

; Create tray menu
Global $cTray_Show = TrayCreateItem("Show")
TrayItemSetOnEvent($cTray_Show, "_Show_GUI")
$About = TrayCreateItem("Help")
TrayItemSetOnEvent($About, "_About")
TrayCreateItem("")
Global $cTray_Exit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

$iParent_Win = WinGetHandle(AutoItWinGetTitle())

GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")

While 1
    if $retryCount > 0 then Exit
    $input = InputBox("Password Protected", "Enter the password to continue", "", "*")
    If @error Or $input <> $PASSWORD Then
        MsgBox(4096,"Error", "Incorrect Password")
        $retryCount = $retryCount + 1
    Else
        ;MsgBox(4096,"Success", "Password Accepted")
        ExitLoop
    EndIf
 Wend

If $fullTest = 1 Then
    ;MsgBox(0, "WINDOW", "Press Ok to continue")
    $hWnd = GUICreate("WINDOWS", 241, 78)
    ;$label = GUICtrlCreateInput ("test", 10, 10, 50, 20)
    GuiSetOnEvent($GUI_EVENT_CLOSE,"Quit")
    $button = GUICtrlCreateButton ("Start",  18, 31, 100, 25)
    $button1 = GUICtrlCreateButton ("Hide",  128, 31, 91, 25)
    GuiCtrlSetOnEvent($button,"DoScript")
    GuiCtrlSetOnEvent($button1,"DoScript1")
    GUISetState (@SW_SHOW)
    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
Else
    MsgBox(0, "WINDOWS", "You need to run WINDOW first.")
 EndIf

While 1
   Sleep(10)
Wend

Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    If BitAND($wParam, 0xFFF0) = 0xF060 Then Exit   ;$SC_CLOSE = 0xF060
    Return $GUI_RUNDEFMSG
EndFunc

Func DoScript1()
    WinSetState($hWnd, "", @SW_HIDE)
EndFunc

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
     If BitAND($wParam, 0x0000FFFF) =  $button Then
          $stop = not $stop
          If $stop = 0 Then GUICtrlSetData($button, "Stop")
          If $stop = 1 Then GUICtrlSetData($button, "Start")
     EndIf
     Return $GUI_RUNDEFMSG
EndFunc

Func WinExistsExact($title, $text)
    AutoItSetOption( "WinTitleMatchMode", $OPT_MATCHEXACT )
    $res = WinExists($title, $text)
    AutoItSetOption( "WinTitleMatchMode", $OPT_MATCHSTART )
    Return $res
EndFunc

Func DoScript()
   While 1
    For $i = 1 to 300
        Sleep (10)
        If $stop = 1 Then Return
       ; GuiCtrlSetData($label, $i)
    Next
    ControlSend ( $title, "", 0, "{Right}")
    $a = Random(300, 900, 1)
    For $i = 1 to $a
        Sleep (10)
        If $stop = 1 Then Return
    Next
    ControlSend ( $title, "", 0, "{Left}")
    $a = Random(100, 500, 1)
    For $i = 1 to $a
        Sleep (10)
        If $stop = 1 Then Return
        Next
   WEnd
EndFunc

Func _Show_GUI()
   WinSetState($hWnd, "", @SW_SHOW)
 EndFunc

Func _About()
    MsgBox(4096,"Test", "Test")
EndFunc

 Func _Exit()
    Exit
EndFunc

Func Quit()
    Exit
 EndFunc

The "Hide" button which I created does not minimized the window to tray when the program has started. What should I do to enable the button? In this code, the button only works if the start DoScript() is not working. What I wanted to do is to hide the window even if the DoScript() is running.

Thank!

Link to post
Share on other sites
  • Moderators

Kyou,

Read the Interrupting a running function tutorial in the Wiki - that will explain what you need to do. If you still have questions, come back and I will try and help you get it working.

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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...