词条 | DestoryIcon |
释义 | DestoryIcon函数介绍Destroys an icon and frees any memory the icon occupied. 销毁一个图标并且释放该图标所占用的内存; 语法说明(Syntax)BOOL WINAPI DestroyIcon( __in HICON hIcon); 在C#.Net中的使用方法为 : [DllImport("user32.dll", EntryPoint = "DestroyIcon")] private static extern bool DestroyIcon(IntPtr handle); 参数(Parameters)hIcon [in] 图标的句柄 Type: HICON A handle to the icon to be destroyed. The icon must not be in use. 将要被销毁的图标的句柄,并且该图标不能正在被使用 返回值(Return value)Type: BOOL布尔值 If the function succeeds, the return value is nonzero.如果销毁图标成功则返回值为true; If the function fails, the return value is zero. To get extended error information, call GetLastError. 如果销毁图标失败返回值为false; 附注(Remarks)It is only necessary to call DestroyIcon for icons and cursors created with the following functions: CreateIconFromResourceEx (if called without the LR_SHARED flag), CreateIconIndirect, and CopyIcon. Do not use this function to destroy a shared icon. A shared icon is valid as long as the module from which it was loaded remains in memory. The following functions obtain a shared icon. LoadIconLoadImage (if you use the LR_SHARED flag) CopyImage (if you use the LR_COPYRETURNORG flag and the hImage parameter is a shared icon) CreateIconFromResourceCreateIconFromResourceEx (if you use the LR_SHARED flag) 范例(Examples)//调用SHGetFileInfo获取文件信息 [DllImport("Shell32.dll")] private 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; } [DllImport("user32.dll", EntryPoint = "DestroyIcon")] private static extern bool DestroyIcon(IntPtr handle); /// <summary> /// 获取文件的图标 /// </summary> /// <param name="imagelist"></param> /// <param name="filename"></param> /// <param name="tf"></param> public void SetIcon(ImageList imagelist, string filename, bool tf) { SHFILEINFO sfi = new SHFILEINFO(); int ntotal = 0; if (tf) { //SHGFI_ICON|SHGFI_SMALLICON ntotal = (int)SHGetFileInfo(filename, 0, ref sfi, 100, 16640); try { if (ntotal > 0) { Icon ico = Icon.FromHandle(sfi.hIcon); imagelist.Images.Add(ico); DestroyIcon(sfi.hIcon); } } catch (Exception e) { MessageBox.Show(e.ToString(), "错误提示:", 0, MessageBoxIcon.Error); } } else { ntotal = (int)SHGetFileInfo(filename, 0, ref sfi, 100, 257); try { if (ntotal > 0) { Icon ico = Icon.FromHandle(sfi.hIcon); imagelist.Images.Add(ico); DestroyIcon(sfi.hIcon); } } catch (Exception e) { MessageBox.Show(e .ToString (),"错误提示:",0,MessageBoxIcon.Error ); } } } |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。