2012-11-13 19 views
0

在Windows7中我使用了自定義的打開文件對話框(WPF應用程序)。我的打開文件對話框源自Microsoft.Win32.CommonDialog。 對話框有舊的樣子,如何將其更改爲新的樣式(windows7文件對話框樣式(資源管理器樣式))。如何在wpf中自定義文件對話框

代碼部分:

private const int OFN_ENABLESIZING = 0x00800000; 
private const int OFN_EXPLORER = 0x00080000; 
private const int OFN_ENABLEHOOK = 0x00000020;  
protected override bool RunDialog(IntPtr hwndOwner) 
{ 
    OPENFILENAME_I.WndProc proc = new OPENFILENAME_I.WndProc(this.HookProc); 
        OPENFILENAME_I ofn = new OPENFILENAME_I(); 
    this._charBuffer = CharBuffer.CreateBuffer(0x2000); 
    if (this._fileNames != null) 
    { 
     this._charBuffer.PutString(this._fileNames[0]); 
    } 
    ofn.lStructSize = Marshal.SizeOf(typeof(OPENFILENAME_I)); 
    ofn.hwndOwner = hwndOwner; 
    ofn.hInstance = IntPtr.Zero; 
    ofn.lpstrFilter = MakeFilterString(this._filter, this.DereferenceLinks); 
    ofn.nFilterIndex = this._filterIndex; 
    ofn.lpstrFile = this._charBuffer.AllocCoTaskMem(); 
    ofn.nMaxFile = this._charBuffer.Length; 
    ofn.lpstrInitialDir = this._initialDirectory; 
    ofn.lpstrTitle = this._title; 
    ofn.Flags = OFN_EXPLORER | OFN_ENABLESIZING | OFN_ENABLEHOOK; 
    ofn.lpfnHook = proc; 
    ofn.FlagsEx = 0x1000000 ;  
    NativeMethods.GetOpenFileName(ofn); // 
} 

[SecurityCritical, SuppressUnmanagedCodeSecurity, DllImport("comdlg32.dll", CharSet = CharSet.Unicode, SetLastError = true)] 
internal static extern bool GetOpenFileName([In, Out] OPENFILENAME_I ofn);  

回答

2

看一看這個鏈接。它有自定義文件對話框。 http://www.ookii.org/software/dialogs/ 也許你可能需要根據你的需要調整它。

問候,

VIMAL

+0

則根據上面提示對話框的ShowReadOnly屬性被設置爲假。但對話框不顯示資源管理器樣式。 – MAnoop