操作隐藏的托盘图标需要使用系统的图标管理功能。下面是一个示例代码,用于隐藏托盘图标:

using System;
using System.Runtime.InteropServices;

public class TrayIconManager
{
    // 定义系统图标管理的常量
    private const int SW_HIDE = 0;
    private const int SW_SHOW = 1;

    // 导入系统函数,用于隐藏和显示窗口
    [DllImport("user32.dll")]
    private static extern IntPtr FindWindow(string className, string windowName);
    
    [DllImport("user32.dll")]
    private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    public static void HideTrayIcon()
    {
        // 查找系统托盘窗口的类名和窗口名
        IntPtr trayHandle = FindWindow("Shell_TrayWnd", null);
        IntPtr trayNotifyHandle = FindWindow("TrayNotifyWnd", null);

        // 隐藏系统托盘窗口
        ShowWindow(trayHandle, SW_HIDE);
        ShowWindow(trayNotifyHandle, SW_HIDE);
    }

    public static void ShowTrayIcon()
    {
        // 查找系统托盘窗口的类名和窗口名
        IntPtr trayHandle = FindWindow("Shell_TrayWnd", null);
        IntPtr trayNotifyHandle = FindWindow("TrayNotifyWnd", null);

        // 显示系统托盘窗口
        ShowWindow(trayHandle, SW_SHOW);
        ShowWindow(trayNotifyHandle, SW_SHOW);
    }
}

public class Program
{
    public static void Main()
    {
        // 隐藏托盘图标
        TrayIconManager.HideTrayIcon();

        // 做其他操作...

        // 显示托盘图标
        TrayIconManager.ShowTrayIcon();
    }
}

这段代码使用了FindWindow函数来查找系统托盘窗口的句柄,然后使用ShowWindow函数来隐藏或显示该窗口。注意,这段代码是基于C#语言的Windows平台实现,如果在其他平台或使用其他编程语言,则需要相应的调整。

C# 代码实现 操作 隐藏的托盘图标

原文地址: https://www.cveoy.top/t/topic/qiM5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录