dankrusi / WindowsVirtualDesktopHelper

App to help manage Virtual Desktops for Windows 10 and Windows 11
Other
555 stars 36 forks source link

[Feature Request]: Full name of Desktop in Tray Icon #148

Open hdgk12jh3kj12h3lk opened 6 months ago

hdgk12jh3kj12h3lk commented 6 months ago

What feature?

I would LOVE to see this, if possible. Would really help a lot (initial isn't sufficient) and it sounds like a simple feature to add.

Thanks so much for this awesome tool!

Windows Version

Windows 10

dankrusi commented 2 weeks ago

Thanks, but its not so simple - displaying an icon is officially supported by Windows, but the icon is square and does not have enough space for a full name, displaying anything else (like a custom widget etc) is much more complicated and required hacks/workarounds with unofficial APIs...

dankrusi commented 1 week ago

Tried a Windows 11 implementation but can't get it to work:

`using System; using System.Drawing; using System.Reflection.Metadata; using System.Runtime.InteropServices; using System.Windows.Forms;

namespace CustomTrayApp { public class Program { [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll", SetLastError = true)]
    private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lpszClass, string lpszWindow);

    [DllImport("user32.dll", SetLastError = true)]
    private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

    [DllImport("user32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

    [DllImport("user32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    [DllImport("user32.dll", SetLastError = true)]
    private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

    private const int SW_SHOW = 5;
    private const uint SWP_NOACTIVATE = 0x0010;
    private const uint SWP_NOZORDER = 0x0004;
    private const int GWL_HWNDPARENT = -8;
    private const string TrayClass = "Shell_TrayWnd";
    private const string NotificationAreaClass = "TrayNotifyWnd";

    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        var trayHandle = FindTrayHandle();

        if(trayHandle != IntPtr.Zero) {
            var customForm = new CustomTrayForm();
            customForm.Load += (s, e) => {
                // Set the form's parent to the system tray window
                SetWindowLong(customForm.Handle, GWL_HWNDPARENT, trayHandle);
                // Optional: Adjust the position inside the tray area
                //SetWindowPos(customForm.Handle, IntPtr.Zero, 0, 0, customForm.Width, customForm.Height, SWP_NOACTIVATE | SWP_NOZORDER);
                ShowWindow(customForm.Handle, SW_SHOW);
            };

            Application.Run(customForm);
        } else {
            MessageBox.Show("Failed to find the system tray handle.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

    private static IntPtr FindTrayHandle() {
        // Find the handle of the taskbar (Shell_TrayWnd)
        IntPtr taskbarHandle = FindWindow(TrayClass, null);
        if(taskbarHandle == IntPtr.Zero)
            return IntPtr.Zero;

        // Find the handle of the notification area (TrayNotifyWnd) within the taskbar
        IntPtr notifyHandle = FindWindowEx(taskbarHandle, IntPtr.Zero, NotificationAreaClass, null);
        return notifyHandle;
    }
}

public class CustomTrayForm : Form {
    public CustomTrayForm() {
        // Create a small form that acts like a UI element in the system tray
        Size = new Size(150, 30);
        FormBorderStyle = FormBorderStyle.None;
        BackColor = Color.LightBlue;
    }

    protected override void OnPaint(PaintEventArgs e) {
        base.OnPaint(e);
        e.Graphics.DrawString("My Tray UI", Font, Brushes.Black, new PointF(10, 10));
    }
}

} `

I don't think Windows 11 allows this anymore. Do you know any apps which do this, without re-implementing the entire taskbar?

dankrusi commented 1 week ago

One method might be to create a whole bunch of icons, one for each letter. Not the nicest solution but it would technically work and be officially supported by Microsoft.

Is anyone interested in this?