473,503 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hide From Alt-Tab List

I have an application. I want it so when the user minimizs the window it
goes into the system tray, and while in the system tray I don't want it in
the "Alt-Tab" list. (When the program starts it starts in the system tray
aswell; only shows main window if they double click).

Currently to achive this when the user minimizes I have to set
"ShowInTaskbar - false" "ControlBox - false" "Size - 0,0" "Text - null"
"FormBorderStyle - FixedToolWindow". And then reset everything when they
double click the system tray. Is there a simplier solution to this? (The
reasion I have to set "Text - null" and "ControlBox - fasle" is because Size
wont go to 0,0 if they arn't set when FormBorderStyle is a ToolWindow).

Ideally I would like to simply set "WindowState - minimized"
"ShowInTaskbar - false" but when "FormBorderStyle - ToolWindow" is set the
window wont minimize to taskbar (it goes into a box above the start menu
icon), but the program always shows up in the Alt-Tab list unless I set the
FormBorderStyle to ToolBar.

I use VS.NET 2005. I tried "this.Visable = false" or "this.Hide()" but for
some reasion it doesn't work for my main window if I set "FormBorderStyle -
ToolWindow" (this.Visable doesn't seem to work for me even if borderstyle
isn't changed). I do the command right under my "InitializeComponent();" in
the form constructor... This is because its my main window? or should it be
working...
Any help would be appresiated. Thanks

NvrBst
Jan 6 '06 #1
4 13166
Hi,

"Never Best" <nb@hotmail.com> wrote in message
news:nSkvf.43758$m05.17143@clgrps12...
I have an application. I want it so when the user minimizs the window it
goes into the system tray, and while in the system tray I don't want it in
the "Alt-Tab" list. (When the program starts it starts in the system tray
aswell; only shows main window if they double click).


Loom in the archives, I posted the code a time ago (I do not have the code
with me now). It's very easy just a couple of simples P/invokes

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 6 '06 #2
Hi,
Found it in the sent-items :)
[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);


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 6 '06 #3
Ahh thank you. I kinda already knew about the p/invoke method from
http://dotnet247.com/247reference/msgs/45/228585.aspx which is
basically identical to yours but he removes the WS_EX_APPWINDOW tag
while doing the SetWindowLong.

Mainly I was hoping for a managed solution because at
http://pinvoke.net/ under the "GetWindowLong" its like !!Obsolet:
This function is UNSAFE!!

But it seems I can't set the window size to 0,0 (it goes to 2,2
min), and thus now I'm using the p/invoke method and it seems fine
:) Maybe later when a managed solution pop's up I'll be able to
change.

Thanks for your reply.
NvrBst
--
----------------------------------------------
Posted with NewsLeecher v3.0 Final
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------
Jan 7 '06 #4
Take a look at this code... also use showintaskbar property of the form
and mark it false when you want it to get off teh task bar - removing an
item from the task bar will remove it from the alt tab list

Here is the code I used to get it to work, it's a little bit bootleg
(with the hasBeenActivated and what not)... but it worked... note: I
didn't add a notification icon, I also didn't do anything on load -
instead i moved everything into activated.:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace WindowsApplication2
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

private bool _hasBeenActivated = false;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent
call
//
this.Activated += new EventHandler(Form1_Activated);
}

/// <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()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 271);
this.Name = "Form1";
this.ShowInTaskbar = false;
this.Text = "Form1";

}
#endregion

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

// the function you should call when you want to show or hide
the window
private void ShowHideWindow ()
{
int myVisibleState = this.GetWindowVisibleState(
this.Handle, 0, 0 );
if ( myVisibleState == WIND_VISIBLE )
{
// SW_HIDE = 0;
this.ShowInTaskbar = false;
ShowWindow( this.Handle, 0 );
}
else if ( myVisibleState == WIND_HIDDEN ||
myVisibleState == WIND_COVERED ||
myVisibleState == WIND_PARTIALLY_COVERED )
{
// SW_RESTORE = 9
this.ShowInTaskbar = true;
ShowWindow( this.Handle, 9 );
SetForegroundWindow( this.Handle );
}
}

