Keeping application to notify icon

  • Thread starter Beenish Sahar Khan
  • Start date
B

Beenish Sahar Khan

I want to start my application so that its notify icon is added to the
system tray, i don't want to show any starting form. I want user to interact
through the notify icon...just like MSN. Is there any way to do this?
regards,
beenish
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

find below pieces of code I use for this

//declarations

[DllImport("user32.dll",EntryPoint="SetForegroundWindow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[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);

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


//PUT THIS code in the constructor
this.Text = "";

// Create the NotifyIcon.
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;
notifyIcon1.Visible = true;

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Visible = false;
this.ShowInTaskbar = false;
iconTimer.Start();

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


cheers,
 
B

Beenish Sahar Khan

Thanks alot, its working :D

Ignacio Machin ( .NET/ C# MVP ) said:
hi,

find below pieces of code I use for this

//declarations

[DllImport("user32.dll",EntryPoint="SetForegroundWindow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[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);

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


//PUT THIS code in the constructor
this.Text = "";

// Create the NotifyIcon.
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;
notifyIcon1.Visible = true;

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Visible = false;
this.ShowInTaskbar = false;
iconTimer.Start();

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


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Beenish Sahar Khan said:
I want to start my application so that its notify icon is added to the
system tray, i don't want to show any starting form. I want user to
interact
through the notify icon...just like MSN. Is there any way to do this?
regards,
beenish
 
B

Beenish Sahar Khan

Thanks for your solution, one more question that i would like to ask is ,
once i've made my form invisble using the below mentioned solution, now
after sometime, while the application is still running, i want to make the
particular form visible, what should i do to make it visible.
Beenish
Ignacio Machin ( .NET/ C# MVP ) said:
hi,

find below pieces of code I use for this

//declarations

[DllImport("user32.dll",EntryPoint="SetForegroundWindow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[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);

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


//PUT THIS code in the constructor
this.Text = "";

// Create the NotifyIcon.
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;
notifyIcon1.Visible = true;

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Visible = false;
this.ShowInTaskbar = false;
iconTimer.Start();

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


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Beenish Sahar Khan said:
I want to start my application so that its notify icon is added to the
system tray, i don't want to show any starting form. I want user to
interact
through the notify icon...just like MSN. Is there any way to do this?
regards,
beenish
 
B

Beenish Sahar Khan

Infact, i will rephrase my question that while running my application i
would like to hide it or show it multiple times, how do i show it so when
the next time i try to hide it, it will hide cleanly. as currently if i
simple make it visible and show it in taskbar, it do not hide again. :( I
request you to provide me a solution to this problem.
regards,
Beenish
Beenish Sahar Khan said:
Thanks for your solution, one more question that i would like to ask is ,
once i've made my form invisble using the below mentioned solution, now
after sometime, while the application is still running, i want to make the
particular form visible, what should i do to make it visible.
Beenish
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%[email protected]...
hi,

find below pieces of code I use for this

//declarations

[DllImport("user32.dll",EntryPoint="SetForegroundWindow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[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);

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


//PUT THIS code in the constructor
this.Text = "";

// Create the NotifyIcon.
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;
notifyIcon1.Visible = true;

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Visible = false;
this.ShowInTaskbar = false;
iconTimer.Start();

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


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Beenish Sahar Khan said:
I want to start my application so that its notify icon is added to the
system tray, i don't want to show any starting form. I want user to
interact
through the notify icon...just like MSN. Is there any way to do this?
regards,
beenish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top