Vikram.exe
Vikram.exe

Reputation: 4585

Hiding TaskBar from a process (c#)

In my application, I want to hide the windows TaskBar and StartMenuButton when my process is started and want to restore it when it exits.

I can do this using:

IntPtr  startButtonHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, (IntPtr)0xC017, null);
IntPtr  taskBarHwnd = FindWindow("Shell_TrayWnd", "");

ShowWindow(taskBarHwnd, 0);
ShowWindow(startButtonHwnd, 0);

and this is working fine for me. Now I see a case where, if my process is crashed for some reason or is FORCIBLY killed by user, I won't be able to restore the TaskBar.

Is there any method of restoring it for these TWO (crash and killed) cases?

I am also interacting with Windows Gadget and I show a Gadget window when some button is clicked in my application, so I can not use properties like Form.TopMost = true & Screen.PrimaryScreen.Bounds

Thanks,

Vikram

Upvotes: 0

Views: 462

Answers (1)

ChrisF
ChrisF

Reputation: 137178

You can cater for most crashes by putting the restore code in a global exception handler. You can do this by setting up an unhandled exception handler

  AppDomain currentDomain = AppDomain.CurrentDomain;
  currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);


static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
    ShowWindow(taskBarHwnd, 0);
    ShowWindow(startButtonHwnd, 0);
}

This won't cater for the case where the program is killed.

Upvotes: 2

Related Questions