问题
Is there a way to build a C# wrapper for an existing application that will allow me to remove it from the taskbar?
More info:
I have an timer app that I suppose to use but don't because it well... sucks. See https://superuser.com/questions/92774/quickbooks-timer-replacement-windows.
So to make it suck less I wonder if I can build a wrapper then just interact with that wrapper instead. Removing the timer from the taskbar and then having my app hid/show it would be a step in that direction.
The other option is to reverse engineer the timer. But that is another project for another day. Right now I would be happy with hiding the thing.
回答1:
You would need to locate the window that is being represented in the taskbar, and remove the "show in taskbar" bit from its (extended) style. This will involve dropping down to the Windows API level. The functions you will need are:
- GetWindowLongPtr - to retrieve the existing extended style (
GWL_EXSTYLE
) - SetWindowLongPtr - to set the new existing extended style (
GWL_EXSTYLE
)
The extended style bit you need to remove is WS_EX_APPWINDOW.
Please see the SetWindowLongPtr docs for info about restrictions on the use of SetWindowLongPtr
to affect windows in other threads, and potentially needing to call SetWindowPos
to cause a visual update. Windows may even prevent you from doing this altogether (e.g. for security or usability reasons)
I haven't tested this and it may depend on the target application. Finally, if this does work it will remove the window from the taskbar altogether, which may be confusing when you re-show the window, so your app may want to re-enable the WS_EX_APPWINDOW
style before showing the other app's window.
来源:https://stackoverflow.com/questions/2157712/remove-application-from-taskbar-with-c-sharp-wrapper