private bool DoFileOk(IntPtr lpOFN) { NativeMethods.OPENFILENAME_I openfilename_I = (NativeMethods.OPENFILENAME_I)UnsafeNativeMethods.PtrToStructure(lpOFN, typeof(NativeMethods.OPENFILENAME_I)); int value = this._dialogOptions.Value; int filterIndex = this._filterIndex; string[] fileNames = this._fileNames; bool flag = false; try { this._dialogOptions.Value = ((this._dialogOptions.Value & -2) | (openfilename_I.Flags & 1)); this._filterIndex = openfilename_I.nFilterIndex; this._charBuffer.PutCoTaskMem(openfilename_I.lpstrFile); if (!this.GetOption(512)) { this._fileNames = new string[] { this._charBuffer.GetString() }; } else { this._fileNames = FileDialog.GetMultiselectFiles(this._charBuffer); } if (this.ProcessFileNames()) { CancelEventArgs cancelEventArgs = new CancelEventArgs(); this.OnFileOk(cancelEventArgs); flag = !cancelEventArgs.Cancel; } } finally { if (!flag) { this._dialogOptions.Value = value; this._filterIndex = filterIndex; this._fileNames = fileNames; } } return(flag); }
protected override IntPtr HookProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam) { IntPtr result = IntPtr.Zero; if (msg == 78) { this._hwndFileDialog = UnsafeNativeMethods.GetParent(new HandleRef(this, hwnd)); NativeMethods.OFNOTIFY ofnotify = (NativeMethods.OFNOTIFY)UnsafeNativeMethods.PtrToStructure(lParam, typeof(NativeMethods.OFNOTIFY)); switch (ofnotify.hdr_code) { case -606: if (this._ignoreSecondFileOkNotification) { if (this._fileOkNotificationCount != 0) { this._ignoreSecondFileOkNotification = false; UnsafeNativeMethods.CriticalSetWindowLong(new HandleRef(this, hwnd), 0, NativeMethods.InvalidIntPtr); result = NativeMethods.InvalidIntPtr; break; } this._fileOkNotificationCount = 1; } if (!this.DoFileOk(ofnotify.lpOFN)) { UnsafeNativeMethods.CriticalSetWindowLong(new HandleRef(this, hwnd), 0, NativeMethods.InvalidIntPtr); result = NativeMethods.InvalidIntPtr; } break; case -604: this._ignoreSecondFileOkNotification = true; this._fileOkNotificationCount = 0; break; case -602: { NativeMethods.OPENFILENAME_I openfilename_I = (NativeMethods.OPENFILENAME_I)UnsafeNativeMethods.PtrToStructure(ofnotify.lpOFN, typeof(NativeMethods.OPENFILENAME_I)); int num = (int)UnsafeNativeMethods.UnsafeSendMessage(this._hwndFileDialog, (WindowMessage)1124, IntPtr.Zero, IntPtr.Zero); if (num > openfilename_I.nMaxFile) { int num2 = num + 2048; NativeMethods.CharBuffer charBuffer = NativeMethods.CharBuffer.CreateBuffer(num2); IntPtr lpstrFile = charBuffer.AllocCoTaskMem(); Marshal.FreeCoTaskMem(openfilename_I.lpstrFile); openfilename_I.lpstrFile = lpstrFile; openfilename_I.nMaxFile = num2; this._charBuffer = charBuffer; Marshal.StructureToPtr(openfilename_I, ofnotify.lpOFN, true); Marshal.StructureToPtr(ofnotify, lParam, true); } break; } case -601: base.MoveToScreenCenter(new HandleRef(this, this._hwndFileDialog)); break; } } else { result = base.HookProc(hwnd, msg, wParam, lParam); } return(result); }