473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 13155
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.