• 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功能实现之窗口渐现效果

  • 相关阅读:
    html 的一些基础操作
    java 通过反射调用属性,方法,构造器
    java 通过反射获取类属性结构,类方法,类父类及其泛型,类,接口和包
    java 反射,类的加载过程以及Classloader类加载器
    java 随机读写访问流及seek方法
    java 序列化机制
    java 标准输入输出流,打印流,数据流
    hp400 硒鼓加粉图解
    Delphi XE5 android 获取网络状态
    Delphi XE5 常见问题解答
  • 原文地址:https://www.cnblogs.com/jcomet/p/1700403.html
Copyright © 2020-2023  润新知