基本信息
源码名称:电脑控制面板调节亮度c++代码
源码大小:0.03M
文件格式:.zip
开发语言:C/C++
更新时间:2024-07-10
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Windows.Forms;
using System.Management;
using System.Runtime.InteropServices;
namespace brightness
{
static class Program
{
private static IntPtr hdc;
private static byte CurrentBrightness;
[DllImport("user32.dll")]
private static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32")]
private static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, uint wParam, int lParam);
[DllImport("gdi32.dll")]
private unsafe static extern bool SetDeviceGammaRamp(IntPtr hdc, void* ramp);
[STAThread]
static void Main()
{
hdc = GetDC(IntPtr.Zero);
CurrentBrightness = GetBrightness();
SetBrightness(CurrentBrightness);
System.Timers.Timer timer1=new System.Timers.Timer();;
timer1.Enabled = true;
timer1.Interval = 1;
timer1.Elapsed = new System.Timers.ElapsedEventHandler(timer1_Elapsed);
System.Timers.Timer timer2 = new System.Timers.Timer(); ;
timer2.Enabled = true;
timer2.Interval = 1000;
timer2.Elapsed = new System.Timers.ElapsedEventHandler(timer2_Elapsed);
Application.Run();
}
static void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
byte k = GetBrightness();
if (CurrentBrightness != k)
{
SetBrightness(k);
CurrentBrightness = k;
}
}
static void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
SetBrightness(GetBrightness());
}
static byte GetBrightness()
{
ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\wmi");
ObjectQuery query = new ObjectQuery("Select * from WmiMonitorBrightness");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
foreach (ManagementObject m in searcher.Get())
{
return (byte)m["CurrentBrightness"];
}
return (byte)0x64;
}
public static unsafe bool SetBrightness(byte brightness)
{
short* gArray = stackalloc short[3 * 256];
short* idx = gArray;
for (int j = 0; j < 3; j )
{
for (int i = 0; i < 256; i )
{
int k = i * (50 brightness / 2) * 256 / 100;
*idx = (short)(k < 32768 ? k : k - 65536);
idx ;
}
}
return SetDeviceGammaRamp(hdc, gArray);
}
}
}
using System;
using System.Windows.Forms;
using System.Management;
using System.Runtime.InteropServices;
namespace brightness
{
static class Program
{
private static IntPtr hdc;
private static byte CurrentBrightness;
[DllImport("user32.dll")]
private static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32")]
private static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, uint wParam, int lParam);
[DllImport("gdi32.dll")]
private unsafe static extern bool SetDeviceGammaRamp(IntPtr hdc, void* ramp);
[STAThread]
static void Main()
{
hdc = GetDC(IntPtr.Zero);
CurrentBrightness = GetBrightness();
SetBrightness(CurrentBrightness);
System.Timers.Timer timer1=new System.Timers.Timer();;
timer1.Enabled = true;
timer1.Interval = 1;
timer1.Elapsed = new System.Timers.ElapsedEventHandler(timer1_Elapsed);
System.Timers.Timer timer2 = new System.Timers.Timer(); ;
timer2.Enabled = true;
timer2.Interval = 1000;
timer2.Elapsed = new System.Timers.ElapsedEventHandler(timer2_Elapsed);
Application.Run();
}
static void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
byte k = GetBrightness();
if (CurrentBrightness != k)
{
SetBrightness(k);
CurrentBrightness = k;
}
}
static void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
SetBrightness(GetBrightness());
}
static byte GetBrightness()
{
ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\wmi");
ObjectQuery query = new ObjectQuery("Select * from WmiMonitorBrightness");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
foreach (ManagementObject m in searcher.Get())
{
return (byte)m["CurrentBrightness"];
}
return (byte)0x64;
}
public static unsafe bool SetBrightness(byte brightness)
{
short* gArray = stackalloc short[3 * 256];
short* idx = gArray;
for (int j = 0; j < 3; j )
{
for (int i = 0; i < 256; i )
{
int k = i * (50 brightness / 2) * 256 / 100;
*idx = (short)(k < 32768 ? k : k - 65536);
idx ;
}
}
return SetDeviceGammaRamp(hdc, gArray);
}
}
}