2009-08-15 64 views
0

我對P/Invoke不太好。任何人都可以告訴我如何在.NET中聲明和使用下面的shell32.dll函數?P/Invoke for shell32.dll的SHMultiFileProperties

http://msdn.microsoft.com/en-us/library/bb762230%28VS.85%29.aspx

HRESULT SHMultiFileProperties(  
    IDataObject *pdtobj, 
    DWORD dwFlags 
); 

它是用於顯示多個文件系統對象Windows外殼程序屬性對話框。

我已經想通了如何使用SHObjectProperties一個文件或文件夾:

[DllImport("shell32.dll", SetLastError = true)] 
static extern bool SHObjectProperties(uint hwnd, uint shopObjectType, [MarshalAs(UnmanagedType.LPWStr)] string pszObjectName, [MarshalAs(UnmanagedType.LPWStr)] string pszPropertyPage); 

public static void ShowDialog(Form parent, FileSystemInfo selected) 
{ 
    SHObjectProperties((uint)parent.Handle, (uint)ObjectType.File, selected.FullName, null)); 
} 

enum ObjectType 
{ 
    Printer = 0x01, 
    File = 0x02, 
    VoumeGuid = 0x04, 
} 

誰能幫助?

回答

4

在.NET Framework中有一個IDataObject接口和一個DataObject類。

[DllImport("shell32.dll", SetLastError = true)] 
static extern int SHMultiFileProperties(IDataObject pdtobj, int flags); 

public static void Foo() 
{ 
    var pdtobj = new DataObject(); 

    pdtobj.SetFileDropList(new StringCollection { @"C:\Users", @"C:\Windows" }); 

    if (SHMultiFileProperties(pdtobj, 0) != 0 /*S_OK*/) 
    { 
     throw new Win32Exception(); 
    } 
} 

編輯:我剛剛編譯和測試這和它的作品(彈出一些對話框,文件夾的外觀設置)。

+0

這讓我在正確的道路上,是一個問題的答案,那麼答案+,+ 1 但是,它更復雜。我正在尋找多文件屬性(如項目的總大小),而不是文件夾外觀設置。幸運的是,我在Code Project上找到了包含必要代碼的JFileManager: http://www.codeproject.com/KB/files/JFileManager.aspx 在JDropFiles類中查找CopyFilesToClipboardForDragDrop(paths,pt)。這有助於在IDataObject中創建Shell ID列表數據。 因此,它適用於Vista,但它仍然在Windows 2003上失敗。仍在尋找完美的解決方案。 – 2009-08-18 18:44:38

0

我可能讀你的問題不正確,但我認爲你正在尋找文件的擴展文件屬性。即打開Windows資源管理器和查看列,如屬性,所有者,版權,大小,創建日期等?

Shell32中有一個名爲GetDetailsOf的API提供這些信息。上codeproject 乾杯的起始物品, 約翰