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

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

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

 

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

代码:

ExpandedBlockStart.gif 代码
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,  0 128 , 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/

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

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

EyesBaby1.0使用帮助文档

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

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

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

EyesBaby功能实现之软件更新

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

转载于:https://www.cnblogs.com/jcomet/archive/2010/03/30/1700403.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值