protected override void WndProc(ref Message m) { switch (m.Msg) { case (int)Msg.WM_SHOWWINDOW: mInitializated = true; InitControls(); mSourceControl.OnShow(EventArgs.Empty); 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; mSourceControl.OnClosingDialog(); 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; } base.WndProc(ref m); }
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); }