Program icons in the ALT+TAB menu

P

Peter Larsen

Hi,
I have asked this question before, but did not get anything useful from it -
so sorry that i am asking again !!

How do i prevent an application from appears more than once in the ALT+TAB
menu.

As it is today, my application will show an icon for each window visible in
the running application. I only want one icon.

And please - i'm not talking about the taskbar and/or property
ShowInTaskbar. I already know this and it does not solve my
problem/question.

Thank you in advance.
Peter
 
N

Nicholas Paldino [.NET/C# MVP]

Peter,

Are you saying you want more than one application instance to run, but
just one icon in the alt-tab list?
 
I

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

Hi,

Peter Larsen said:
Hi,
I have asked this question before, but did not get anything useful from
it - so sorry that i am asking again !!

This is the first time I see it in this NG !
How do i prevent an application from appears more than once in the ALT+TAB
menu.

As it is today, my application will show an icon for each window visible
in
the running application. I only want one icon.

This is what I would do:
1- Detect if another instance of my app is running ( posted many times
here )
2- If an instance is running hide the new instance from the ALT+TAB ( code
posted below).

The problem may be in hiding it, the code use Set/GetWindowLong which IIRC
will affect ALL the instances of that particular window , please somebody
correct me if I'm wrong.

Anyway, you could just try it


Now, I do hope you have a strong reason for doing this, I would be very
surprise knowing I have 10 instances open of IE and seeing only one in the
list.


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










[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;

private System.Windows.Forms.NotifyIcon notifyIcon1;


// I use two icons depending of the status of the app
normalIcon = new Icon(this.GetType(),"Normal.ico");
alertIcon = new Icon(this.GetType(),"Alert.ico");
notifyIcon1.Icon = normalIcon;

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

//Make it gone frmo the ALT+TAB
int windowStyle = GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDOW);
 
B

Brett Wickard

I think he's saying that he has one application running only once with
numerous windows open (that are visible in the taskbar) --- so when the user
hits alt-tab, the application shows up a bunch of times - once for each
window open that is visible in the task bar. This is the default behavior
of other windows apps, so I think he wants to know if there is a way to
override that default behavior.

Nicholas Paldino said:
Peter,

Are you saying you want more than one application instance to run, but
just one icon in the alt-tab list?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Peter Larsen said:
Hi,
I have asked this question before, but did not get anything useful from
it - so sorry that i am asking again !!

How do i prevent an application from appears more than once in the
ALT+TAB
menu.

As it is today, my application will show an icon for each window visible
in
the running application. I only want one icon.

And please - i'm not talking about the taskbar and/or property
ShowInTaskbar. I already know this and it does not solve my
problem/question.

Thank you in advance.
Peter
 
P

Peter Larsen

No - one application with multiple visible forms - but only apearing once in
the ALT+TAB menu !

Did i really say so ??

/Peter :)
 
P

Peter Larsen

You are talking about one application started more than once - this is not
my question.
I'm talking about ONE application with more than one window visible.

/Peter :)

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

Peter Larsen said:
Hi,
I have asked this question before, but did not get anything useful from
it - so sorry that i am asking again !!

This is the first time I see it in this NG !
How do i prevent an application from appears more than once in the
ALT+TAB
menu.

As it is today, my application will show an icon for each window visible
in
the running application. I only want one icon.

This is what I would do:
1- Detect if another instance of my app is running ( posted many times
here )
2- If an instance is running hide the new instance from the ALT+TAB ( code
posted below).

The problem may be in hiding it, the code use Set/GetWindowLong which IIRC
will affect ALL the instances of that particular window , please somebody
correct me if I'm wrong.

Anyway, you could just try it


Now, I do hope you have a strong reason for doing this, I would be very
surprise knowing I have 10 instances open of IE and seeing only one in the
list.


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










[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;

private System.Windows.Forms.NotifyIcon notifyIcon1;


// I use two icons depending of the status of the app
normalIcon = new Icon(this.GetType(),"Normal.ico");
alertIcon = new Icon(this.GetType(),"Alert.ico");
notifyIcon1.Icon = normalIcon;

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

//Make it gone frmo the ALT+TAB
int windowStyle = GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDOW);
 
P

Peter Larsen

Thats right !!

Brett Wickard said:
I think he's saying that he has one application running only once with
numerous windows open (that are visible in the taskbar) --- so when the
user hits alt-tab, the application shows up a bunch of times - once for
each window open that is visible in the task bar. This is the default
behavior of other windows apps, so I think he wants to know if there is a
way to override that default behavior.

Nicholas Paldino said:
Peter,

Are you saying you want more than one application instance to run, but
just one icon in the alt-tab list?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Peter Larsen said:
Hi,
I have asked this question before, but did not get anything useful from
it - so sorry that i am asking again !!

How do i prevent an application from appears more than once in the
ALT+TAB
menu.

As it is today, my application will show an icon for each window visible
in
the running application. I only want one icon.

And please - i'm not talking about the taskbar and/or property
ShowInTaskbar. I already know this and it does not solve my
problem/question.

Thank you in advance.
Peter
 
M

Michael Bray

How do i prevent an application from appears more than once in the
ALT+TAB menu.

I presume you are opening the windows with Show(). When you call Show,
pass the owning form as a parameter:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
// Form2 defined elsewhere
Form2 f = new Form2();
f.Show(this);
}
}

This works, but I don't know what other side effects it might have.

-mdb
 
S

Stoitcho Goutsev \(100\)

Peter,

I don't know what other suggestion can be made. The ALT+TAB list shows
windows that appear in the task bar. I don't know how you can solve the
problem if you don't want to hide your windows from the task bar.



--

Stoitcho Goutsev (100)




Peter Larsen said:
Thats right !!

Brett Wickard said:
I think he's saying that he has one application running only once with
numerous windows open (that are visible in the taskbar) --- so when the
user hits alt-tab, the application shows up a bunch of times - once for
each window open that is visible in the task bar. This is the default
behavior of other windows apps, so I think he wants to know if there is a
way to override that default behavior.

Nicholas Paldino said:
Peter,

Are you saying you want more than one application instance to run,
but just one icon in the alt-tab list?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,
I have asked this question before, but did not get anything useful from
it - so sorry that i am asking again !!

How do i prevent an application from appears more than once in the
ALT+TAB
menu.

As it is today, my application will show an icon for each window
visible in
the running application. I only want one icon.

And please - i'm not talking about the taskbar and/or property
ShowInTaskbar. I already know this and it does not solve my
problem/question.

Thank you in advance.
Peter
 
P

Peter Larsen

Great this works :)
Thanks for your time, Michael, and thanks to you all for participating.

/Peter :)
 

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