how to stop forms appearing in alt + tab task list

H

harry

Hello,

I've got a form which is a splash screen and set all the properties to stop
if from appearing in the taskbar,
have no borders, place it in the center of the screen and all that.

However it still appears as a white icon when it is displayed and you alt +
tab (not quite certain what that screen
is called) is there anyway to stop it from appearing at all excep just on
the screen in front of my app?

my initialisecomponent method:-

private void InitializeComponent()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.LightGray;
this.BackgroundImage =
((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(400, 280);
this.Controls.Add(this.lblStatus);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "SplashScreen";
this.ShowInTaskbar = false;
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SplashScreen";
this.DoubleClick += new
System.EventHandler(this.SplashScreen_DoubleClick);
}


cheers
 
G

Gary Milton

Hi Harry,

To do this, you need to apply the extended window style of 'toolwindow' to
the splash screen which involves p/invoking some Win32 API's. Set your
splash screen border to 'None', set the 'ShowInTaskBar' property to False
and then use the following code:-

Add the following import to the top of your splash screen code...

\\\
using System.Runtime.InteropServices;
///

....then add the following code into your splash screen form...

\\\
private const int GWL_EXSTYLE = (-20);
private const int WS_EX_TOOLWINDOW = 0x80;
private const int WS_EX_APPWINDOW = 0x40000;

[DllImport("user32", CharSet=CharSet.Auto)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32", CharSet=CharSet.Auto)]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int
dwNewLong);

private void frmSplashScreen_Activated(object sender, System.EventArgs e)
{
SetWindowLong(this.Handle, GWL_EXSTYLE, (GetWindowLong(this.Handle,
GWL_EXSTYLE) | WS_EX_TOOLWINDOW) & ~WS_EX_APPWINDOW);
}
///

Hope this helps,

Gary
 
H

harry

Cheers, that worked a treat.

Gary Milton said:
Hi Harry,

To do this, you need to apply the extended window style of 'toolwindow' to
the splash screen which involves p/invoking some Win32 API's. Set your
splash screen border to 'None', set the 'ShowInTaskBar' property to False
and then use the following code:-

Add the following import to the top of your splash screen code...

\\\
using System.Runtime.InteropServices;
///

...then add the following code into your splash screen form...

\\\
private const int GWL_EXSTYLE = (-20);
private const int WS_EX_TOOLWINDOW = 0x80;
private const int WS_EX_APPWINDOW = 0x40000;

[DllImport("user32", CharSet=CharSet.Auto)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32", CharSet=CharSet.Auto)]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int
dwNewLong);

private void frmSplashScreen_Activated(object sender, System.EventArgs e)
{
SetWindowLong(this.Handle, GWL_EXSTYLE, (GetWindowLong(this.Handle,
GWL_EXSTYLE) | WS_EX_TOOLWINDOW) & ~WS_EX_APPWINDOW);
}
///

Hope this helps,

Gary

harry said:
Hello,

I've got a form which is a splash screen and set all the properties to stop
if from appearing in the taskbar,
have no borders, place it in the center of the screen and all that.

However it still appears as a white icon when it is displayed and you
alt
+
tab (not quite certain what that screen
is called) is there anyway to stop it from appearing at all excep just on
the screen in front of my app?

my initialisecomponent method:-

private void InitializeComponent()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.LightGray;
this.BackgroundImage =
((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(400, 280);
this.Controls.Add(this.lblStatus);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "SplashScreen";
this.ShowInTaskbar = false;
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SplashScreen";
this.DoubleClick += new
System.EventHandler(this.SplashScreen_DoubleClick);
}


cheers
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Gary,

Actually there is easier way to set WS_EX_TOOLWINDOW and remove
WS_EX_APPWINDOW styles.

To remove WS_EX_APPWINDOW set Form.ShowInTaskbar property to *false*

To set WS_EX_TOOLWINDOW set Form.FormBorderStyle either to
FormBorderStyle.FixedToolWindow or FormBorderStyle.SizableToolWindow

--
HTH
B\rgds
100 [C# MVP]

Gary Milton said:
Hi Harry,

To do this, you need to apply the extended window style of 'toolwindow' to
the splash screen which involves p/invoking some Win32 API's. Set your
splash screen border to 'None', set the 'ShowInTaskBar' property to False
and then use the following code:-

Add the following import to the top of your splash screen code...

\\\
using System.Runtime.InteropServices;
///

...then add the following code into your splash screen form...

\\\
private const int GWL_EXSTYLE = (-20);
private const int WS_EX_TOOLWINDOW = 0x80;
private const int WS_EX_APPWINDOW = 0x40000;

[DllImport("user32", CharSet=CharSet.Auto)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32", CharSet=CharSet.Auto)]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int
dwNewLong);

private void frmSplashScreen_Activated(object sender, System.EventArgs e)
{
SetWindowLong(this.Handle, GWL_EXSTYLE, (GetWindowLong(this.Handle,
GWL_EXSTYLE) | WS_EX_TOOLWINDOW) & ~WS_EX_APPWINDOW);
}
///

Hope this helps,

Gary

harry said:
Hello,

I've got a form which is a splash screen and set all the properties to stop
if from appearing in the taskbar,
have no borders, place it in the center of the screen and all that.

However it still appears as a white icon when it is displayed and you
alt
+
tab (not quite certain what that screen
is called) is there anyway to stop it from appearing at all excep just on
the screen in front of my app?

my initialisecomponent method:-

private void InitializeComponent()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.LightGray;
this.BackgroundImage =
((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(400, 280);
this.Controls.Add(this.lblStatus);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "SplashScreen";
this.ShowInTaskbar = false;
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SplashScreen";
this.DoubleClick += new
System.EventHandler(this.SplashScreen_DoubleClick);
}


cheers
 
H

Harry Longleat

The trouble is using either ToolWindow BorderStyle, gives me a border
and a caption with a close icon in the corner.
Using BorderStyle.None gets rid off all that but it still shows up in
the alt + tab screen. Using Garys method allows me to set the extended
windows property while making the splashscreen appear as just an image.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Harry,

To get rid of the caption set form's ControlBox to *false* and Text to ""
(empty string)

It is not like Gary's solution doesn't work it is completely correct.
However, I believe that one should avoid using PInovke if there is a managed
solution for the problem.If you prefer setting windows styles you may
consider doing it in CreateParam property instead using PInvoke and
SetWindowLong.
 
H

Harry Longleat

Funny you should post that I was playing around this morning with
another form and came across that my very self. I agree with you I don't
like having to work with the win api if I can avoid it.

cheers
 
H

Harry Longleat

I have one slight problem if I go the root of the tool window and
setting text to "" and controlbox to *false* in that a small black
border appears round the window which I'd like to get rid of but after
playing with various properties it doesn't seem possible unless I go the
border none and p/invoke method.

cheers

PS I know, I know I want the moon on a stick ;-)
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Harry,

That thin balck border cannot be removed by setting the properties. However
you still have managed solution for this.

Override CreateParams property and remove the WS_BORDER style. Since you
override that property you can set all the styles there.

private const int WS_BORDER = 0x00800000;
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style &= ~WS_BORDER;

return cp;
}
}

Or if you want to keep your options for changing the form style open you can
check and remove that style only for ToolWindows
 

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