// the following is the meat of the entire thing
// it does some visibility checks on a pixel matrix regarding your
// app's window - it then decides if the window is hidden
// or not
public const int WIND_HIDDEN = 0;
public const int WIND_VISIBLE = 1;
public const int WIND_COVERED = 21;
public const int WIND_PARTIALLY_COVERED = 3;
internal int GetWindowVisibleState(IntPtr hWnd, int iStepX, int
iStepY)
{
RECT rc = new RECT();
Point pt = new Point();
int i = 0;
int j = 0;
int width = 0;
int height = 0;
int iCountedDots = 0;
int iNotCoveredDots = 0;
IntPtr hAux = IntPtr.Zero;
if ( iStepX <= 0 ) iStepX = 4;
if ( iStepY <= 0 ) iStepY = 16;

if ( !this.Visible || this.WindowState ==
FormWindowState.Minimized )
return WIND_HIDDEN;
else
{
GetWindowRect( hWnd, ref rc );
width = rc.right - rc.left;
height = rc.bottom - rc.top;

for ( i = rc.top; i<rc.bottom; i+=( height/iStepY ) )
{
pt.Y = i;
for ( j=rc.left; j<rc.right; j+= ( width / iStepX ) )
{
pt.X = j;
hAux = WindowFromPoint( pt );
while ( GetParent( hAux ) != IntPtr.Zero )
hAux = GetParent( hAux );
if ( hAux == hWnd ) // another window!
iNotCoveredDots++;
iCountedDots++;
}
}
if ( iNotCoveredDots == iCountedDots ) // window is
completely visible
return WIND_VISIBLE;
else if ( iNotCoveredDots == 0 ) // they're all covered
return WIND_COVERED;
else // partial
return WIND_PARTIALLY_COVERED;
}
}

[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(
System.Drawing.Point lpPoint);

[DllImport("user32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
public static extern IntPtr GetParent(IntPtr hWnd);

[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool GetWindowRect(IntPtr hWnd, ref RECT
rect);

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern bool ShowWindow(IntPtr hWnd, short State);

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern bool SetForegroundWindow(IntPtr hWnd);

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public Int32 left;
public Int32 top;
public Int32 right;
public Int32 bottom;
}

private void Form1_Activated(object sender, EventArgs e)
{
if (! _hasBeenActivated )
{
_hasBeenActivated = true;
ShowWindow( this.Handle, 0 );
}
}

}
}
nv****@hotmail.com wrote:
Ahh thank you. I kinda already knew about the p/invoke method from
http://dotnet247.com/247reference/msgs/45/228585.aspx which is
basically identical to yours but he removes the WS_EX_APPWINDOW tag
while doing the SetWindowLong.

Mainly I was hoping for a managed solution because at
http://pinvoke.net/ under the "GetWindowLong" its like !!Obsolet:
This function is UNSAFE!!

But it seems I can't set the window size to 0,0 (it goes to 2,2
min), and thus now I'm using the p/invoke method and it seems fine
:) Maybe later when a managed solution pop's up I'll be able to
change.

Thanks for your reply.
NvrBst

Jan 7 '06 #5

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

Similar topics

12
6261
by: deko | last post by:
Is there any way to work around the blank space created by hidden divs? I'm trying to use a relatively postioned divs with show/hide behaviors to annotate an image. The divs show/hide...
9
2737
by: sergio | last post by:
Hi all, I have created the following script that will show/hide a menu based on checkboxes. It works fine in Opera but not on IE6! Does anybody knows a workaround this problem? Thanks for your...
5
2160
by: Zambien | last post by:
Hi all, Here's my problem. I have tables that are using the menu/submenu idea for hiding rows. This works fine in IE (of course) and does show/hide correctly in netscape, but as soon as the...
0
1265
by: Serj Kondryukov | last post by:
I need my program do not see Alt key. That is if user press in textbox Alt+F F must be entered to textbox. I have try to write PreFilterMessage where i hide Alt from LParam and replace...
3
1928
by: ranjithsubra | last post by:
Hi , i am a new member of this group,Learning vc++, 1.If i press Ctrl+Alt+Del, what happen Desktop window will be shoutdown, logof ,etc. 2. I need to Hide the KeyCombination CTRL+ALT+DEL, when...
1
1475
by: traewathen | last post by:
Hello all i am rather new to the whole c # and .net language. my question is in regards to the c# portion of the matter. this is my code block which i have for hiding and unhiding:: ...
5
1529
by: JEgbert | last post by:
I am trying to hide a layer when a text box length is zero, and its just not working! It hides the content in the layer, but you still see a little 2 pixel width blip on the screen. I've spent...
6
3201
by: Doogie | last post by:
Hi I have an img control I am trying to hide upon certain types of commands in my code behind. When to hide it is directly tied to a asp:dropdownlist control. So depending on what the user...
10
7354
by: dkyadav80 | last post by:
<html> /// here what shoud be java script for: ->when script run then not display all input text field only display selection field. ->when user select other value for institute only this...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7280
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,...
0
7332
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...
1
6991
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...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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 ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.