C
C#2y ago
dom

✅ Minimize to tray

I've googled, used chat gpt, and done everything I can think of but I can't find a way to minimise my application to tray. What I want to minimize is the Console, if theres a way I can write text in a window that looks like a cmd but isn't the console that would make it easier to minimise to tray please help tell me. I can send the code i've got right now and keep in mind I am a beginner and started today.
41 Replies
Thinker
Thinker2y ago
you click this button catsip
dom
domOP2y ago
yea but that minimises to task bar i want it to minimize to tray
Pobiega
Pobiega2y ago
Not really doable with a console app afaik since you need a gui handle to make a trey icon
dom
domOP2y ago
is there a way I can make something that looks like this other than logging to console?
dom
domOP2y ago
dom
domOP2y ago
and slowly like
Pobiega
Pobiega2y ago
or rather, its doable, but you'll essentially be making a winforms app
dom
domOP2y ago
loads text with delay
Pobiega
Pobiega2y ago
¯\_(ツ)_/¯
dom
domOP2y ago
tf is winforms
Thinker
Thinker2y ago
a GUI framework You're using the console, pretty much the only way to put thing on the screen is to write it to the console
dom
domOP2y ago
yea so is there a way to make it go to tray
dom
domOP2y ago
when i click that
Thinker
Thinker2y ago
However you can do this.
dom
domOP2y ago
with winforms?
Thinker
Thinker2y ago
with just the console
dom
domOP2y ago
yea ik i use Thread.Sleep(150); or somethinmg like that idk im new
Thinker
Thinker2y ago
that or await Task.Delay(150);
dom
domOP2y ago
yea but im tryna get it to do this
dom
domOP2y ago
so it looks better in my opinion and idk if task.delay would work havent tried
Pobiega
Pobiega2y ago
If you want to write a "fancy" console app, consider using $spectre
MODiX
MODiX2y ago
Spectre.Console is a .NET library that allows for easy creation of console UIs, text formatting in the console, and command-line argument parsing. https://spectreconsole.net/
Spectre.Console - Welcome!
Spectre.Console is a .NET library that makes it easier to create beautiful console applications.
Pobiega
Pobiega2y ago
what does your application do once it detects a roblox instance btw?
dom
domOP2y ago
it closes it and thats it so far
Pobiega
Pobiega2y ago
but.. why? and what do you want it to do at a later stage?
dom
domOP2y ago
cuz its going to inject an fps unlocker
Pobiega
Pobiega2y ago
that sounds like violating roblox TOS
dom
domOP2y ago
its not
Pobiega
Pobiega2y ago
injecting ANYTHING into their client will 100% violate their TOS
dom
domOP2y ago
a roblox dev said it isnt bannable or against tos same with shaders
Pobiega
Pobiega2y ago
If you can link me the exact paragraph of the TOS where it says "injecting custom code into our executables is fine", that would be swell
dom
domOP2y ago
bro it changes a file not the application running
Pobiega
Pobiega2y ago
Users may not ... (b) copy, modify, distribute, publicly perform or display, reverse engineer, disassemble, modify, or create derivative works of the Services or related or implemented technology ...
thats a direct violation of paragraph 6
dom
domOP2y ago
idk idrc its an fps unlocker im recreating an already existing one
Pobiega
Pobiega2y ago
Can you pop over to #info-and-rules and re-read our rules
dom
domOP2y ago
im not making it inject something there u go i was joking lol
Pobiega
Pobiega2y ago
keep in mind that discord has a very unusual TOS paragraph that forbids violating OTHER products TOS
dom
domOP2y ago
huh yea but that lags your game
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
arion
arion2y ago
Regarding the topic of tracking minimizes on console apps. I believe this is possible using WinEventHooks albeit a unusual (we're using PInvoke) In my case I am using 2 specific Nuget Packages
Vanara.PInvoke.Kernel32
Vanera.PInvoke.User32
Vanara.PInvoke.Kernel32
Vanera.PInvoke.User32
The attached screenshot shows two respective events being written to the console 22 (Minimize (Start)) 23 (Minimize (End)) (Not minimized) Coupled with a possible tray icon via WinForms on some other thread maybe. You can use User32.ShowWindow to hide / show the console window (SW_HIDE is 0 and SW_SHOWNORMAL is 1) Attached is the proof of concept code:
namespace Lab23;

using Vanara.PInvoke;

internal static class LabTest28
{
internal static void Init()
{

var h_Console = Kernel32.GetConsoleWindow();


var h_Hook = User32.SetWinEventHook(
User32.EventConstants.EVENT_SYSTEM_MINIMIZESTART,
User32.EventConstants.EVENT_SYSTEM_MINIMIZEEND,
new HINSTANCE(h_Console.DangerousGetHandle()),
_winEventProc, 0, 0, User32.WINEVENT.WINEVENT_OUTOFCONTEXT

);

if (h_Hook == IntPtr.Zero)
{
Console.WriteLine("Failed to set hook.");
Environment.Exit(-1);
}

else
{
// Console.WriteLine("Hook set successfully.");

HastilyWrittenMessageLoop();
}
}

private static void HastilyWrittenMessageLoop()
{
while (User32.GetMessage(out var msg) > 0 && msg.message != (int)User32.WindowMessage.WM_QUIT)
{
User32.TranslateMessage(msg);
User32.DispatchMessage(msg);
}
}

private static readonly User32.WinEventProc _winEventProc = (hook, @event, hwnd, idObject, child, thread, time) =>
{
Console.WriteLine("Event: {0}", @event);
};

}
namespace Lab23;

using Vanara.PInvoke;

internal static class LabTest28
{
internal static void Init()
{

var h_Console = Kernel32.GetConsoleWindow();


var h_Hook = User32.SetWinEventHook(
User32.EventConstants.EVENT_SYSTEM_MINIMIZESTART,
User32.EventConstants.EVENT_SYSTEM_MINIMIZEEND,
new HINSTANCE(h_Console.DangerousGetHandle()),
_winEventProc, 0, 0, User32.WINEVENT.WINEVENT_OUTOFCONTEXT

);

if (h_Hook == IntPtr.Zero)
{
Console.WriteLine("Failed to set hook.");
Environment.Exit(-1);
}

else
{
// Console.WriteLine("Hook set successfully.");

HastilyWrittenMessageLoop();
}
}

private static void HastilyWrittenMessageLoop()
{
while (User32.GetMessage(out var msg) > 0 && msg.message != (int)User32.WindowMessage.WM_QUIT)
{
User32.TranslateMessage(msg);
User32.DispatchMessage(msg);
}
}

private static readonly User32.WinEventProc _winEventProc = (hook, @event, hwnd, idObject, child, thread, time) =>
{
Console.WriteLine("Event: {0}", @event);
};

}
arion
arion2y ago
Downsides would be: if hosted within something like Windows Terminal or other parent attached processes, it would track the parent. (You minimize Windows Terminal and you would hide windows terminal and all its tabs) You Minimize Rider or Visual Studio Code, you hide those programs to the tray too since they're running your code This can be mitigated by getting the parent process' name, if any then not doing this if there is an attached parent.
Want results from more Discord servers?
Add your server