1

在 Windows7 中,我使用自定义的打开文件对话框(WPF 应用程序)。我的打开文件对话框源自Microsoft.Win32.CommonDialog. 对话框具有旧外观,如何将其更改为新外观(windows7 文件对话框外观(资源管理器样式))。

代码部分:

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);    
4

0 回答 0