如何始终保持窗口可见,但不强制它位于顶部

How to keep window visible at all times, but not force it to be on top(如何始终保持窗口可见,但不强制它位于顶部)

本文介绍了如何始终保持窗口可见,但不强制它位于顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个桌面小工具",我已禁用手动最小化窗口,但现在还有另一个问题:如果用户按下 Windows+D,例如.

I'm creating a "desktop gadget" of sorts, I've disabled manual minimizing of the window, but now there is another problem: the system can still hide the window if the user presses Windows+D, for example.

以这种方式隐藏时,不会触发通常的最小化/调整大小/可见性事件.我想做一些类似于 TopMost 的事情,但不强制窗口顺序.

When hidden that way, no usual minimize/resize/visibility events are fired. I want to do something almost like TopMost, but without forcing the window order.

也许可以使用 win32 API 安装全局快捷方式事件,并将 TopMost 短暂设置为 true,但这听起来很 hackish.

Maybe it's possible to install a global shortcut event using win32 API, and briefly set TopMost to true, but that sounds very hackish.

我找到了一种解决方案,但它似乎不适用于 Windows 10:通过显示桌面"/Win+D 保持窗口可见另一个常见的选项,即编写一个实际的桌面小工具,在 Windows 10 上是不可能的,因为它们已被弃用.

I found one solution, but it does not seem to work on Windows 10: Keeping window visible through "Show Desktop"/Win+D The other common option, which would be writing an actual desktop gadget, is not possible on Windows 10, given their deprecation.

是否有任何其他方法可以让窗口始终可见(但不在屏幕顶部)?

Are there any other methods to keep a window visible (but not on top of the screen) at all moments?

推荐答案

这个函数对我有用:

BOOL FixShowDesktop(HWND hWnd)
{
    HWND hWndTmp = FindWindowEx(NULL, NULL, L"Progman", NULL);
    if (hWndTmp)
    {
        hWndTmp = FindWindowEx(hWndTmp, NULL, L"SHELLDLL_DefView", NULL);
        if (hWndTmp)
        {
            SetWindowLongPtr(hWnd, -8, (LONG_PTR)hWndTmp);
            return TRUE;
        }
    }
    return FALSE;
}

注意,这段代码比 保持窗口可见要好一些通过显示桌面"/Win+D,因为该窗口可能会被其他窗口(与任何其他窗口一样)溢出.使用 SetParent 将窗口置于所有其他窗口之下.

Note, this code is a bit better then from Keeping window visible through "Show Desktop"/Win+D because the window can be overflowed by other windows (like any other window). Using SetParent places window under all other windows.

这篇关于如何始终保持窗口可见,但不强制它位于顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何始终保持窗口可见,但不强制它位于顶部

基础教程推荐