icadea Posted February 5, 2008 Share Posted February 5, 2008 Hi all, Need some guidance/pointers 1) I would like the GUI to show when the second instance of the same program is executed. Even If Not _Singleton("test") Then resgui() is set, when the second time the program is executed the GUI still remains in the taskbar and does not show in the desktop. The mouse have to hover above the trayicon to show the GUI. 2) How to ensure the GUI always remains in the fix position on everytime it comes back from the tray. Am using the latest autoit 3.2.10 on Win2000SP4. thanks. the code is provided below #include <Constants.au3> #include <GUIConstants.au3> #include <Misc.au3> Opt("TrayAutoPause", 0) Opt("TrayMenuMode", 1) Opt("TrayOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("GUICloseOnESC", 0) TraySetOnEvent($TRAY_EVENT_MOUSEOVER, "resgui") If Not _Singleton("test") Then resgui() $finweb = GUICreate("test", 107, 279, -1, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) GUISetBkColor(0xA6CAF0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE hidegui() EndSwitch WEnd Func hidegui() GUISetState(@SW_HIDE, $finweb) TraySetState(1) EndFunc ;==>hidegui Func resgui() TraySetState(2) GUISetState(@SW_SHOW, $finweb) EndFunc ;==>resgui Link to comment Share on other sites More sharing options...
rasim Posted February 5, 2008 Share Posted February 5, 2008 Hi! 2) expandcollapse popup#include <Constants.au3> #include <GUIConstants.au3> #include <Misc.au3> Opt("TrayAutoPause", 0) Opt("TrayMenuMode", 1) Opt("TrayOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("GUICloseOnESC", 0) Global $WinPos TraySetOnEvent($TRAY_EVENT_MOUSEOVER, "resgui") If Not _Singleton("test") Then resgui() $finweb = GUICreate("test", 107, 279, -1, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) GUISetBkColor(0xA6CAF0) GUISetState(@SW_SHOW) $WinPos = WinGetPos($finweb) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE hidegui() EndSwitch WEnd Func hidegui() GUISetState(@SW_HIDE, $finweb) TraySetState(1) WinMove($finweb, "", $WinPos[0], $WinPos[1]) EndFunc ;==>hidegui Func resgui() TraySetState(2) GUISetState(@SW_SHOW, $finweb) EndFunc ;==>resgui Link to comment Share on other sites More sharing options...
icadea Posted February 5, 2008 Author Share Posted February 5, 2008 Thanks rasim for the fixed post help. Can anyone help on the first question 1) I would like the GUI to show when the second instance of the same program is executed. Even If Not _Singleton("test") Then resgui() is set, when the second time the program is executed the GUI still remains in the taskbar and does not show in the desktop. The mouse have to hover above the trayicon to show the GUI. First, the test.exe program is executed. Second, program is minimized to the tray. Third if the test.exe program is executed again, it will maximize to show the gui from the trayicon as per the command If Not _Singleton("test") Then resgui() But it is not happening here. Please show some pointers what command need to be used to make this happen. thanks Link to comment Share on other sites More sharing options...
rover Posted February 5, 2008 Share Posted February 5, 2008 monitor for an instance of your scriptname with wmibetter than polling ProcessList in your message looplook for 'WMI Code Creator' and 'Scriptomatic' on this forum (any post by GEOSoft has a link in his Sig for scriptomatic)http://www.microsoft.com/downloads/details...;displaylang=enexpandcollapse popup; NOTE: compiled scriptname including '.exe' cannot be longer than 15 characters ; limitation of .ProcessName return from Win32_ProcessTrace, longer names cut off #include <Constants.au3> #include <GUIConstants.au3> #include <Misc.au3> Func OnAutoItStart() _Singleton("test gui",0) EndFunc Opt("TrayAutoPause", 0) Opt("TrayMenuMode", 1) Opt("TrayOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("GUICloseOnESC", 0) Opt("MustDeclareVars", 1) ; WMI Asynchronous mode - monitor for instance of scriptname Local $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") Local $strComputer = ".", $strQuery, $SINK, $objWMIService $strQuery = "Select ProcessID,ProcessName FROM Win32_ProcessTrace WHERE ProcessName='" $SINK = ObjCreate("WbemScripting.SWbemSink") ObjEvent($SINK, "SINK_") $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") If Not @error Then $objWMIService.ExecNotificationQueryAsync($SINK, $strQuery&@ScriptName&"'") EndIf Local $WinPos, $finweb, $nMsg TraySetOnEvent($TRAY_EVENT_MOUSEOVER, "resgui") $finweb = GUICreate("test gui", 107, 279, -1, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) GUISetBkColor(0xA6CAF0) GUISetState(@SW_SHOW) $WinPos = WinGetPos($finweb) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE hidegui() EndSwitch WEnd Func hidegui() GUISetState(@SW_HIDE, $finweb) TraySetState(1) WinMove($finweb, "", $WinPos[0], $WinPos[1]) EndFunc ;==>hidegui Func resgui() TraySetState(2) GUISetState(@SW_SHOW, $finweb) EndFunc ;==>resgui Func SINK_OnObjectReady($objLatestEvent) If $objLatestEvent.ProcessID <> @AutoItPID Then resgui() EndFunc ;==>SINK_OnObjectReady Func MyErrFunc() Local $HexNumber = Hex($oMyError.number,8) TrayTip("WMI Debug: Intercepted COM Error","Number = " & $HexNumber & " Windescription = " & $oMyError.windescription,5) SetError(1) Endfunc I see fascists... Link to comment Share on other sites More sharing options...
icadea Posted February 6, 2008 Author Share Posted February 6, 2008 thanks rover for the pointer and example. i'll check GEOSoft scriptomatic. Link to comment Share on other sites More sharing options...
rover Posted February 10, 2008 Share Posted February 10, 2008 my apologies, WMI Win32_ProcessTrace Classrequires WinXP and up!wont work in Win2000SP4http://msdn2.microsoft.com/en-us/library/a...377(VS.85).aspxthis version will work in 3.2.10.0 and earlier with AdlibEnableand beta 3.2.11.0 and up if new Timers UDF usedTimers UDF requires beta v3.2.11.0 and up for new Timers UDFRestore minimized script GUI from tray when second instance of script run and closed by Singleton()expandcollapse popup#include <Constants.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <Timers.au3> #include <Misc.au3> Func OnAutoItStart() If Not _Singleton("test gui",1) Then Exit(2) EndFunc Opt("TrayAutoPause", 0) Opt("TrayMenuMode", 1) Opt("TrayOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("GUICloseOnESC", 0) Opt("MustDeclareVars", 1) Local $WinPos, $finweb, $nMsg TraySetOnEvent($TRAY_EVENT_MOUSEOVER, "resgui") $finweb = GUICreate("test gui", 107, 279, -1, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) GUISetBkColor(0xA6CAF0) GUISetState(@SW_SHOW) $WinPos = WinGetPos($finweb) ;//////////////////// AdlibEnable("_RestoreGUI1", 250) ; - remove if using Timers UDF ;_Timer_SetTimer($finweb, 250, "_RestoreGUI2") ; - remove if using AdlibEnable ;//////////////////// While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE hidegui() EndSwitch WEnd Func hidegui() GUISetState(@SW_HIDE, $finweb) TraySetState(1) WinMove($finweb, "", $WinPos[0], $WinPos[1]) EndFunc ;==>hidegui Func resgui() TraySetState(2) GUISetState(@SW_SHOW, $finweb) EndFunc ;==>resgui ;//////////////////// ; AdlibEnable()- remove if using Timers UDF Func _RestoreGUI1() Local $plist = ProcessList(@ScriptName) Switch $plist[0][0] Case 1 Case Else resgui() EndSwitch EndFunc ;==>_RestoreGUI ;//////////////////// ; call back function - remove if using AdlibEnable Func _RestoreGUI2($hWnd, $Msg, $iIDTimer, $dwTime) #forceref $hWnd, $Msg, $iIDTimer, $dwTime Local $plist = ProcessList(@ScriptName) Switch $plist[0][0] Case 1 Case Else resgui() EndSwitch EndFunc ;==>_RestoreGUI ;//////////////////// Func OnAutoItExit() If @exitCode <> 2 Then GUIDelete($finweb) ;//////////////////// AdlibDisable() ; remove if using Timers UDF ;_Timer_KillAllTimers($finweb) ; remove if using AdlibEnable ;//////////////////// EndIf EndFunc I see fascists... Link to comment Share on other sites More sharing options...
icadea Posted February 10, 2008 Author Share Posted February 10, 2008 No problem rover . Am always grateful that people took their time to code and reply. Appreciate it. I was wondering why it was not working till i tested on different OS, than i searched through this forum for another solution. Seeing your code here is like godsend. thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now