windows Win32:如何通过 hWnd 在任务栏中隐藏 3rd 方窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7219063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Win32: How to hide 3rd party windows in taskbar by hWnd
提问by Andrew Florko
I have to hide popup windows in third party library.
我必须在第三方库中隐藏弹出窗口。
I have implemented windows hook stuff with SetWindowsHookExand know all the newely created hWnd(s). I listen to HSHELL_WINDOWCREATED
callback and do the following:
我已经用SetWindowsHookEx实现了 Windows 钩子的东西,并且知道所有新创建的 hWnd(s)。我听HSHELL_WINDOWCREATED
回调并执行以下操作:
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);
SetWindowLong(hWnd, GWL_STYLE, style);
What I do wrong here to hide newely created windows in task bar?
我在这里做错了什么来隐藏任务栏中新创建的窗口?
回答by Seth Carnegie
Before you use SetWindowLong
, call ShowWindow(hWnd, SW_HIDE)
, then call SetWindowLong
, then call ShowWindow
again like ShowWindow(hWnd, SW_SHOW)
. So your code will look like this:
使用之前SetWindowLong
,调用ShowWindow(hWnd, SW_HIDE)
,然后调用SetWindowLong
,然后调用ShowWindow
再喜欢ShowWindow(hWnd, SW_SHOW)
。所以你的代码看起来像这样:
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
Here is a relevant quote from Microsoft's Website:
以下是微软网站的相关引述:
To prevent the window button from being placed on the taskbar, create the unowned window with the WS_EX_TOOLWINDOW extended style. As an alternative, you can create a hidden window and make this hidden window the owner of your visible window.
The Shell will remove a window's button from the taskbar only if the window's style supports visible taskbar buttons. If you want to dynamically change a window's style to one that doesn't support visible taskbar buttons, you must hide the window first (by calling ShowWindow with SW_HIDE), change the window style, and then show the window.
为防止窗口按钮放置在任务栏上,请使用 WS_EX_TOOLWINDOW 扩展样式创建无主窗口。作为替代方案,您可以创建一个隐藏窗口并使这个隐藏窗口成为您的可见窗口的所有者。
只有当窗口的样式支持可见的任务栏按钮时,Shell 才会从任务栏中删除窗口的按钮。如果要将窗口的样式动态更改为不支持可见任务栏按钮的样式,则必须先隐藏该窗口(通过使用 SW_HIDE 调用 ShowWindow),更改窗口样式,然后显示该窗口。
回答by user9375012
You must use GWL_EXSTYLE to get/set the EX flags, GWL_STYLE will not work for EX flags.
您必须使用 GWL_EXSTYLE 来获取/设置 EX 标志,GWL_STYLE 不适用于 EX 标志。