ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

WPF开发的实用桌面管理小工具 ---- 系列文章

2022-07-25 22:32:06  阅读:210  来源: 互联网

标签:桌面 int ---- 源码 窗体 WPF rect Win32Api


目录

WPF 开发的实用小工具(附源码)持续更新(七)根据应用首个字的首字母按键定位 WPF 开发的实用小工具(附源码)持续更新(六)嵌入桌面 WPF 开发的实用小工具(附源码)持续更新(五)靠边隐藏 WPF 开发的实用小工具(附源码)持续更新(三)移除应用 WPF 开发的实用小工具(附源码)持续更新(二)拖动应用 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 onm ouseLeftButtonDown(MouseButtonEventArgs e)
        {
            anchorPoint = e.GetPosition(this);
            inDrag = true;
            CaptureMouse();
            e.Handled = true;
        }
        
        protected override void onm ouseMove(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 onm ouseLeftButtonUp(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

 新更新 滚动增加动画

 

github源码下载地址

gitee源码下载地址

下载解压后体验

 

出处:https://www.cnblogs.com/yanjinhua/p/13896894.html

标签:桌面,int,----,源码,窗体,WPF,rect,Win32Api
来源: https://www.cnblogs.com/mq0036/p/16519099.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有