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

王朝学院·作者佚名  2010-01-12  
宽屏版  字体: |||超大  

其实所谓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, 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;

}

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

EyesBaby1.0使用帮助文档

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

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

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有