Hidding the window for a tray app (overriding so alt-tab doesn't work properly)

I have a tray app that has a window and I do not want it to be alt-tabbable.  

It doesn't show up in the alt-tab window right now unless the user is using a full screen program

1.  why does it show up doing a full screen program?
2.  What is the best thing to override to not allow alt-tab to work properly (just capture WM_MAXIMIZE in WndProc?) and leave the window minimized.  

LVL 5
jjacksnAsked:
Who is Participating?
 
RomanPetrenkoConnect With a Mentor Commented:
Look,
I have Windows XP SP2 RC1
the following code hides the main window when you minimize it and shows notifyIcon and the window not visible in neither in TaskBar nor AltTab list, in notifyIcon's context menu you can choose "show" to show it.
as  dvd player I've tried BSPlayer and Nero Media player in FullScreen and windowed mode:
---Sample---
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.ComponentModel.IContainer components;

public Form1()
{
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
      if( disposing )
      {
            if (components != null)
            {
                  components.Dispose();
            }
      }
      base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
      this.components = new System.ComponentModel.Container();
      System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
      this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
      this.contextMenu1 = new System.Windows.Forms.ContextMenu();
      this.menuItem1 = new System.Windows.Forms.MenuItem();
      //
      // notifyIcon1
      //
      this.notifyIcon1.ContextMenu = this.contextMenu1;
      this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
      this.notifyIcon1.Text = "notifyIcon1";
      //
      // contextMenu1
      //
      this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                                                              this.menuItem1});
      //
      // menuItem1
      //
      this.menuItem1.Index = 0;
      this.menuItem1.Text = "Show";
      this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
      //
      // Form1
      //
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Name = "Form1";
      this.Text = "Form1";
      this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
      Application.Run(new Form1());
}

private void Form1_SizeChanged(object sender, System.EventArgs e)
{
      if (this.WindowState == FormWindowState.Minimized)
      {
            Hide();
            notifyIcon1.Visible = true;
      }
}

private void menuItem1_Click(object sender, System.EventArgs e)
{
      notifyIcon1.Visible = false;
      Show();
}
}
---end of Sample---
Is this smaple works the same way for you?
0
 
RomanPetrenkoCommented:
This window should be visible? you can simply hide it(ShowWindow with SW_HIDE command).
0
 
jjacksnAuthor Commented:
This window is never visible.  Another window shows as a popup, but not the main window.  I use the SW_HIDE command, and that works fine when a window is not if full screen mode.  By fine I mean it isn't in the alt-tab window.  

However, when a window is full screen, you can alt-tab to it.  
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
RomanPetrenkoCommented:
>This window is never visible.
...
>However, when a window is full screen, you can alt-tab to it
You mean above the window of another application is full screen? When you say "Full screen" you mean maximized or like screensavers(no taskbar, toolbars and may be grafic mode changed).
0
 
RomanPetrenkoCommented:
I think you can use this.Hide() on Deactivate event of main form. This possibly will help
0
 
jjacksnAuthor Commented:
I mean like when you are playing a dvd or something like that, so it goes into complete full screen mode.  then you can see my app in the alt-tab window.  others, it works fine.
0
 
RomanPetrenkoCommented:
So your main window is hidden and it's popup is in fullscreen mode, did I understand you right?
How do you create full-screen popup window? can you provide here simple sample. I'd like to see such behavior you describe.
0
 
jjacksnAuthor Commented:
Roman, create an app that has no taskbar and call this.Hide().  You will not be able to see in alt-tab.  Then play a DVD in full screen mode.  when you alt-tab, you can see it.
0
 
RomanPetrenkoCommented:
This happened because the window active(focused) now. When you hiding it you also should move focus to another window(May be to desktop or next window in alt-tab list). Also you may try WS_TRANSPARENT|WS_TOPMOST style, then your window will not grab focus and also will be visible over all other windows.
0
 
jjacksnAuthor Commented:
Roman, it is never active to begin with though... so I don't quite understand what you are saying?
0
 
RomanPetrenkoCommented:
It becomes active when you press alt-tab because it next window to your DVD player.
0
 
jjacksnAuthor Commented:
It doesn't become active, it simply is shown in the alt-tab window and one COULD select it.  However, if a window is not in full-screen mode, then you can't see my application icon in the alt-tab window.
0
 
jjacksnAuthor Commented:
??

This code doesn't hide the main app, I can get through it via alt-tab, and I can't see an icon get loaded into the tray.  Is this the right code?
0
 
RomanPetrenkoCommented:
yes. It was compiled with VS.net 2003 and works fine.
When you minimize window it hides and shows icon in tray, click on show menu item in task bar you'll get it back.
0
 
jjacksnAuthor Commented:
I can still alt tab to it.  
0
 
RomanPetrenkoCommented:
Did you find the problem? now the code I posted before works? You found better solution?
0
 
jjacksnAuthor Commented:
Roamin, as I said, I can still alt-tab to the screen in your code (which I don't want to be able to do)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.