c++ - Win32 : How to hide 3rd party windows in taskbar by hWnd

标签 c++ windows winapi

我必须在第三方库中隐藏弹出窗口。

我已经用 SetWindowsHookEx 实现了 Windows 钩子(Hook)的东西 |并知道所有新创建的 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);      

在任务栏中隐藏新创建的窗口我做错了什么?

最佳答案

在使用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

这是来自 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.

关于c++ - Win32 : How to hide 3rd party windows in taskbar by hWnd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24485664/

相关文章:

c++ - C++中的静态构造函数?我需要初始化私有(private)静态对象

c++ - 视觉 C++ : InvokeHelper() function

windows - EasyPHP 和 Windows 8 端口 127.0.0.1 问题

c++ - 在 64 位和 32 位窗口中读取注册表

c++ - 计算C++中相同运行进程的总数

winapi - 是否可以直接从 GDI+ 位图进行 BitBlt?

c++ - 如何比较 vector 和数组?

c++ - 如何从 C++ 中的 istream 中干净地提取字符串分隔字符串

python - 将特殊字符传递给 cmd.exe 中的 python 脚本

windows - 如何在 Windows Server 2008 R2 中关闭(禁用)Web 代理自动发现 (WPAD)