You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Win32应用多显示器场景下隐藏全部任务栏的问题求解

多显示器场景下隐藏所有任务栏的实现方案

原有代码仅匹配了类名为Shell_TrayWnd的窗口,这是Windows主显示器对应的任务栏窗口类,副显示器的任务栏窗口类为Shell_SecondaryTrayWnd,需要枚举所有匹配这两类的窗口统一处理即可。

修正后的实现代码如下:

#include <windows.h>
#include <tchar.h>

void ShowTaskbar(bool bShow)
{
    HWND hTaskbar = NULL;
    // 处理主显示器任务栏
    hTaskbar = ::FindWindow(_T("Shell_TrayWnd"), NULL);
    if (hTaskbar != NULL)
    {
        ::ShowWindow(hTaskbar, bShow ? SW_SHOW : SW_HIDE);
    }
    // 遍历处理所有副显示器任务栏
    while ((hTaskbar = ::FindWindowEx(NULL, hTaskbar, _T("Shell_SecondaryTrayWnd"), NULL)) != NULL)
    {
        ::ShowWindow(hTaskbar, bShow ? SW_SHOW : SW_HIDE);
    }
}

注意事项

  • 该实现兼容Windows 8及以上系统,副显示器独立任务栏是Windows 8版本开始新增的特性
  • 程序无需额外提权,普通用户权限即可完成窗口显示状态修改
  • 程序退出前建议主动恢复任务栏显示,避免用户系统出现任务栏异常的问题

内容的提问来源于stack exchange,提问作者WStar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 06:57:03