(This series of articles is original from lemon (lc_mtt). Please indicate the source for reprinting. Thank you ~)
Next to the previous section: (C #) Windows Shell programming Series 8-different icons with different extension names?
QueryInfo Extension
The Active Desktop introduces a new feature. When you hover your mouse over a specific object, the tooltip displays their descriptions. We can use QueryInfo extension to provide custom tooltip for other objects in Shell. For example:
In fact, this function is easier to implement than the first two Shell extensions. It only implements the IQueryInfo interface:
IQueryInfo Interface Definition
[ComImport (), ComVisible (true), InterfaceType (ComInterfaceType. InterfaceIsIUnknown), guidattriwn ("00021500-0000-0000-c000-000000000046")]
Public interface IQueryInfo
{
[PreserveSig]
Uint GetInfoTip (uint dwFlags, out IntPtr pszInfoTip );
[PreserveSig]
Uint GetInfoFlags (out uint dwFlags );
}
The IQueryInfo Interface contains only two functions. Currently, GetInfoFlags is not supported and 0 must be returned.
GetInfoTip () Let's return the tooltip text string. Its parameters:
DwFlags is not currently used.
PszInfoTip is a pointer to a Unicode string pointer variable. We want to assign it a pointer to the string buffer we have allocated.
Do you still remember to use the IPersistFile interface to retrieve a single file path and save it in the szFileName variable? You can also use:
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 = "------------- Content preview ------------- \ r \ n" + text;
PszInfoTip = Marshal. StringToCoTaskMemUni (tip );
Return S_ OK;
}
Code: http://files.cnblogs.com/lemony/MyContextMenu.rar
This chapter seems too simple. The next chapter describes how to use the IShellPropSheetExt interface to add an attribute page to a file/folder, as shown below: