Cybergon Posted April 12 Share Posted April 12 Hi, I have a script that runs in a console user interface and I'd like for it to minimize to system tray or even better close to system tray. Most of the search results I find are related to GUI which doesn't quite work for me. Is it even possible? Or should I completely rewrite my code to work on GUI? Link to comment Share on other sites More sharing options...
Trong Posted April 12 Share Posted April 12 (edited) This code runs a test on the computer - Windows 11 24H2 LTSC - Autoit version: 3.3.16.1 #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** If @Compiled < 1 Then MsgBox(48 + 262144, "TEST CUI - You have not compiled yet!", "Let's compile the script with CUI to try it out!", 10) Exit EndIf Local $hDOS = WinGetHandle("[CLASS:ConsoleWindowClass]") If Not $hDOS Then WinGetTitle("[active]") ConsoleWrite("Hello" & @CRLF) WinSetState($hDOS, '', @SW_HIDE) Sleep(2000) WinSetState($hDOS, '', @SW_SHOW) Sleep(2000) WinSetState($hDOS, '', @SW_MINIMIZE) Sleep(2000) WinSetState($hDOS, '', @SW_MAXIMIZE) Sleep(2000) WinSetState($hDOS, '', @SW_RESTORE) Sleep(2000) ConsoleWrite("Move" & WinMove($hDOS, '', @DesktopHeight, @DesktopWidth) & @CRLF) Sleep(2000) ConsoleWrite("Restore Move" & WinMove($hDOS, '', 10, 10) & @CRLF) Sleep(3000) ConsoleWrite("Move" & WinMove($hDOS, '', @DesktopHeight, @DesktopWidth) & @CRLF) Sleep(2000) ConsoleWrite("Restore Move" & WinMove($hDOS, '', 10, 10) & @CRLF) Sleep(3000) You should rewrite script using GUI to make it easier to control than using CUI Edited April 12 by Trong Regards, Link to comment Share on other sites More sharing options...
Nine Posted April 12 Share Posted April 12 (edited) Or something like this : #NoTrayIcon #include <Constants.au3> #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) Opt("TrayAutoPause", 0) HotKeySet("{ESC}", Terminate) If Not @Compiled Then Exit MsgBox($MB_OK, "Error", "The script needs to be compiled") Local $hWnd = WinGetHandle("[CLASS:ConsoleWindowClass]") While Sleep(100) If BitAND(WinGetState($hWnd), $WIN_STATE_MINIMIZED) Then WinSetState($hWnd, "", @SW_HIDE) TraySetIcon("shell32.dll", 16) TraySetOnEvent($TRAY_EVENT_PRIMARYUP, Restore) TraySetState($TRAY_ICONSTATE_SHOW) TraySetToolTip("Left click to restore") EndIf WEnd Func Terminate() Exit EndFunc Func Restore() TraySetState($TRAY_ICONSTATE_HIDE) WinSetState($hWnd, "", @SW_SHOW) WinActivate($hWnd) EndFunc ;==>GUI_Restore Edited April 12 by Nine simplified code “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Cybergon Posted April 15 Author Share Posted April 15 Thanks for the answers, fellas. Sorry I kind of forgot about this thread, I'm just using RBTray so it's all good. Cheers! 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