Loading

WPF 开发的实用小工具(附源码)持续更新

前言

看最近比较冷清,我来暖暖场。

 点击链接加入群聊

【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

 新更新 滚动增加动画

 

 源码下载地址

 gitee

下载解压后体验

posted @ 2020-10-29 15:15  驚鏵  阅读(1435)  评论(6编辑  收藏  举报