栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何以编程方式隐藏桌面图标?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何以编程方式隐藏桌面图标?

您可以使用Windows API来执行此操作。这是C#中的示例代码,它将切换桌面图标。

    [Dllimport("user32.dll", SetLastError = true)] static extern IntPtr FindWindow(string lpClassName, string lpWindowName);    [Dllimport("user32.dll", SetLastError = true)] static extern IntPtr GetWindow(IntPtr hWnd, GetWindow_Cmd uCmd);    enum GetWindow_Cmd : uint    {        GW_HWNDFIRST = 0,        GW_HWNDLAST = 1,        GW_HWNDNEXT = 2,        GW_HWNDPREV = 3,        GW_OWNER = 4,        GW_CHILD = 5,        GW_ENABLEDPOPUP = 6    }    [Dllimport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);    private const int WM_COMMAND = 0x111;    static void ToggleDesktopIcons()    {        var toggleDesktopCommand = new IntPtr(0x7402);        IntPtr hWnd = GetWindow(FindWindow("Progman", "Program Manager"), GetWindow_Cmd.GW_CHILD);        SendMessage(hWnd, WM_COMMAND, toggleDesktopCommand, IntPtr.Zero);    }

这会将消息发送到Progman的SHELLDLL_DefView子窗口,该窗口告诉它切换唯一子窗口“
FolderView”的可见性(通过添加或删除WS_VISIBLE样式)。“ FolderView”是包含图标的实际窗口。

要测试图标是否可见,可以使用GetWindowInfo函数查询WS_VISIBLE样式,如下所示:

    [return: MarshalAs(UnmanagedType.Bool)]    [Dllimport("user32.dll", SetLastError = true)]    private static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);    [StructLayout(LayoutKind.Sequential)]    public struct RECT    {        private int _Left;        private int _Top;        private int _Right;        private int _Bottom;    }    [StructLayout(LayoutKind.Sequential)]    struct WINDOWINFO    {        public uint cbSize;        public RECT rcWindow;        public RECT rcClient;        public uint dwStyle;        public uint dwExStyle;        public uint dwWindowStatus;        public uint cxWindowBorders;        public uint cyWindowBorders;        public ushort atomWindowType;        public ushort wCreatorVersion;        public WINDOWINFO(Boolean? filler) : this()   // Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".        { cbSize = (UInt32)(Marshal.SizeOf(typeof(WINDOWINFO)));        }    }

这是一个调用上述代码的函数,如果窗口可见,则返回true,否则返回false。

    static bool IsVisible()    {        IntPtr hWnd = GetWindow(GetWindow(FindWindow("Progman", "Program Manager"), GetWindow_Cmd.GW_CHILD), GetWindow_Cmd.GW_CHILD);        WINDOWINFO info = new WINDOWINFO();        info.cbSize = (uint)Marshal.SizeOf(info);        GetWindowInfo(hWnd, ref info);        return (info.dwStyle & 0x10000000) == 0x10000000;    }

Windows
API代码以及有关窗口样式的更多信息可在以下位置找到:http
:
//www.pinvoke.net/default.aspx/user32/GetWindowInfo.html



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/400779.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号