473,780 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hiding simple program in system tray?

VMI
How difficult is it to hide my program in the system tray? It's not something
that's required, but it'd look to add it since the program will be writing an
ascii file every minute. And it wouldn't too elegant to have it in the
taskbar.

Thanks.
Nov 17 '05 #1
3 1894
Will this help?
http://msdn.microsoft.com/library/de...rp06102002.asp

"VMI" <VM*@discussion s.microsoft.com > wrote in message
news:6B******** *************** ***********@mic rosoft.com...
How difficult is it to hide my program in the system tray? It's not
something
that's required, but it'd look to add it since the program will be writing
an
ascii file every minute. And it wouldn't too elegant to have it in the
taskbar.

Thanks.
Nov 17 '05 #2
Hi,

Use the code below for just that, note that I included both declarations and
code, the code can be inserted in the constructor ( part of it can be
inserted by the designer )
[DllImport("user 32.dll")]
public static extern int SetWindowLong( IntPtr window, int index, int
value);
[DllImport("user 32.dll")]
public static extern int GetWindowLong( IntPtr window, int index);

const int GWL_EXSTYLE = -20;
const int WS_EX_TOOLWINDO W = 0x00000080;
const int WS_EX_APPWINDOW = 0x00040000;

normalIcon = new Icon(this.GetTy pe(),"Normal.ic o");

this.notifyIcon 1 = new System.Windows. Forms.NotifyIco n(this.componen ts);
notifyIcon1.Ico n = normalIcon;

notifyIcon1.Con textMenu = this.contextMen u1;
notifyIcon1.Vis ible = true;

this.WindowStat e = System.Windows. Forms.FormWindo wState.Minimize d;
this.Visible = false;
this.ShowInTask bar = false;
iconTimer.Start ();

int windowStyle = GetWindowLong(H andle, GWL_EXSTYLE);
SetWindowLong(H andle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDO W);

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"VMI" <VM*@discussion s.microsoft.com > wrote in message
news:6B******** *************** ***********@mic rosoft.com...
How difficult is it to hide my program in the system tray? It's not
something
that's required, but it'd look to add it since the program will be writing
an
ascii file every minute. And it wouldn't too elegant to have it in the
taskbar.

Thanks.

Nov 17 '05 #3
its relatively simple:
the trick is to set the form.Opacity = 0

1. drag and drop a System.Windows. Forms.NotifyIco n to the form

2. code sample
public class SysTrayForm : System.Windows. Forms.Form
{
public SysTrayForm() {
InitializeCompo nent();
this.Hide();
InitializeTray( );
}

private System.Windows. Forms.NotifyIco n notifyIcon;
private MenuItem[] muItems = new MenuItem[2];

void InitializeTray( ) {
notifyIcon = new System.Windows. Forms.NotifyIco n();
notifyIcon.Icon = this.Icon;
notifyIcon.Text = "Right Click for the menu";
notifyIcon.Visi ble = true;

muItems[0] = new MenuItem("Show" , new EventHandler(ne w
System.EventHan dler(this.Show) ));
muItems[1] = new MenuItem("Exit" , new EventHandler(ne w
System.EventHan dler(this.ExitF orm)));

ContextMenu notifyiconMnu = new ContextMenu(muI tems);
notifyIcon.Cont extMenu = notifyiconMnu;
}

void Show(object sender, System.EventArg s e) {
//show some form here, but NOT this one
}

void ExitForm(object sender, System.EventArg s e) {
notifyIcon.Visi ble = false;
this.Close();
Application.Exi t();
}
}

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7365
by: Phil Galey | last post by:
VB.NET 2002 on Windows 2000 SP 3 When I start my program, the NotifyIcon appears in the tray, as it should. However, when I close the program, the NotifyIcon remains until I hover over it with my mouse. If I don't hover over it to make it disappear and then open the program again, another one is added, resulting in a multiplicity of the icon in the tray. I've even tried setting its Visible property to false, followed by a call to the...
7
6901
by: Danielb | last post by:
I want my application to run most of the time as just an notify icon visible in the system tray, with some dialogs windows that open if the user selects an option from the context menu on the tray icon. I've had a look at the example on code project that creates an application that runs in the system tray: http://www.codeproject.com/csharp/desktop_mail_checker.asp So I copied how the above article sets up the main form: the form's...
1
840
by: Amber | last post by:
The DataGrid allows you to make columns visible or invisible on demand - even edit and other special columns. This article will show you how it is done. Some developers have reported problems controlling the visibility of columns in the DataGrid control. The problem usually comes down to one fact. The DataGrid has a property called AutoGenerateColumns. The default value is "True". This means that when AutoGenerateColumns is set to True,...
8
8003
by: Michael Rich | last post by:
I am writing a program that primaryly runs in the system tray. When the program starts, I would like to hide the main form and only show the tray icon. in the Form Load event I set Me.Visible = False, but this does not hide the form. In the Form Activate event, if I set the same thing, the form is never displayed. There has got to be an easy way to do that I am overlooking.
4
1908
by: Tony Vitonis | last post by:
Hello. I've written an app that I want to "live" in the system tray. I want it to start up with just a tray icon showing, and if the user selects "Settings..." from the icon's context menu, to display a window that will allow him to change settings. When he hits "OK" or "Cancel", the window should hide again. At first, I tried putting a "Me.Visible = False" in the form's Load event, but apparently that code runs before the command can...
1
1065
by: Kevin White | last post by:
Hi all, I have a program that has this basic flow: 1- Splash screen opens and creates a system tray icon (the splash screen is the main form that is started on program execution, and stays hidden to be the form that the tray icon "belongs to") 2- From the tray icon, multiple forms are opened up for data entry 3- User may or may not exit the program from the system tray icon If Windows shuts down, how does my program receive...
1
5243
by: Ranjan as usual | last post by:
Dear folks, I just completed an autoresponder program. My program should be constantly running to monitor the folder of exchange server, but I just don't want to minimize it in my test box. Is there a way to make it like a icon on the system tray, next to the system clock? Any pointers would be appreciated. cheers, Ranjan
5
2638
by: Casper | last post by:
I'm trying to get my program to run in the system tray. I've looked at dozend of tutorials on the web and on newsgroups but I just dont get it! Has anyone got any links or example code that could use? I'm using Microsoft Visual Basic 2005 Express Edition. Thanks in advance.
5
6139
by: scottt | last post by:
I asked a question along a similar line about a week ago and didn't get any replies. Let me try to ask the quetion again a little bit different to see if I can get some help on this problem. Is there a way (API function) from one program to restore another application that is running in the system tray? Specifically I need to send a double mouse click to the application to get it to restore from the system tray. Thanks.
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.