前言
看最近比較冷清,我來暖暖場。
點擊鏈接加入群聊
【update】
1、新增托盤。
2、新增換膚。
3、透明度切換。
環境
Visual Studio 2019,dotNet Framework 4.0 SDK
本項目采用MVVM模式。
1.獲取主監視器上工作區域的尺寸。
2.並設置當前主窗體高度,設置窗體的Left與Top 到最右側。
private Rect desktopWorkingArea;
desktopWorkingArea = System.Windows.SystemParameters.WorkArea; this.Height = desktopWorkingArea.Height / 2; this.Left = desktopWorkingArea.Width - this.Width; this.Top = desktopWorkingArea.Height / 2 - (this.Height / 2);
3.移動窗體只允許Y軸 移動,調用Win32 的 MoveWindow。
#region 移動窗體 protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { anchorPoint = e.GetPosition(this); inDrag = true; CaptureMouse(); e.Handled = true; } protected override void OnMouseMove(MouseEventArgs e) { try { if (inDrag) { System.Windows.Point currentPoint = e.GetPosition(this); var y = this.Top + currentPoint.Y - anchorPoint.Y; Win32Api.RECT rect; Win32Api.GetWindowRect(new WindowInteropHelper(this).Handle, out rect); var w = rect.right - rect.left; var h = rect.bottom - rect.top; int x = Convert.ToInt32(PrimaryScreen.DESKTOP.Width - w); Win32Api.MoveWindow(new WindowInteropHelper(this).Handle, x, (int)y, w, h, 1); } } catch (Exception ex) { Log.Error($"MainView.OnMouseMove{ex.Message}"); } } protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { if (inDrag) { ReleaseMouseCapture(); inDrag = false; e.Handled = true; } } #endregion
4.在Tab鍵+Alt鍵切換時隱藏當前窗體。
WindowInteropHelper wndHelper = new WindowInteropHelper(this); int exStyle = (int)Win32Api.GetWindowLong(wndHelper.Handle, (int)Win32Api.GetWindowLongFields.GWL_EXSTYLE); exStyle |= (int)Win32Api.ExtendedWindowStyles.WS_EX_TOOLWINDOW; Win32Api.SetWindowLong(wndHelper.Handle, (int)Win32Api.GetWindowLongFields.GWL_EXSTYLE, (IntPtr)exStyle);
5.在窗體加載完成去注冊表讀取安裝的應用(還有系統桌面),獲取應用路徑后提取.ICO轉換為.PNG保存。
6.剩下的代碼都是wpf中的動畫和自動定義控件的代碼。
效果圖預覽
2020/11/09
新更新 滾動增加動畫