How not to hide Form from Running Programs

This question comes up a lot, and the well-known and documented workaround is to set your Form’s Text property to an empty string to hide it from the Running Programs applet so I won’t go into that.  And before reading further, if you’re after hiding a Form, then go Google for that info – everything I present here are ways that are proven to not work.  It’s simply info for those who are tempted to try another route.


We know that the Running Programs applet simply enumerates all top-level windows with text.  We also know that a lot of native apps don’t have the problem of child windows showing up, so I decided to try to mimic that behavior with some P/Invoke shenanigans.  The test app simply had 2 forms – Form1 would create a Form2 instance on a button click and then call ShowDialog on the new Form2 instance.  After that (if it got that far), I’d check the applet to see if my code worked.


Method 1: Reparent the Form with SetParent


[DllImport(“coredll.dll”, SetLastError = true)]
internal static extern IntPtr SetParent(IntPtr hwndChild, IntPtr hwndNewParent);



  • Tried calling this after creating the Form2 and before calling ShowDialog.  ShowDialog subsequently throws an ArgumentException

  • Tried calling it in the ctor of Form2. ShowDialog subsequently throws an ArgumentException

  • Tried passing Form1’s Handle to Form 2, then calling SetParent in a Form2.Activate handler. ShowDialog subsequently throws an ArgumentException

  • Tried calling SetParent from a button click in Form2, so after the dialog is loaded and shown.  No exception now, but when SetParent runs, Form1 gains scrollbars, Form2’s controls end up in Form1 along with Form1’s controls (so a mash up of both) and all controls are non-responsive.

Method 2: Change the Window Style bits


internal const int GWL_STYLE = -16;
internal const int GWL_EXSTYLE = -20;
internal const uint WS_CHILD = 0x40000000;
internal const uint WS_EX_APPWINDOW = 0x00040000;

[DllImport(“coredll.dll”, SetLastError = true)]
internal static extern uint SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);

[DllImport(“coredll.dll”, SetLastError = true)]
internal static extern uint GetWindowLong(IntPtr hWnd, int nIndex);



  • Tried setting style to WS_CHILD after creation and before ShowDialog.  Still appears in applet.

  • Tried setting style to WS_CHILD in Form2 ctor.  Still appears in applet.

  • Tried setting style to WS_CHILD in Form2 Activate handler.  Still appears in applet.

  • Tried setting style to WS_CHILD in Form2 button click handler.  Still appears in applet.

  • Tried unsetting extended style to WS_EX_APPWINDOW after creation and before ShowDialog.  Still appears in applet.

  • Tried unsetting extended style to WS_EX_APPWINDOW in Form2 button handler.  Still appears in applet.

So what’s the take away lesson?  CF Forms like to be shown in that damned applet, and the simplest mechanism is still to just set the text to an empty string when you want to hide it.

2 thoughts on “How not to hide Form from Running Programs”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s