protected override void WndProc(ref Message m) { switch (m.Msg) { case (int)Msg.WM_NOTIFY: OFNOTIFY ofNotify = (OFNOTIFY)Marshal.PtrToStructure(m.LParam, typeof(OFNOTIFY)); if (ofNotify.hdr.code == (uint)DialogChangeStatus.CDN_SELCHANGE) { StringBuilder filePath = new StringBuilder(256); Win32.SendMessage(Win32.GetParent(mhandle), (int)DialogChangeProperties.CDM_GETFILEPATH, (int)256, filePath); if (FileNameChanged != null) { FileNameChanged(this, filePath.ToString()); } } else if (ofNotify.hdr.code == (uint)DialogChangeStatus.CDN_FOLDERCHANGE) { StringBuilder folderPath = new StringBuilder(256); Win32.SendMessage(Win32.GetParent(mhandle), (int)DialogChangeProperties.CDM_GETFOLDERPATH, (int)256, folderPath); if (FolderNameChanged != null) { FolderNameChanged(this, folderPath.ToString()); } } break; } base.WndProc(ref m); }
protected override void WndProc(ref Message m) { //Debug.WriteLine(m); if (m.Msg == WM_NOTIFY) { OFNOTIFY ofNotify = (OFNOTIFY)Marshal.PtrToStructure(m.LParam, typeof(OFNOTIFY)); if (ofNotify.hdr.code == (uint)DialogChangeStatus.CDN_SELCHANGE) { StringBuilder filePath = new StringBuilder(256); uint cd = 0x0465;//CDM_GETFILEPATH; SendMessage(parent, cd, (IntPtr)256, filePath); if (filePath.ToString() != "") { if (filePath.ToString().ToLower().EndsWith("bmp") || filePath.ToString().ToLower().EndsWith("png") || filePath.ToString().ToLower().EndsWith("jpg")) { ((AddPrevControl)addControl).SetImage(filePath.ToString()); } } } } base.WndProc(ref m); }
protected override void WndProc(ref Message m) { Msg msg = (Msg)m.Msg; if (msg != Msg.WM_NOTIFY) { if (msg == Msg.WM_COMMAND) { int dlgCtrlID = NativeMethods.GetDlgCtrlID(m.LParam); if (dlgCtrlID == 1 || dlgCtrlID != 2) { } } } else { OFNOTIFY ofNotify = (OFNOTIFY)Marshal.PtrToStructure(m.LParam, typeof(OFNOTIFY)); switch (ofNotify.hdr.code) { case 4294966689u: { int i = ((OPENFILENAME)Marshal.PtrToStructure(ofNotify.OpenFileName, typeof(OPENFILENAME))).nFilterIndex; if (this._CustomCtrl != null && this._filterIndex != i) { this._filterIndex = i; this._CustomCtrl.OnFilterChanged(this, i); } break; } case 4294966693u: { StringBuilder folderPath = new StringBuilder(256); NativeMethods.SendMessage(new HandleRef(this, NativeMethods.GetParent(base.Handle)), 1126u, (IntPtr)256, folderPath); if (this._CustomCtrl != null) { this._CustomCtrl.OnFolderNameChanged(this, folderPath.ToString()); } break; } case 4294966694u: { StringBuilder filePath = new StringBuilder(256); NativeMethods.SendMessage(new HandleRef(this, NativeMethods.GetParent(base.Handle)), 1125u, (IntPtr)256, filePath); if (this._CustomCtrl != null) { this._CustomCtrl.OnFileNameChanged(this, filePath.ToString()); } break; } } } base.WndProc(ref m); }
protected override void WndProc(ref Message m) { switch ((Msg)m.Msg) { case Msg.WM_NOTIFY: OFNOTIFY ofNotify = (OFNOTIFY)Marshal.PtrToStructure(m.LParam, typeof(OFNOTIFY)); switch (ofNotify.hdr.code) { case (uint)DialogChangeStatus.CDN_SELCHANGE: { StringBuilder filePath = new StringBuilder(256); NativeMethods.SendMessage(new HandleRef(this, NativeMethods.GetParent(Handle)), (uint)DialogChangeProperties.CDM_GETFILEPATH, (IntPtr)256, filePath); if (_CustomCtrl != null) { _CustomCtrl.OnFileNameChanged(this, filePath.ToString()); } } break; case (uint)DialogChangeStatus.CDN_FOLDERCHANGE: { StringBuilder folderPath = new StringBuilder(256); NativeMethods.SendMessage(new HandleRef(this, NativeMethods.GetParent(Handle)), (int)DialogChangeProperties.CDM_GETFOLDERPATH, (IntPtr)256, folderPath); if (_CustomCtrl != null) { _CustomCtrl.OnFolderNameChanged(this, folderPath.ToString()); } } break; case (uint)DialogChangeStatus.CDN_TYPECHANGE: { OPENFILENAME ofn = (OPENFILENAME)Marshal.PtrToStructure(ofNotify.OpenFileName, typeof(OPENFILENAME)); int i = ofn.nFilterIndex; if (_CustomCtrl != null && _filterIndex != i) { _filterIndex = i; _CustomCtrl.OnFilterChanged(this as IWin32Window, i); } } break; case (uint)DialogChangeStatus.CDN_INITDONE: break; case (uint)DialogChangeStatus.CDN_SHAREVIOLATION: break; case (uint)DialogChangeStatus.CDN_HELP: break; case (uint)DialogChangeStatus.CDN_INCLUDEITEM: break; case (uint)DialogChangeStatus.CDN_FILEOK: //0xfffffda2: #pragma warning disable 1690, 0414 //NativeMethods.SetWindowPos(_CustomCtrl._hFileDialogHandle, IntPtr.Zero, //(int)_CustomCtrl._OpenDialogWindowRect.left, //(int)_CustomCtrl._OpenDialogWindowRect.top, //(int)_CustomCtrl._OpenDialogWindowRect.Width, //(int)_CustomCtrl._OpenDialogWindowRect.Height, //FileDialogControlBase.MSFileDialogWrapper.UFLAGSSIZE); break; #pragma warning restore 1690, 0414 default: break; } break; case Msg.WM_COMMAND: switch (NativeMethods.GetDlgCtrlID(m.LParam)) //switch (m.WParam & 0x0000ffff) { case (int)ControlsId.ButtonOk: //OK break; case (int)ControlsId.ButtonCancel: //Cancel break; case (int)ControlsId.ButtonHelp: //0x0000040e://help break; } break; default: break; } base.WndProc(ref m); }
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); //艾宏增加 多选文件时,获取第一个文件名 string temppath = filePath.ToString(); int index = temppath.IndexOf(" \""); //多个文件名中间由 ' "'分隔 if (index > 0) { temppath = temppath.Substring(0, index); } temppath = temppath.Replace("\"", ""); //多选文件名时,需要去掉中间的'"'字符 OnPathChanged(this, temppath); 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); }
protected override void WndProc(ref Message m) { switch (m.Msg) { case (int)Msg.WM_CLOSE: { if (mSourceControl != null) { CancelEventArgs e = new CancelEventArgs(); e.Cancel = false; mSourceControl.OnClosingDialog(e); //if (e.Cancel == true && mIsOpen == true) // return; } } break; case (int)Msg.WM_SHOWWINDOW: mInitializated = true; InitControls(); break; case (int)Msg.WM_WINDOWPOSCHANGING: if (!mIsClosing) { if (!mInitializated) { WINDOWPOS pos = (WINDOWPOS)Marshal.PtrToStructure(m.LParam, typeof(WINDOWPOS)); if (mSourceControl.StartLocation == AddonWindowLocation.Right) { if (pos.flags != 0 && ((pos.flags & (int)SWP_Flags.SWP_NOSIZE) != (int)SWP_Flags.SWP_NOSIZE)) { mOriginalSize = new Size(pos.cx, pos.cy); pos.cx += mSourceControl.Width; Marshal.StructureToPtr(pos, m.LParam, true); } } if (mSourceControl.StartLocation == AddonWindowLocation.Bottom) { if (pos.flags != 0 && ((pos.flags & (int)SWP_Flags.SWP_NOSIZE) != (int)SWP_Flags.SWP_NOSIZE)) { mOriginalSize = new Size(pos.cx, pos.cy); pos.cy += mSourceControl.Height; Marshal.StructureToPtr(pos, m.LParam, true); } } } RECT currentSize; switch (mSourceControl.StartLocation) { case AddonWindowLocation.Right: currentSize = new RECT(); Win32.GetClientRect(mOpenDialogHandle, ref currentSize); mSourceControl.Height = (int)currentSize.Height; break; case AddonWindowLocation.Bottom: currentSize = new RECT(); Win32.GetClientRect(mOpenDialogHandle, ref currentSize); mSourceControl.Width = (int)currentSize.Width; break; case AddonWindowLocation.None: currentSize = new RECT(); Win32.GetClientRect(mOpenDialogHandle, ref currentSize); mSourceControl.Width = (int)currentSize.Width; mSourceControl.Height = (int)currentSize.Height; break; } } break; case (int)Msg.WM_IME_NOTIFY: if (m.WParam == (IntPtr)ImeNotify.IMN_CLOSESTATUSWINDOW) { mIsClosing = true; CancelEventArgs e = new CancelEventArgs(); e.Cancel = false; mSourceControl.OnClosingDialog(e); Win32.SetWindowPos(mOpenDialogHandle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE); Win32.GetWindowRect(mOpenDialogHandle, ref mOpenDialogWindowRect); Win32.SetWindowPos(mOpenDialogHandle, IntPtr.Zero, (int)(mOpenDialogWindowRect.left), (int)(mOpenDialogWindowRect.top), (int)(mOriginalSize.Width), (int)(mOriginalSize.Height), UFLAGSSIZE); } break; case (int)Msg.WM_COMMAND: if (m.WParam.ToInt32() == 1) //´ò¿ª { mIsOpen = true; OFNOTIFY ofNotify = new OFNOTIFY(); ofNotify.fileNameShareViolation = IntPtr.Zero; StringBuilder strbuf = new StringBuilder(256); Win32.GetWindowText(mComboFileName, strbuf, 256); if (strbuf.Length > 0) { ofNotify.OPENFILENAME = Marshal.StringToBSTR(strbuf.ToString()); ofNotify.hdr.code = (uint)DialogChangeStatus.CDN_SELCHANGE; int rawsize = Marshal.SizeOf(ofNotify); byte[] rawdata = new byte[rawsize]; GCHandle handle = GCHandle.Alloc(rawdata, GCHandleType.Pinned); IntPtr wParam = handle.AddrOfPinnedObject(); Marshal.StructureToPtr(ofNotify, wParam, false); //Win32.SendMessage(mhwnd, (int)Msg.WM_NOTIFY, IntPtr.Zero, wParam); handle.Free(); CancelEventArgs e = new CancelEventArgs(); e.Cancel = false; mSourceControl.OnClosingDialog(e); if (e.Cancel == true) { if (File.Exists(strbuf.ToString())) { string strDir = Path.GetDirectoryName(strbuf.ToString()); if (strDir.Length <= 0) { return; } Win32.SetWindowText(mComboFileName, new StringBuilder(strDir)); } } } } else if (m.WParam.ToInt32() == 2) //È¡Ïû { mIsOpen = false; } break; } base.WndProc(ref m); }