(C#)Windows Shell 外殼編程系列9 – QueryInfo 擴充提示

來源:互聯網
上載者:User

(本系列文章由檸檬的(lc_mtt)原創,轉載請註明出處,謝謝~)

 

接上一節:(C#)Windows Shell 外殼編程系列8 - 同尾碼名不同表徵圖?

 

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;

 

 

代碼:http://files.cnblogs.com/lemony/MyContextMenu.rar

 

這一章似乎過於簡單。下一章將簡述如何使用 IShellPropSheetExt 介面為檔案/檔案夾增加屬性頁面,如下:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.