c# 制作的资源管理器 问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 00:22:40
本人在 网上找了个资源管理器的代码 运行资源管理器 打开的文件夹中文件较多时就会出现 内存不足的情况
下面的 使用的 结构有问题 不过不知道怎么解决
谁可以帮忙解决下吗 下面是代码

[DllImport("Shell32.dll")]
public static extern int ExtractIcon(IntPtr h, string strx, int ii);

[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;
}
protected virtual Icon myExtractIcon(string FileName, int iIndex)
{
try
{
IntPtr hIcon = (IntPtr)ExtractIcon(this.Handle, FileName, iIndex);
if (!hIcon.Equals(null)

没有关闭句柄

楼主要习惯使用
try{
}catch(Exception Ex)
{
}finally
{
//在这里关闭句柄
closehandle(hIcon)
}

你是想制作类似于资源管理器的程序还是打开资源管理器,如果是打开资源管理器的话这样最简单:
Process.Start("explorer.exe", "E:\\");
第一个参数是让Process类的Start方法打开指定程序(此处为explorer.exe,也就是资源管理器,第二个参数是第一个参数的对应参数,此处也就是让explorer.exe从E盘打开资源管理器)。

你是说你获取图片的程序有问题啊
那好办,我之前写过一个获取图片的程序,根据网上的改了一点,能成功运行:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;

namespace FileList_Xml.PubFunctions
{
class GetIcons
{
//定义结构
[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public IntPtr iIcon;
public uint dwAttributes;
//非托管字符串
[MarshalAs(UnmanagedType.ByValTStr, S