Win32:如何通过 hWnd 在任务栏中隐藏 3rd 方窗口

Win32: How to hide 3rd party windows in taskbar by hWnd(Win32:如何通过 hWnd 在任务栏中隐藏 3rd 方窗口)

本文介绍了Win32:如何通过 hWnd 在任务栏中隐藏 3rd 方窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to hide popup windows in third party library.

我已经使用 SetWindowsHookEx 实现了 Windows 挂钩内容a> 并知道所有新创建的 hWnd(s).我听 HSHELL_WINDOWCREATED 回调并执行以下操作:

I have implemented windows hook stuff with SetWindowsHookEx and know all the newely created hWnd(s). I listen to HSHELL_WINDOWCREATED callback and do the following:

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?

推荐答案

在使用SetWindowLong之前,先调用ShowWindow(hWnd, SW_HIDE),然后再调用SetWindowLong,然后像 ShowWindow(hWnd, SW_SHOW) 一样再次调用 ShowWindow.所以你的代码看起来像这样:

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:

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

这是来自 微软网站的相关引述:

为了防止窗口按钮被放置在任务栏上,创建具有 WS_EX_TOOLWINDOW 扩展样式的无主窗口.作为替代方案,您可以创建一个隐藏窗口并将其隐藏window 可见窗口的所有者.

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.

Shell 只会在以下情况下从任务栏中删除窗口按钮窗口的样式支持可见的任务栏按钮.如果你想将窗口的样式动态更改为不支持的样式可见的任务栏按钮,您必须先隐藏窗口(通过调用ShowWindow with SW_HIDE),更改窗口样式,然后显示窗口.

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.

这篇关于Win32:如何通过 hWnd 在任务栏中隐藏 3rd 方窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Win32:如何通过 hWnd 在任务栏中隐藏 3rd 方窗口

基础教程推荐