• (C#)Windows Shell 外壳编程系列9 QueryInfo 扩展提示


    (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢~)

    QueryInfo扩展
    活动桌面引入一项新特性,当你在某些特定对象上旋停鼠标时,工具提示将显示它们的描述。我们可以使用 QueryInfo 扩展为Shell中的其它对象提供自定义的工具提示。如下图:

    事实上,这个功能实现比前两个 Shell 扩展更简单,它仅仅是实现 IQueryInfo 接口:

    IQueryInfo 接口定义
    [ComImport(), ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), GuidAttribute("00021500-0000-0000-c000-000000000046")]
    public interface IQueryInfo
    {
        [PreserveSig]
    uint GetInfoTip(uint dwFlags, out IntPtr pszInfoTip);
        [PreserveSig]
    uint GetInfoFlags(out uint dwFlags);
    }

    IQueryInfo 接口只包含两个函数,其中 GetInfoFlags 目前还不被支持并且必须返回 0。

    GetInfoTip() 让我们返回工具提示文本 字符串。其参数:

    dwFlags 当前并不被使用。

    pszInfoTip 是个Unicode 字符串指针变量的指针,我们要将其赋值为我们所分配的字符串缓冲区的指针。

    还记得之前使用 IPersistFile 接口获取单个文件路径保存在 szFileName 变量中吗?现在也可以使用:

    GetInfoTip
    public uint GetInfoTip(uint dwFlags, out IntPtr pszInfoTip)
    {
        StreamReader sr = new StreamReader(szFileName, Encoding.GetEncoding("gb2312"));
    string text = sr.ReadToEnd();
        sr.Close();
    if (text.Length > 256)
        {
            text = text.Substring(0, 256) + "";
        }
    string tip = "------------- 内容预览 -------------\r\n\r\n" + text;
        pszInfoTip = Marshal.StringToCoTaskMemUni(tip);
    return S_OK;
    }

    代码:https://files.cnblogs.com/lemony/MyContextMenu.rar

    这一章似乎过于简单。下一章将简述如何使用 IShellPropSheetExt 接口为文件/文件夹增加属性页,如下:

  • 相关阅读:
    remove white space from read
    optimize the access speed of django website
    dowload image from requests
    run jupyter from command
    crawl wechat page
    python version 2.7 required which was not found in the registry windows 7
    health
    alternate rows shading using conditional formatting
    word
    【JAVA基础】static 关键字
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/1764032.html
Copyright © 2020-2023  润新知