Jump to content
Kyou

Minimized to Tray Button

Recommended Posts

I have a working code here. 

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

Opt("GUIOnEventMode",1)

$title = "WINDOW"
$text=""
$fullTest = WinExistsExact($title, $text)
$PASSWORD = "PASS"
$retryCount = 0
$stop = 1  ;<<<<<<<<<<<<<<<<<<<<<<<<<

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")
    GUICreate("WINDOW", 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) ; <----- THIS IS THE BUTTON
    GuiCtrlSetOnEvent($button,"DoScript")
    GUISetState (@SW_SHOW)
    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")  ;<<<<<<<<<<<<<<<<<<<<<
Else
    MsgBox(0, "WINDOW", "You need to run WINDOW client first.")
 EndIf

While 1
   Sleep(10)
Wend

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, "{F12}")
    $a = Random(300, 900, 1)
    For $i = 1 to $a
        Sleep (10)
        If $stop = 1 Then Return
    Next
    ControlSend ( $title, "", 0, "{Del}")
    $a = Random(100, 500, 1)
    For $i = 1 to $a
        Sleep (10)
        If $stop = 1 Then Return
        Next
   WEnd
EndFunc

Func Quit()
    Exit
 EndFunc

What I wanted to do is to make the 'Hide' button minimized the entire window when clicked and while it is on tray, there will be a menu if a user right clicked on it. Exactly what the code below should do.

#NoTrayIcon
#include <guiconstantsex.au3>
#include <constants.au3>
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)
; Create tray menu items and set the events
$About = TrayCreateItem("About")
TrayItemSetOnEvent($About, "_About")
TrayCreateItem("") ; Create a separator line.
$Exit = TrayCreateItem("Exit")
TrayItemSetOnEvent($Exit, "_Exit")
; Set the action if you left click on the tray icon
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "SpecialEvent")
; Show the menu if the icon is right clicked
TraySetClick(8)
Global $MainGui = GUICreate("TestGUI", 392, 316, -1, -1)
GUISetState()
;Test()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_MINIMIZE
            ; Hide the GUI
            GUISetState(@SW_HIDE)
            ; Show the icon
   TraySetState(1)
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
Func SpecialEvent()
    ; Show the GUI
    GUISetState(@SW_SHOW)
    GUISetState(@SW_RESTORE)
    ; Hide the icon
    TraySetState(2)
EndFunc   ;==>SpecialEvent
Func _About()
    MsgBox(0,0,"Test")
EndFunc
Func _Exit()
    Exit
EndFunc

My problem is I cannot integrate this code to the one I have. Can anyone help me with this? I would be very much thankful as I am just starting to learn.

Share this post


Link to post
Share on other sites

Hello
This can Help :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("{ESC}","_Exit")
$hWnd = GUICreate("", 400, 300, -1, -1, BitOR($WS_POPUPWINDOW,$WS_CLIPCHILDREN, $WS_CLIPSIBLINGS))
$Bt = GUICtrlCreateButton("Exit", 280, 250, 90, 30)
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()

        Switch $msg
            Case $Bt
                Exit
        EndSwitch

WEnd
Func _Exit()
    Exit
    EndFunc

 

Share this post


Link to post
Share on other sites

Hello
This can Help :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("{ESC}","_Exit")
$hWnd = GUICreate("", 400, 300, -1, -1, BitOR($WS_POPUPWINDOW,$WS_CLIPCHILDREN, $WS_CLIPSIBLINGS))
$Bt = GUICtrlCreateButton("Exit", 280, 250, 90, 30)
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()

        Switch $msg
            Case $Bt
                Exit
        EndSwitch

WEnd
Func _Exit()
    Exit
    EndFunc

 

Actually no but thanks for trying to help.

Share this post


Link to post
Share on other sites

Kyou,

Take a look at this:

#include <GUIConstantsEx.au3>

; 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")
TrayCreateItem("")
Global $cTray_Exit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

; Get handle of hidden AutoIt GUI
$iParent_Win = WinGetHandle(AutoItWinGetTitle())

; Create GUI as child of Autoit GUI - no task bar icon
$hGUI = GUICreate("Test", 500, 500, Default, Default, Default, Default, $iParent_Win)
GUISetState()

While 1
    Switch GUIGetMsg()
        ; These events are just reported - not actioned

        Case $GUI_EVENT_CLOSE, $GUI_EVENT_MINIMIZE
            ; Hide GUI
            GUISetState(@SW_HIDE, $hGUI)
    EndSwitch

WEnd



Func _Show_GUI()
    GUISetState(@SW_SHOW, $hGUI)
EndFunc



Func _Exit()
    Exit
EndFunc

Any use?

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

 

Share this post


Link to post
Share on other sites

Kyou,

Take a look at this:

#include <GUIConstantsEx.au3>

; 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")
TrayCreateItem("")
Global $cTray_Exit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

; Get handle of hidden AutoIt GUI
$iParent_Win = WinGetHandle(AutoItWinGetTitle())

; Create GUI as child of Autoit GUI - no task bar icon
$hGUI = GUICreate("Test", 500, 500, Default, Default, Default, Default, $iParent_Win)
GUISetState()

While 1
    Switch GUIGetMsg()
        ; These events are just reported - not actioned

        Case $GUI_EVENT_CLOSE, $GUI_EVENT_MINIMIZE
            ; Hide GUI
            GUISetState(@SW_HIDE, $hGUI)
    EndSwitch

