Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Minimizing to System Tray

Status
Not open for further replies.

kmfna

MIS
Sep 26, 2003
306
US
Hello all,

I was curious if anyone knows of a way to minimize a console app to the system tray. I have just written an application that is designed to run all the time and fire at certain intervals. I could make it a service, but I need it to run with a window that I can interact with, just in case I need to perform some ad-hoc stuff.

I would greatly appreciate any help.

Thanks in advance,
Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Thanks for the link, and while that should certainly work for a WinForms application, I don't know that it will work for the prompt window of a console application. But, I'll see if I can adapt this in the morning to give me access to the console window. If anyone has any other ideas they would be greatly appreciated.

Thanks again, MasterRacker!
And, again, thanks in advance to anyone else who offers insight!

Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Oops, missed the console part. There are various 3rd party programs like AlwaysUp or AppToService for running programs as services. One of them might work with a .NET app. There is also a Resource Kit utility SrvAny.

Whether or not any of these also get you into the system tray I don't know.



Jeff
[purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day

"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me
 
Jeff,

Its cool, thanks. I actually just ended up running the form minimized and hiding it while it is processing. And, should anyone else want to do this, I'll include some of my code.
This code is globally defined...actually the first thing I do
Code:
#region Console Window property stuff
[DllImport("kernel32.dll", ExactSpelling=true)]
private static extern IntPtr GetConsoleWindow();

private static IntPtr ThisConsole=GetConsoleWindow();
		
[DllImport("user32.dll",CharSet=CharSet.Auto, SetLastError=true)]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private const int HIDE=0;
private const int MAXIMIZE=3;
private const int MINIMIZE=6;
private const int RESTORE=9;
#endregion

This is the code that I used when I needed to change the window's state:
Code:
Processing=true;
ShowWindow(ThisConsole, HIDE); //Hides Console Window
Console.WriteLine("\r\nExecuting at: " + System.DateTime.Now.ToString());

PutFiles();
GetFiles();
			
Console.WriteLine("\r\nExecution completed.\r\n");
ShowWindow(ThisConsole, RESTORE); //Restores Console Window
Processing=false;

I hope this helps other people as well!
Thanks,
Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top