EyesBaby功能实现之Windows前景色调节器

其实所谓Windows前景色调节器就是利用Winform窗体遮盖整个Windows区域。主要要求实现窗口透明,且鼠标可以穿过窗体点击其他程序。

难点就是怎么样让鼠标穿透窗体,代码也是从网上找的,现在找不到原链接了:)

 

原理就是调用Windows API设置窗口的属性。

代码:

复制代码
代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

/*
 * 作者:Billy Qing
 * 日期:2009年11月20日
 * 说明:EyesBaby Windows 前景窗口。
 * 版本:1.0
 
*/
namespace EyesBaby
{
    
public partial class WinScreenAdjust : Form
    {
        
/*
         * 下面这段代码主要用来调用Windows API实现窗体透明(鼠标可以穿透窗体)
         *  也是从网上找的:)
         
*/
        [DllImport(
"user32.dll", EntryPoint = "GetWindowLong")]
        
public static extern long GetWindowLong(IntPtr hwnd, int nIndex);
        [DllImport(
"user32.dll", EntryPoint = "SetWindowLong")]
        
public static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);
        [DllImport(
"user32", EntryPoint = "SetLayeredWindowAttributes")]
        
private static extern int SetLayeredWindowAttributes(IntPtr Handle, int crKey, byte bAlpha, int dwFlags);
        
const int GWL_EXSTYLE = -20;
        
const int WS_EX_TRANSPARENT = 0x20;
        
const int WS_EX_LAYERED = 0x80000;
        
const int LWA_ALPHA = 2
        
public WinScreenAdjust()
        {
            InitializeComponent();
        }

        
private void Form1_Load(object sender, EventArgs e)
        {
            
// 取消窗体任务栏
            ShowInTaskbar = false;
            
// 窗体位于Windows最顶部
            this.TopMost = true;
            
// 去除窗体边框
            this.FormBorderStyle = FormBorderStyle.None;
            
// 设置窗体最大化大小(除底部任务栏部分)
            this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
            
// 设置Windows窗口状态为最大化模式
            this.WindowState = FormWindowState.Maximized;
            
// 设置Windows属性
            SetWindowLong(this.Handle, GWL_EXSTYLE, GetWindowLong(this.Handle, GWL_EXSTYLE) | WS_EX_TRANSPARENT | WS_EX_LAYERED);
            SetLayeredWindowAttributes(
this.Handle, 0128, LWA_ALPHA);  
        }
    }
}
复制代码

 

 

至于EyesBaby中给窗体设置颜色部分就比较简单了。

代码:

 

复制代码

            
// 打开颜色选择对话框 ,并分析是否选择了对话框中的确定按钮 
            if (this.colColorAdjust.ShowDialog() == DialogResult.OK)
            {
                
int[] item=colColorAdjust.CustomColors;
                
// 将先中的颜色设置为窗体的背景色
                this.winAdjust.BackColor = colColorAdjust.Color;
                
// 保存到配置文件
                ConfigHelper.WinForeColor = this.winAdjust.BackColor.Name;
            }
复制代码

 

源代码下载地址:http://eyesbaby.codeplex.com/

安装版下载地址:https://files.cnblogs.com/yizhuqing/EyesBabySetup10.zip

我的第一款实用工具-眼保程序(EyesBaby)

EyesBaby1.0使用帮助文档

EyesBaby功能实现之窗口拖拽与缩放功能

EyesBaby功能实现之图片控件上添加字符

EyesBaby功能实现之Windows前景色调节器

EyesBaby功能实现之软件更新

EyesBaby功能实现之窗口渐现效果

 

  

 欢迎加入EyesBaby开发小组

 EyesBaby需求反馈小组

 

posted on   木子清  阅读(1273)  评论(0编辑  收藏  举报

编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了

导航

< 2010年1月 >
27 28 29 30 31 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31 1 2 3 4 5 6

统计

我的网站:道道工作室
点击右上角即可分享
微信分享提示