How to customize file dialog in wpf
        Posted  
        
            by 
                ManjuAnoop
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by ManjuAnoop
        
        
        
        Published on 2012-11-13T04:36:18Z
        Indexed on 
            2012/11/13
            5:00 UTC
        
        
        Read the original article
        Hit count: 222
        
In Windows7 I am using a customized Open File Dialog( WPF application). My Open File dialog is derived from Microsoft.Win32.CommonDialog. The dialog have old look, how to change this to new look (windows7 file dialog look(Explorer style)).
Code portion:
  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);
© Stack Overflow or respective owner