/// <summary> /// 最小化按钮的事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void minBtn_Click(object sender, RoutedEventArgs e) { NcButtonDownEventArgs args = new NcButtonDownEventArgs(NcButtonDownEvent, this); this.RaiseEvent(args); SystemCommands.MinimizeWindow(Window.GetWindow(this)); }
/// <summary> /// 最大化按钮的事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void maxBtn_Click(object sender, RoutedEventArgs e) { NcButtonDownEventArgs args = new NcButtonDownEventArgs(NcButtonDownEvent, this); this.RaiseEvent(args); if (this.WindowState == System.Windows.WindowState.Maximized) { SystemCommands.RestoreWindow(Window.GetWindow(this)); } else { SystemCommands.MaximizeWindow(Window.GetWindow(this)); } }
/// <summary> /// 系统消息处理 /// </summary> /// <param name="hwnd"></param> /// <param name="msg"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <param name="handled"></param> /// <returns></returns> private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { IntPtr result = IntPtr.Zero; WM_MESSAGE message = (WM_MESSAGE)msg; switch (message) { case WM_MESSAGE.WM_NCLBUTTONDOWN: case WM_MESSAGE.WM_NCRBUTTONDOWN: NcButtonDownEventArgs args = new NcButtonDownEventArgs(NcButtonDownEvent, this); this.RaiseEvent(args); break; case WM_MESSAGE.WM_SETTINGCHANGE: { // 系统设置变更 this.CalculateBorderSize(); } break; case WM_MESSAGE.WM_DEVICECHANGE: int nEventType = wParam.ToInt32(); switch (nEventType) { case 0x8000: // DBT_DEVICEARRIVAL: Console.WriteLine(); break; case 0x8004: // DBT_DEVICEREMOVECOMPLETE: Console.WriteLine(); break; default: handled = false; return(result); } //try //{ // var temp = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_VOLUME)); //} //catch //{ // Console.WriteLine(); //} break; case WM_MESSAGE.WM_SYSCOMMAND: int cmd = wParam.ToInt32(); if (cmd == NativeMethods.SYSMENU_ABOUT_ID) { AboutMenuEventArgs args1 = new AboutMenuEventArgs(AboutMenuEvent, this); this.RaiseEvent(args1); } break; default: handled = false; break; } return(result); }