无边框窗口覆盖任务栏 [英] Borderless Window Covers Taskbar

查看:46
本文介绍了无边框窗口覆盖任务栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定制的无边框窗口.最大化时,它会覆盖任务栏.这不是我想要的.我玩过 WM_GETMINMAXINFO 消息.但是,我发现 Windows 10 会在底部和右侧留下额外的 8 像素间隙.这是一个全有或全无的命题.这是我尝试的第一个代码:

I have a custom-made borderless window. When maximized, it covers the taskbar. This is not what I want. I have played with the WM_GETMINMAXINFO message. But, I have found that Windows 10 will then leave an extra 8-pixel gap along both the bottom and right side. It is an all-or-nothing proposition. Here is the first code that I tried:

case WM_GETMINMAXINFO:
     PMINMAXINFO pmm;
     pmm = (PMINMAXINFO)lParam;
     pmm->ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
     pmm->ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
     return 0;

这个结果与我的相同,没有钩住 WM_GETMINMAXINFO 消息.所以,我从底部敲了两个像素,这样我就可以访问任务栏(处于自动隐藏"模式):

The result of this is identical to what I had, without hooking the WM_GETMINMAXINFO message. So, I knocked two pixels off of the bottom, so I could access the taskbar (which is in "autohide" mode":

case WM_GETMINMAXINFO:
     PMINMAXINFO pmm;
     pmm = (PMINMAXINFO)lParam;
     pmm->ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
     pmm->ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN)-2;
     return 0;

突然间,底部出现10像素间隙,右侧出现 8像素间隙!这似乎是 Windows 10 的事情,因为这在 Win7 中从未发生过.我也试过SystemParametersInfo,调用SPI_GETWORKAREA(而不是GetSystemMetrics()).这会产生相同的结果.

Suddenly, I have a 10-pixel gap on the bottom, and a new 8-pixel gap on the right side! this appears to be a Windows 10 thing, as this never happened with Win7. I have also tried SystemParametersInfo, calling SPI_GETWORKAREA (instead of GetSystemMetrics()). This yields the same results.

据我所知,问题不在于WM_GETMINMAXINFO不是.相反,我需要将命令放入我的代码中,以将任务栏保持在顶部.我已经搜索了 Windows 样式.但是,我在那里找不到任何帮助.

From what I gather, the problem is not with WM_GETMINMAXINFO. Instead, I need to put a command into my code, to keep the taskbar on top. I have searched through the windows styles. But, I have found nothing of help there.

有谁知道如何解决这个关键问题.

Does anyone know how to fix this critical problem.

推荐答案

好吧,我在一个最不可能的地方找到了答案.有人试图用 Python 代码操纵边界.从他们的尝试中,我能够为无边界窗口设计一个 C++ 解决方案.结果如下:

Well, I found the answer in a most unlikely place. Someone was trying to manipulate borders with Python code. From their attempt, I was able to devise a solution for a borderless window, in C++. Here is the result:

首先,我用 WS_OVERLAPPEDWINDOW | 创建了一个窗口.WS_VISIBLE 样式,启用所有 Windows 功能.然后我用这个代码处理了 WM_NCCALCSIZE 消息:

To start, I created a window with the WS_OVERLAPPEDWINDOW | WS_VISIBLE style, to enable all Windows functions. I then handled the WM_NCCALCSIZE message with this code:

case WM_NCCALCSIZE:
 {
    WINDOWPLACEMENT      wp;
    LPNCCALCSIZE_PARAMS  szr;

    wp.length = sizeof(WINDOWPLACEMENT);
    GetWindowPlacement(hWnd, &wp);
    szr = LPNCCALCSIZE_PARAMS(lParam);
    if (wp.showCmd == SW_SHOWMAXIMIZED)  szr->rgrc[0].bottom -= (WFRAME+2);
    return 0;
 }

在上面的代码中,我从第一个矩形的底部减去边框的宽度.添加了额外的 2 个像素,以暴露自动隐藏的任务栏.最大化的窗口现在正常运行,允许访问任务栏.

In the code above, I subtracted the width of the border from the bottom of the first rectangle. The extra 2 pixels were added, to expose the bit of the auto-hidden taskbar. The maximized window now acts as it should, allowing access to the taskbar.

为了在这个无边框窗口中创建我的虚拟客户区,我在 WM_CREATEWM_SIZE 处理程序中添加了这段代码:

To create my virtual client area in this borderless window, I added this bit of code to both the WM_CREATE and WM_SIZE handlers:

WINDOWPLACEMENT  wp;
GetWindowRect(hWnd, &rWnd);
GetClientRect(hWnd, &rClient);
wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hWnd, &wp);
rClient.left += WFRAME;  rClient.right -= WFRAME;    rClient.top += (WFRAME+cyMenu);
if (wp.showCmd == SW_SHOWNORMAL)  rClient.bottom -= WFRAME;
cxClient = rClient.right-rClient.left;
cyClient = rClient.bottom-rClient.top;

元素 cyMenu 是为我的虚拟菜单栏保留的空间.它将包含一系列按钮,模拟菜单和最小/最大/关闭按钮.

The element cyMenu is a space reserved for my virtual menu bar. It will contain a series of buttons, simulating the menu and min/max/close buttons.

这篇关于无边框窗口覆盖任务栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