systray

  • Thread starter Thread starter mario
  • Start date Start date
Hi Mario

To put an icon in the systray you use the NotifyIcon component. take a look
at MSDN for it.
If you want your application removed from the taskbar, as well as showing no
windows let me know as you may need aditional code.


Cheers,
 
Hi Mario

This is the code I'm using now, I'm cutting&paste from my app so maybe it
will not compile as it is.

using System.Runtime.InteropServices;

[DllImport("user32.dll",EntryPoint="SetForegroundWindow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool MessageBeep(int type);
[DllImport("user32.dll")]
public static extern int SetWindowLong( IntPtr window, int index, int
value);
[DllImport("user32.dll")]
public static extern int GetWindowLong( IntPtr window, int index);
[DllImport("winmm.dll")]
public static extern int sndPlaySound(string lpszSoundName , int uFlags)
;


const int GWL_EXSTYLE = -20;
const int WS_EX_TOOLWINDOW = 0x00000080;
const int WS_EX_APPWINDOW = 0x00040000;

//This is the icon when there are no orders in the system
Icon normalIcon;


public Form1()
{
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);

// The Icon property sets the icon that will appear
// in the systray for this application.
notifyIcon1.Icon = normalIcon;

// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
notifyIcon1.ContextMenu = this.contextMenu1;

// The Text property sets the text that will be displayed,
// in a tooltip, when the mouse hovers over the systray icon.
notifyIcon1.Text = "the text";
notifyIcon1.Visible = true;


//Remove from the taskbar and also from alt+tab
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Visible = false;
this.ShowInTaskbar = false;

int windowStyle = GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDOW);
}


Cheers,
 
I also have managed to keep my app in the taskbar tray but am having
problems with hiding the window from the taskbar. Any help on this would be
greatly appreciated...

Thanks

John
 
Hi John,

Take a look at my other post. I got that some from somewhere in the
newsgroup :)

Cheers,
 
Back
Top