Prevent borderless Form to appear in "Alt+TAB" window

  • Thread starter Frank Stegerwald
  • Start date
F

Frank Stegerwald

Hi,

i have a Windows Form (Splashscreen) that runs on
a seperate thread until my main app is up and running.

This form has its FrameBorderStyle set to "None".
How can I prevent this Form from beeing displayed in the
"ALT+TAB" list?

Any help will be greatly appreciated

Frank Stegerwald
 
J

Jeffrey Tan[MSFT]

Hi Frank,

Thanks for your post!!

I think Eric has provided you half of the solution :)

Actually, whether a Window(In .Net, this is called Form) will appear in
Alt+Tab list can be determined by its extended window style. For a detailed
description of "Extended Window Styles", please refer to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/htm
l/_mfc_extended_window_styles.asp

In the above reference, you will see that:
WS_EX_APPWINDOW: Forces a top-level window onto the taskbar when the window
is visible.
WS_EX_TOOLWINDOW: Creates a tool window, which is a window intended to be
used as a floating toolbar. A tool window has a title bar that is shorter
than a normal title bar, and the window title is drawn using a smaller
font. A tool window does not appear in the task bar or in the window that
appears when the user presses ALT+TAB.

So if we get rid of a window(Form)'s WS_EX_APPWINDOW style and then apply
WS_EX_TOOLWINDOW to it, we can get what we want. In .Net a Form's style and
extended style can be changed through overriding CreateParams property,
like below:

//Suppose Form2 is the splash window
private const int WS_EX_TOOLWINDOW= 0x00000080;
private const int WS_EX_APPWINDOW=0x00040000;
protected override CreateParams CreateParams
{
get
{
CreateParams cp=base.CreateParams;
cp.ExStyle=cp.ExStyle&(~WS_EX_APPWINDOW);
cp.ExStyle=cp.ExStyle|WS_EX_TOOLWINDOW;
return cp;
}
}

//In Main app(Form1)
public Form1()
{
Thread t=new Thread(new ThreadStart(ThreadProc));
t.Start();
System.Threading.Thread.Sleep(5000);
InitializeComponent();
}

private void ThreadProc()
{
Form2 f=new Form2();
f.FormBorderStyle=FormBorderStyle.None;
Application.Run(f);
}

Why I say Eric gives you the half solution? Because .Net encapsulate
WS_EX_APPWINDOW style as ShowInTaskbar property, so if we set
ShowInTaskbar=false, we can get rid of this line:
cp.ExStyle=cp.ExStyle&(~WS_EX_APPWINDOW). They are the same effect.

At last, if you want to hide an already existed window from Alt+Tab list,
you can p/invoke SetWindowLong/GetWindowLong Win32 Api to change it
extended window style.

The above code works well on my side. Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
F

Frank Stegerwald

Hi Jeffrey and Eric,

I want to thank both of you for helping me out
on this topic.
I had already set the "ShowInTaskbar" property
which really gave me half of the results ;-)

But a special Thanks goes to Jeffrey for such
a DETAILED information, that includes the solution
coded out!!!

Dont know what MSFT stands for in your name, but
if there are ratings for newsgroup answers here
are my 11 out of 10 points to you...

Thanks you both again for the detailed help.
Greetings from Germany
Frank Stegerwald
 
J

Jeffrey Tan[MSFT]

Hi Frank,

Thanks for your great feedback!

MSFT is the code name of Microsoft in Nasdaq :).

If you need further help, please feel free to post. Cheers!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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