zoukankan      html  css  js  c++  java
  • 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功能实现之窗口渐现效果

  • 相关阅读:
    关于python的open函数encoding的入参
    控制台输出的log加颜色
    logging把log写到控制台
    合并两个list里的字典
    关于字典数组和元组合并
    python字典做入参调用时要写成**K这种形式
    python在循环中将含变量的字典加到列表中(问题:如果写法不当,会导致最后赋值的变量覆盖列表中前面赋值的变量)
    给定列表,按照列表内容获取excel指定列名下的内容
    selenum报错element is not attached to the page document
    python selenium获取input输入框中的值
  • 原文地址:https://www.cnblogs.com/jcomet/p/1700403.html
Copyright © 2011-2022 走看看