生成快速成启动按钮

2008年10月12日星期日

生成快速成启动按钮

[DllImport("shell32.dll")]
public static extern int SHGetFileInfo(string pszPath,
uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, uint uFlags);

public struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
//public char szDisplayName;
//public char szTypeName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
}

public static Image getImage(string strFileName)
{
bool isLargeIcon = true;

uint iconSize;
SHFILEINFO shellFileInfo = new SHFILEINFO();

//SHGFI_ICON|SHGFI_SMALLICON
if (isLargeIcon == true)
{
iconSize = 16640;
}
else
{
iconSize = 257;
}

int iTotal = (int)SHGetFileInfo(strFileName, 0, ref shellFileInfo, 100, iconSize);

Icon ic = Icon.FromHandle(shellFileInfo.hIcon);
Bitmap myBmp = ic.ToBitmap();
return myBmp;
}

///
/// 增中快捷方式
///

/// StatusStrip控件
/// 启动路径名
/// 自动生成编号
///
public string addCStatusStrip(StatusStrip ss,string strFileName,string autoName)
{
string resutl = "OK";
try
{
ToolStripDropDownButton toolSDDB;
toolSDDB = new System.Windows.Forms.ToolStripDropDownButton();
toolSDDB.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
toolSDDB.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
toolSDDB.Name = "toolSDDB_" + autoName;
toolSDDB.ShowDropDownArrow = false;
toolSDDB.Size = new System.Drawing.Size(84, 29);
toolSDDB.ToolTipText = strFileName.Substring(strFileName.LastIndexOf(@"\"));
toolSDDB.Click += new System.EventHandler(toolSDDB_Click);
toolSDDB.Tag = strFileName;

toolSDDB.Image = getImage(strFileName);
ss.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {toolSDDB});
}
catch { resutl = "NO"; }
return resutl;
}

      0 评论:

      发表评论