WEnd



Func _Show_GUI()
    GUISetState(@SW_SHOW, $hGUI)
EndFunc



Func _Exit()
    Exit
EndFunc

Any use?

M23

This is exactly what I wanted but how can I use "Hide" button here instead of the actual minimize button?

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

Opt("GUIOnEventMode",1)

$title = "WINDOW"
$text=""
$fullTest = WinExistsExact($title, $text)
$PASSWORD = "PASS"
$retryCount = 0
$stop = 1  ;<<<<<<<<<<<<<<<<<<<<<<<<<

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")
    GUICreate("WINDOW", 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) ; <----- THIS IS THE BUTTON
    GuiCtrlSetOnEvent($button,"DoScript")
    GUISetState (@SW_SHOW)
    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")  ;<<<<<<<<<<<<<<<<<<<<<
Else
    MsgBox(0, "WINDOW", "You need to run WINDOW client first.")
 EndIf

While 1
   Sleep(10)
Wend

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, "{F12}")
    $a = Random(300, 900, 1)
    For $i = 1 to $a
        Sleep (10)
        If $stop = 1 Then Return
    Next
    ControlSend ( $title, "", 0, "{Del}")
    $a = Random(100, 500, 1)
    For $i = 1 to $a
        Sleep (10)
        If $stop = 1 Then Return
        Next
   WEnd
EndFunc

Func Quit()
    Exit
 EndFunc

The minimize button should minimize the window in the task bar while the Hide button should minimize the window to tray.

Thanks in advance!

Share this post


Link to post
Share on other sites

Kyou,

Firstly, when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily.

Just ad a "Hide" button to the GUI and then add its ControlID to the list of events in the Switch structure which will hide the GUI.

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

 

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

  • Similar Content

    • By MONaH-Rasta
      Opt('TrayAutoPause', 0) $iTray1 = TrayCreateItem('Tray 1') TrayItemSetState(-1, 1) TrayCreateItem('') $iTrayMenu1 = TrayCreateMenu('Tray Menu 1') $iTray2 = TrayCreateItem('Tray 2', $iTrayMenu1, -1, 1) TrayItemSetState(-1, 1) $iTray3 = TrayCreateItem('Tray 3', $iTrayMenu1, -1, 1) $iTray4 = TrayCreateItem('Tray 4', $iTrayMenu1, -1, 1) TrayCreateItem('') $iTrayMenu2= TrayCreateMenu('Tray Menu 2') $iTray5 = TrayCreateItem('Tray 5', $iTrayMenu2, -1, 1) TrayItemSetState(-1, 1) $iTray6 = TrayCreateItem('Tray 6', $iTrayMenu2, -1, 1) $iTray7 = TrayCreateItem('Tray 7', $iTrayMenu2, -1, 1) TrayCreateItem('') $iTray8 = TrayCreateItem('Tray 8') $iTray9 = TrayCreateItem('Tray 9') $iTray10 = TrayCreateItem('Tray 10') TrayItemSetState(-1, 1) While True Sleep(1000*5) WEnd When I click on Tray 3 / Tray 4 / Tray 6 / Tray 7 nothing happens. Only Tray 2 and Tray 5 stay checked.
      I have tried setting 
      Opt("TrayMenuMode", 8) In this case radio menuitems act like normal menuitems only looks different.
      I'm using AutoIt v3.3.14.5.
      Tested on Windows 10 LTSC 2019 (1809) x64 version: 10.0.17763 build 17763.475 and Windows Server 2008 R2.
      Tried run script x64 and x86 same result.
      Is this kind a bug or something?
    • By argumentum
      So I'm coding in win 10, ..every thing looks nice but then I think, what about XP, ...ugly, but I make it pretty again, no problem. Lets check in Win 7 and here is my conundrum.
      Win 10, DRM is on, XP is off ( well, non-existant ), so far so good. I decide to make it the "switch" to enable or disable the checkbox in the context menu.
      Win 7 ... I try to apply the same logic and:
      DRM on:

       
      DRM off:

       
      now, "Windows 7 Basic": DRM is off


      Question: how should I determine if to hide the check-mark or not?, Is there a way to know that this theme is ? or better yet, how can I know that the theme is classic ?
      Thanks
      PS: I know that the code is not here but I think that my trend of thought would make it irrelevant anyway.
       
    • By ur
      I need to read the status of OneDrive icon running in the taskbar and update the status in a log file.
      2nd part I can complete
      But the first part, how to read the status of tray menu icon.

      I need the text above from the tray icon.
      I looked into , but not that helpful.
       
       
    • By WoodGrain
      Hi All,
      I'm using UseTraySetIcon("shell32.dll", xx) to set my tray icon to a specific icon while running, is there a way I can specify this icon when I compile my script into an exe so my exe icon is the same?
      Thanks!
    • By 9252Survive
      Hello Guys, 
      Is there a way to have Auto it Exe messages/line number when you hover over the tray icon just at it shows when you run Au3.?
      For an example, if I the script has paused due to WinWait or Sleep I could hover over the icon and it shows the line where it's at. Is there a way to achieve the same with the compiled exe? 
      Many thanks for the help! 
       
×
×
  • Create New...