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

2

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

问题描述

我正在创建一个桌面小工具",我已禁用手动最小化窗口,但现在还有另一个问题:如果用户按下 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.

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

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14