C# show form information in Windows 11 taskbar

72 views Asked by At

I make a simple Form that can be shown over Windows TaskBar between the last program icon and first systray icon. That works fine in Windows 10 but not in Windows 11

Handle of Shell_TrayWnd was fine retrieve in Windows 10 and Windows 11

Some idea what change ?

Thanks in advance

Here my code :

[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();

1

There are 1 answers

2
smoorke On

the problem here is SetParent doesn't do what you think it does.

try using SetWindowLong(Handle, GWL_HWNDPARENT, _oTargetWnd);