Windows7 では、カスタマイズされたファイルを開くダイアログ (WPF アプリケーション) を使用しています。My Open File ダイアログは から派生してい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);