protected override bool RunDialog(IntPtr hwndOwner) { bool flag; OPENFILENAME_I.WndProc proc = new OPENFILENAME_I.WndProc(this.HookProc); OPENFILENAME_I ofn = new OPENFILENAME_I(); try { 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 = this.Options | 0x880020; ofn.lpfnHook = proc; ofn.FlagsEx = 0x1000000; if ((this._defaultExtension != null) && this.AddExtension) { ofn.lpstrDefExt = this._defaultExtension; } if (_fakeKey != null) { ResetPlaces(); } if (m_places != null) { SetupFakeRegistryTree(); } flag = this.RunFileDialog(ofn); } finally { this._charBuffer = null; if (ofn.lpstrFile != IntPtr.Zero) { Marshal.FreeCoTaskMem(ofn.lpstrFile); } try { if (m_places != null) { ResetPlaces(); } } catch { } } return(flag); }
internal override bool RunFileDialog(OPENFILENAME_I ofn) { bool saveFileName = false; saveFileName = NativeMethods.GetSaveFileName(ofn); if (!saveFileName) { switch (NativeMethods.CommDlgExtendedError()) { case 0x3001: throw new InvalidOperationException("FileDialogSubClassFailure"); case 0x3002: throw new InvalidOperationException("FileDialogInvalidFileName" + base.SafeFileName); case 0x3003: throw new InvalidOperationException("FileDialogBufferTooSmall"); } } return(saveFileName); }
private bool DoFileOk(IntPtr lpOFN) { OPENFILENAME_I openfilename_i = (OPENFILENAME_I)Marshal.PtrToStructure(lpOFN, typeof(OPENFILENAME_I)); int num = this._dialogOptions; int num2 = this._filterIndex; string[] strArray = this._fileNames; bool flag = false; try { this._dialogOptions = (this._dialogOptions & -2) | (openfilename_i.Flags & 1); this._filterIndex = openfilename_i.nFilterIndex; this._charBuffer.PutCoTaskMem(openfilename_i.lpstrFile); if (!this.GetOption(0x200)) { this._fileNames = new string[] { this._charBuffer.GetString() }; } else { this._fileNames = GetMultiselectFiles(this._charBuffer); } if (this.ProcessFileNames()) { CancelEventArgs e = new CancelEventArgs(); this.OnFileOk(e); flag = !e.Cancel; } } finally { if (!flag) { this._dialogOptions = num; this._filterIndex = num2; this._fileNames = strArray; } } return(flag); }
internal static extern bool GetSaveFileName([In, Out] OPENFILENAME_I ofn);
internal abstract bool RunFileDialog(OPENFILENAME_I ofn);
private IntPtr ProcOnNotify(IntPtr hwnd, IntPtr lParam) { IntPtr hres = IntPtr.Zero; OFNOTIFY structure = (OFNOTIFY)Marshal.PtrToStructure(lParam, typeof(OFNOTIFY)); switch ((NativeMethods.DialogChangeStatus)structure.hdr_code) { case NativeMethods.DialogChangeStatus.CDN_FILEOK: //- 606: if (this._ignoreSecondFileOkNotification) { if (this._fileOkNotificationCount != 0) { this._ignoreSecondFileOkNotification = false; NativeMethods.CriticalSetWindowLong(new HandleRef(this, hwnd), 0, InvalidIntPtr); hres = InvalidIntPtr; break; } this._fileOkNotificationCount = 1; } if (!this.DoFileOk(structure.lpOFN)) { NativeMethods.CriticalSetWindowLong(new HandleRef(this, hwnd), 0, InvalidIntPtr); hres = InvalidIntPtr; } break; case NativeMethods.DialogChangeStatus.CDN_TYPECHANGE: { OPENFILENAME_I ofn = (OPENFILENAME_I)Marshal.PtrToStructure(structure.lpOFN, typeof(OPENFILENAME_I)); int i = ofn.nFilterIndex; OnFilterChanged(this, i); } break; case NativeMethods.DialogChangeStatus.CDN_HELP: // - 605: break; case NativeMethods.DialogChangeStatus.CDN_FOLDERCHANGE: //- 603: { StringBuilder folderPath = new StringBuilder(256); NativeMethods.SendMessage(new HandleRef(this, structure.hdr_hwndFrom), (int)DialogChangeProperties.CDM_GETFOLDERPATH, (IntPtr)256, folderPath); OnPathChanged(this, folderPath.ToString()); folderPath.Length = 0; } break; case NativeMethods.DialogChangeStatus.CDN_SHAREVIOLATION: //- 604: this._ignoreSecondFileOkNotification = true; this._fileOkNotificationCount = 0; break; case NativeMethods.DialogChangeStatus.CDN_SELCHANGE: //- 602: { OPENFILENAME_I openfilename_i = (OPENFILENAME_I)Marshal.PtrToStructure(structure.lpOFN, typeof(OPENFILENAME_I)); int num = (int)NativeMethods.UnsafeSendMessage(this._hwndFileDialog, 0x464, IntPtr.Zero, IntPtr.Zero); if (num > openfilename_i.nMaxFile) { int size = num + 0x800; CharBuffer buffer = CharBuffer.CreateBuffer(size); IntPtr ptr2 = buffer.AllocCoTaskMem(); Marshal.FreeCoTaskMem(openfilename_i.lpstrFile); openfilename_i.lpstrFile = ptr2; openfilename_i.nMaxFile = size; this._charBuffer = buffer; Marshal.StructureToPtr(openfilename_i, structure.lpOFN, true); Marshal.StructureToPtr(structure, lParam, true); } StringBuilder filePath = new StringBuilder(256); NativeMethods.SendMessage(new HandleRef(this, structure.hdr_hwndFrom), (uint)DialogChangeProperties.CDM_GETFILEPATH, (IntPtr)256, filePath); OnPathChanged(this, filePath.ToString()); filePath.Length = 0; break; } case NativeMethods.DialogChangeStatus.CDN_INITDONE: //- 601: { NativeMethods.PostMessage(new HandleRef(this, this._hwndFileDialogEmbedded), MSG_POST_CREATION, IntPtr.Zero, IntPtr.Zero); } break; } return(hres); }
private static extern IntPtr IntCriticalSetWindowLongPtr(HandleRef hWnd, int nIndex, OPENFILENAME_I.WndProc dwNewLong);