| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | 
							- using System;
 
- using System.Windows;
 
- using System.Windows.Input;
 
- using System.Windows.Interop;
 
- namespace OpenSEMI.Ctrlib.Window
 
- {
 
- 	public class CustomWnd : System.Windows.Window
 
- 	{
 
- 		private HwndSource curHwndSource = null;
 
- 		private HwndSourceHook curHwndSourceHook = null;
 
- 		static CustomWnd()
 
- 		{
 
- 			FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomWnd), new FrameworkPropertyMetadata(typeof(CustomWnd)));
 
- 		}
 
- 		public CustomWnd()
 
- 		{
 
- 			base.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, CloseWindow));
 
- 			base.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, MaximizeWindow, CanResizeWindow));
 
- 			base.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, MinimizeWindow));
 
- 			base.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, RestoreWindow, CanResizeWindow));
 
- 		}
 
- 		private void CanResizeWindow(object sender, CanExecuteRoutedEventArgs e)
 
- 		{
 
- 			e.CanExecute = (base.ResizeMode == ResizeMode.CanResize || base.ResizeMode == ResizeMode.CanResizeWithGrip);
 
- 		}
 
- 		private void RestoreWindow(object sender, ExecutedRoutedEventArgs e)
 
- 		{
 
- 			base.WindowState = WindowState.Normal;
 
- 		}
 
- 		private void MinimizeWindow(object sender, ExecutedRoutedEventArgs e)
 
- 		{
 
- 			base.WindowState = WindowState.Minimized;
 
- 		}
 
- 		private void MaximizeWindow(object sender, ExecutedRoutedEventArgs e)
 
- 		{
 
- 			base.WindowState = WindowState.Maximized;
 
- 		}
 
- 		private void CloseWindow(object sender, ExecutedRoutedEventArgs e)
 
- 		{
 
- 			Close();
 
- 		}
 
- 		protected override void OnSourceInitialized(EventArgs e)
 
- 		{
 
- 			base.OnSourceInitialized(e);
 
- 			IntPtr handle = new WindowInteropHelper(this).Handle;
 
- 			curHwndSource = HwndSource.FromHwnd(handle);
 
- 			if (curHwndSource != null)
 
- 			{
 
- 				curHwndSourceHook = this.WndProc;
 
- 				curHwndSource.AddHook(curHwndSourceHook);
 
- 			}
 
- 		}
 
- 		private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
 
- 		{
 
- 			IntPtr zero = IntPtr.Zero;
 
- 			if (msg != 26)
 
- 			{
 
- 				handled = false;
 
- 			}
 
- 			return zero;
 
- 		}
 
- 	}
 
- }
 
 
  |