In my project I need to hide the icon of an external application from taskbar. I am able to fetch appropriate window handle using FindWindow method in user32.dll
Is there any function to hide taskbar icon, something like:
HideTaskbarIcon (hwnd as IntPtr)
I have found the following code on google but can't understand the operators, can someone elaborate the operators used and their equivalent in visual basic:
long style= GetWindowLong(hWnd, GWL_STYLE);
style &= ~(WS_VISIBLE); // this works - window become invisible
style |= WS_EX_TOOLWINDOW; // flags don't work - windows remains in taskbar
style &= ~(WS_EX_APPWINDOW);
ShowWindow(hWnd, SW_HIDE); // hide the window
SetWindowLong(hWnd, GWL_STYLE, style); // set the style
ShowWindow(hWnd, SW_SHOW); // show the window for the new style to come into effect
ShowWindow(hWnd, SW_HIDE); // hide the window so we can't see it
No.
Window styles are expressed as a bitmask. The code in question is using bitwise
AND,NOT, andORoperators to manipulate the individual bits. It usesGetWindowLong()to retrieve the window's existing style bits, removes theWS_VISIBLEandWS_EX_APPWINDOWbits, adds theWS_EX_TOOLWINDOWbit, and then assigns the new bitmask back to the window. Only visible windows with theWS_EX_APPWINDOWbit can appear on the Taskbar.That being said, the original code is wrong. Extended window styles (ones with
_EX_in their names) cannot be retrieved/assigned usingGWL_STYLE,GWL_EXSTYLEmust be used instead, and there is no reason to ever manipulateWS_VISIBLEdirectly asShowWindow()handles that. The original code should have looked like this instead:Microsoft has documentation on that topic:
Logical and Bitwise Operators in Visual Basic
Logical/Bitwise Operators (Visual Basic)
For example: