MrCreatoR Posted April 14, 2020 Posted April 14, 2020 Ok, i am trying to figure out if it's possible to force #NoTrayIcon in my UDF, but still be able to give that option to the end user? Why i would need that? Here is an example: _Init() Func _Init() If $CmdLine[0] = 0 Or $CmdLine[1] <> '/MyID' Then ;Do something... Return EndIf ;Hide Tray Icon Opt('TrayIconHide', 1) ;Do something after the script started with command line... MsgBox(64, @ScriptName, $CmdLineRaw) Exit EndFunc Func _Start() ;Start new script instance with command line to handle something Local $iPID = Run(@AutoItExe & (@Compiled ? '' : ' "' & @ScriptFullPath & '"') & ' /MyID "Hello"') EndFunc So basically my UDF runs a second copy of my program with specific arguments, if i will not use #NoTrayIcon, the tray icon appears for a moment even if i use Opt('TrayIconHide', 1) right away. This is how it can be fixed: #NoTrayIcon Global $SHOW_TRAY_ICON = 1 _Init() Func _Init() If $CmdLine[0] = 0 Or $CmdLine[1] <> '/MyID' Then If $FE_SHOWTRAYICON Then Opt('TrayIconHide', 0) EndIf ;Do something... Return EndIf ;Do something after the script started with command line... MsgBox(64, @ScriptName, $CmdLineRaw) Exit EndFunc Func _Start() ;Start new script instance with command line to handle something Local $iPID = Run(@AutoItExe & (@Compiled ? '' : ' "' & @ScriptFullPath & '"') & ' /MyID "Hello"') EndFunc But then i force the user to mess with the UDF code if he needs the tray icon to be hidden on start. Yes i can make $SHOW_TRAY_ICON = 0 by default, but then other user that want his tray icon be shown will have to mess with the code and change it. Anyway it's not a solution (using #NoTrayIcon in the UDF), so i need to find a way to hide completely the tray icon for the new process. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
argumentum Posted April 14, 2020 Posted April 14, 2020 (edited) NoTrayIconOff() Func NoTrayIconOff() Local $i = 1, $n, $aMainScript = FileReadToArray(@ScriptFullPath) For $n = 0 To UBound($aMainScript) -1 If $aMainScript[$n] = "#NoTrayIcon" Then $i = 0 ExitLoop EndIf Next If $i Then TraySetState() EndFunc add this to your UDF. That should do it Edit: yes, you can add the "#NoTrayIcon" in your UDF, just add the above too. Edited April 14, 2020 by argumentum clarify a bit Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
TheDcoder Posted April 14, 2020 Posted April 14, 2020 @argumentum Nice work around but it won't work for compiled scripts. EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
MrCreatoR Posted April 14, 2020 Author Posted April 14, 2020 7 hours ago, argumentum said: add this to your UDF. That should do it Thanks, but as TheDcoder said it will not work for compiled script. I though that if we use #OnAutoItStartRegister, the function should be executed immediately on start, even before the other directives, but that's not the case. If you ask me, by default AutoIt script should be executed without any additional tray icon, and if user needs that icon, he should create it manually. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
seadoggie01 Posted April 14, 2020 Posted April 14, 2020 (edited) All your user needs to do is use the following line to show the Tray icon if you've compiled the script with #NoTrayIcon TraySetState($TRAY_ICONSTATE_SHOW) Per the example in the help file for TrayGetMsg Edit: Btw, this was helpful for me too, I didn't know this before and stumbled across it. AutoIt FTW again! Edited April 14, 2020 by seadoggie01 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
MrCreatoR Posted April 14, 2020 Author Posted April 14, 2020 35 minutes ago, seadoggie01 said: All your user needs to do is use the following line I have already mentioned that this is not a good solution (Opt('TrayIconHide', 0) is the same). I want to avoid #NoTrayIcon usage in my UDF. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
Bert Posted April 14, 2020 Posted April 14, 2020 could you do a count on the number of instances your program is running and if it sees one already running, then hide the tray icon? The Vollatran project My blog: http://www.vollysinterestingshit.com/
argumentum Posted April 14, 2020 Posted April 14, 2020 3 hours ago, MrCreatoR said: Thanks, but as TheDcoder said it will not work for compiled script. ...then let the user of the UDF code accordingly. I don't see a way around it. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
MrCreatoR Posted April 14, 2020 Author Posted April 14, 2020 14 minutes ago, Bert said: if it sees one already running, then hide the tray icon? Icon is hidden (but seen for a moment), i don't need to count for that. Changed example, it should be more clear now: _Init() For $i = 1 To 5 _Start() Next Func _Init() If $CmdLine[0] = 0 Or Not StringInStr($CmdLineRaw, '/MyID') Then ;Do something... Return EndIf ;Hide Tray Icon Opt('TrayIconHide', 1) ;Do something after the script started with command line... ;ConsoleWrite($CmdLineRaw) Exit EndFunc Func _Start() ;Start new script instance with command line to handle something Run(@AutoItExe & (@Compiled ? '' : ' "' & @ScriptFullPath & '"') & ' /MyID "Hello"') EndFunc Run it and look at the tray area. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
MrCreatoR Posted April 14, 2020 Author Posted April 14, 2020 I even thought to make something like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ScreenCapture.au3> #include <GDIPlus.au3> _Init() $aCamouflage = _Camouflage_Create() For $i = 1 To 5 _Start() WinActivate($aCamouflage[0]) Next _Camouflage_Delete($aCamouflage) Func _Init() If $CmdLine[0] = 0 Or Not StringInStr($CmdLineRaw, '/MyID') Then ;Do something... Return EndIf ;Hide Tray Icon ;Opt('TrayIconHide', 1) ;Do something after the script started with command line... ;ConsoleWrite($CmdLineRaw) Exit EndFunc Func _Start() ;Start new script instance with command line to handle something Run(@AutoItExe & (@Compiled ? '' : ' "' & @ScriptFullPath & '"') & ' /MyID "Hello"') EndFunc Func _Camouflage_Create() Local $hHBmp, $hGUI, $hGraphics, $hBMP $hHBmp = _ScreenCapture_Capture('', 0, 0, -1, -1, False) $hGUI = GUICreate('', @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) _GDIPlus_Startup() $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBMP = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) _WinAPI_DeleteObject($hHBmp) GUISetState(@SW_SHOWNOACTIVATE, $hGUI) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBMP, 0, 0, @DesktopWidth, @DesktopHeight) Local $aRet[3] = [$hGUI, $hGraphics, $hBMP] Return $aRet EndFunc Func _Camouflage_Delete($aCamouflage) _GDIPlus_GraphicsDispose($aCamouflage[1]) _GDIPlus_BitmapDispose($aCamouflage[2]) _GDIPlus_Shutdown() GUIDelete($aCamouflage[0]) EndFunc The idea is to make sort of camouflage to show the screen capture while the subscripts are executed, but it's a very lame workaround. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
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