Jump to content

Accessing Tray in the middle of script


Edun
 Share

Recommended Posts

Somehow I think this is quite simple task to do but for some reason I wasn't able to find solution by myself from help file or forums. So shortly what my script does is wait for active windows and performs functions after that. Like:

While 1
   Sleep(100)

   If WinActive("Window1","") Then func1()

   If WinActive("Window2","") Then func2()

   If WinActive("Window3","") Then func3()

WEnd

I have also created a GUI for some settings which I run before this while loop and it works ok. But now I was wondering how to access that menu afterwards. I have built the tray system for that but obviously it won't respond to any buttons when my script is performing a function or waiting for active windows since it needs TrayGetMsg() for that. Please help the idiot :sweating:

-Edun

 

Edited by Edun
Link to comment
Share on other sites

55 minutes ago, kylomas said:

Please post a reproducer.

 

Do you mean like example script?

This would be a example. How can I access this GUI afterwards using Tray. As you can see right now my script will make the tray options visible but I won't be able to click anything from there since my code is looping. This script writes "My name is Edun" to a window named "help" (tested in notepad). If I check the box it will also write the date after it. How can I return to my GUI using tray options to check or uncheck the box?

This code is probably horror to you guys and not sure if I could explain this correctly.

 

#include <Misc.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <IE.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <GUIToolTip.au3>
#NoTrayIcon
#include <TrayConstants.au3>
Opt("TrayMenuMode", 3)


#Region GUI START
Global $MainGUI = GUICreate("Test GUI", 444, 369, 570, 196)

Global $option1 = GUICtrlCreateCheckbox("Check if you want the date", 8, 40, 161, 17)
GUICtrlSetState(-1, $GUI_CHECKED)

Global $okbutton = GUICtrlCreateButton("Ok", 24, 328, 97, 33)
Global $cancelbutton = GUICtrlCreateButton("Cancel", 304, 328, 97, 33)
#EndRegion GUI END

#Region Tray start
Global $idSettings = TrayCreateItem("Settings") ;
TrayCreateItem("") ; Create a separator line.
Global $idExit = TrayCreateItem("Exit")

TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.
#EndRegion Tray end



GUISetState(@SW_SHOW) ;Set GUI visible

RunGui()

Func RunGui()
   While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
         Case $GUI_EVENT_CLOSE, $cancelbutton
            Exit
         Case $okbutton
            GUISetState(@SW_HIDE, $MainGUI)
            ExitLoop
       EndSwitch
   WEnd
EndFunc


While 1
   Sleep(100)

   If WinActive("help","") Then examplefunc() ;help is the name of notepad file

WEnd

While 1
   Switch TrayGetMsg()
      Case $idSettings
         RunGui()

      Case $idExit
          ExitLoop
   EndSwitch
WEnd


Func examplefunc()
   WinWaitActive("help")
   Send("My name is Edun")
   If GUICtrlRead($option1) = $GUI_CHECKED Then
      Send(" and the date is " & _NowDate())
   EndIf
Sleep(10000)
EndFunc

 

Edited by Edun
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...