C# Hiding an application from the taskbar

前端 未结 3 1010
慢半拍i
慢半拍i 2021-01-11 14:41

I have been struggling to hide another application from the taskbar from my application.
I have been using the SetWindowLong function in order to set/remove WS_EX_APPWIN

3条回答
  •  Happy的楠姐
    2021-01-11 15:07

    Here is how I do this.

    1. Create a window (hwndOwner) with WS_POPUP style and WS_EX_TOOLWINDOW
    2. Call SetWindowLong(hwnd, GWL_HWNDPARENT, hwndOwner)
    3. Call SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) |     ~WS_EX_APPWINDOW)
    

    This will remove the target window from the taskbar and alt tab. This will work on every OS since WS2000 at least.

    Now, David Heffernan pointed to the MSDN documentation which says you can't do this. Well, I don't know why it says that but its inaccurate. You can do this and INFACT the .NET Framework does this, just use .NET Reflector to examine the code for System.Windows.Forms.Form.Owner property - it uses SetWindowLong to transfer ownership, as often as you would like!

    And for more evidence of incorrect MSDN documentation, look no further than the docs for the Owner property, it says "A top-level window cannot have an owner." it should be the exact opposite of this, ONLY top-level windows can have an owner!

提交回复
热议问题