首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

在Windows窗体应用程序窗体中嵌入文件资源管理器实例

在Windows窗体应用程序中嵌入文件资源管理器实例,可以使用以下方法:

  1. 使用Windows Forms的WebBrowser控件。
  2. 使用第三方控件,如Explorer Browser。
  3. 使用Windows API。

以下是使用WebBrowser控件的示例代码:

代码语言:csharp
复制
using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            webBrowser1.Navigate("explorer.exe");
        }
    }
}

以上代码将在WebBrowser控件中嵌入文件资源管理器实例。

使用第三方控件Explorer Browser的示例代码如下:

代码语言:csharp
复制
using System;
using System.Windows.Forms;
using ShellDll;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            explorerBrowser1.Navigate("C:\\");
        }
    }
}

以上代码将在Explorer Browser控件中嵌入文件资源管理器实例。

使用Windows API的示例代码如下:

代码语言:csharp
复制
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        [DllImport("shell32.dll")]
        static extern int SHCreateShellItem(IntPtr pidlParent, IntPtr psfParent, IntPtr pidl, out IShellItem ppsi);

        public Form1()
        {
            InitializeComponent();
            SHCreateShellItem(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, out IShellItem ppsi);
            ppsi.BindToHandler(null, BHID.BHID_SFObject, typeof(IShellFolder).GUID, out object folder);
            IShellFolder2 shellFolder = (IShellFolder2)folder;
            shellFolder.GetDefaultSearchGUID(out Guid category);
            shellFolder.EnumObjects(IntPtr.Zero, SHCONTF.SHCONTF_FOLDERS | SHCONTF.SHCONTF_NONFOLDERS | SHCONTF.SHCONTF_INCLUDEHIDDEN, out IEnumIDList enumIDList);
            enumIDList.Reset();
            IntPtr[] pidls = new IntPtr[1];
            uint fetched;
            while (enumIDList.Next(1, pidls, out fetched) == 0)
            {
                SHCreateShellItem(IntPtr.Zero, IntPtr.Zero, pidls[0], out IShellItem item);
                listView1.Items.Add(item.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY), item.GetDisplayName(SIGDN.SIGDN_PARENTRELATIVEPARSING));
            }
        }
    }
}

以上代码将在ListView控件中嵌入文件资源管理器实例。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的视频

领券