EyesBaby功能實現之Windows前景色彩調節器

來源:互聯網
上載者:User

其實所謂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;
             }

出處:http://yizhuqing.cnblogs.com/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.