C# 在 Windows 11 任务栏中显示表单信息

问题描述 投票:0回答:1

我制作了一个简单的表单,可以在最后一个程序图标和第一个系统托盘图标之间的 Windows 任务栏上显示。 这在 Windows 10 中工作正常,但在 Windows 11 中不行

在 Windows 10 和 Windows 11 中可以很好地检索 Shell_TrayWnd 的句柄

知道有什么变化吗?

提前致谢

这是我的代码:

[DllImport("user32.dll")]
public static extern IntPtr GetDesktopWindow();
        
public FormTaskBar()
{
    InitializeComponent();
        
    // List all windows with extended information
    List<WindowInformation> lWinExtended = cProcWinList.GetAllWindowsExtendedInfo();

    // Search for the taskbar
    WindowInformation oTaskInfo = lWinExtended.Find(w => w.Class == "Shell_TrayWnd");
    _oTargetWnd = oTaskInfo.Handle;
    // Search for the tray icon
    _oTrayWnd = oTaskInfo.ChildWindows.Find(x => x.Class == "TrayNotifyWnd").Handle;

    cGlobal.oDebug?.Log("Shell_TrayWnd : " + _oTargetWnd);
    cGlobal.oDebug?.Log("TrayNotifyWnd : " + _oTrayWnd);
    UpdatePositions();

    // Attaches the control to the taskbar
    SafeNativeMethods.SetParent(Handle, _oTargetWnd);

    Show();

c# taskbar windows-11
1个回答
0
投票

这里的问题是 SetParent 并没有按照你想象的那样做。

尝试使用

SetWindowLong(Handle, GWL_HWNDPARENT, _oTargetWnd);

© www.soinside.com 2019 - 2024. All rights reserved.