Use WinAPI to hide the window in the taskbar in the C #

Trust me, I searched it on Google and expected it to be a fairly easy discovery – it turns out it’s not.
I have window handles, but no forms. What should I do Do?
Thank you!
declare these:

[DllImport(" user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private const int GWL_EX_STYLE = -20;
private const int WS_EX_APPWINDOW = 0x00040000, WS_EX_TOOLWINDOW = 0x00000080;

Then use it before displaying the form :

SetWindowLong(handle, GWL_EX_STYLE, (GetWindowLong(handle, GWL_EX_STYLE) | WS_EX_TOOLWINDOW) & ~WS_EX_APPWINDOW);

(Change the handle to the storage window Any content of the handle)

Trust me, I googled it and expected it to be a fairly easy discovery-it turns out it is not.
I have window handles , But no form. What should I do?
Thank you!

Declare these:

[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private const int GWL_EX_STYLE = -20;
private const int WS_EX_APPWINDOW = 0x00040000, WS_EX_TOOLWINDOW = 0x00000080;

Then use it before displaying the form:

SetWindowLong(handle, GWL_EX_STYLE, (GetWindowLong(handle, GWL_EX_STYLE) | WS_EX_TOOLWINDOW) & ~WS_EX_APPWINDOW);

(Change the handle to whatever stores the window handle)

Leave a Comment

Your email address will not be published.