Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
курсак .doc
Скачиваний:
3
Добавлен:
01.07.2025
Размер:
1.25 Mб
Скачать

Список літератури

  1. В. Зиборов Visual C# 2010 на примерах

  2. Системное программное обеспечение / А.В.Гордеев, А.Ю.Молчанов.

  3. Э. Троелсен Язык программирования C# 2010 и платформа .NET 4.0

  4. Колисниченко Секреты, настройка и оптимизация реестра Windows 7

  5. Дж.Донован. Системное программирование.

Додатки

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

using Microsoft.Win32;

using System.Collections;

using System.Security;

using System.Security.AccessControl;

using System.Security.Permissions;

using System.Diagnostics;

namespace Brightness

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

[DllImport("brightness_dll.dll", CharSet=CharSet.Ansi)]

public static extern string GetPowerStatus();

[DllImport("brightness_dll.dll", CharSet = CharSet.Ansi)]

public static extern string GetBatteryFlag();

[DllImport("brightness_dll.dll", CharSet = CharSet.Ansi)]

public static extern int GetBatteryPercent();

[DllImport("brightness_dll.dll", CharSet = CharSet.Ansi)]

public static extern int GetBatteryTime();

[DllImport("brightness_dll.dll", CharSet = CharSet.Ansi)]

public static extern int GetFullBatteryTime();

[DllImport("brightness_dll.dll", CharSet = CharSet.Ansi)]

public static extern void SetBrightness(int Brightness);

short val;

private void SwitchImg()

{

Image img = Image.FromFile(@"img\8.png");

if (GetPowerStatus() == "Power on")

{

if (GetBatteryPercent() >= 95)

img = Image.FromFile(@"img\1.png");

if (GetBatteryPercent() < 95 && GetBatteryPercent() >= 20)

img = Image.FromFile(@"img\2.png");

if (GetBatteryPercent() < 20)

img = Image.FromFile(@"img\7.png");

pictureBox1.Image = img;

}

if (GetPowerStatus() == "Power off")

{

if (GetBatteryPercent() > 50)

img = Image.FromFile(@"img\3.png");

if (GetBatteryPercent() == 50)

img = Image.FromFile(@"img\4.png");

if (GetBatteryPercent() < 50 && GetBatteryPercent() > 10)

img = Image.FromFile(@"img\5.png");

if (GetBatteryPercent() <= 10)

img = Image.FromFile(@"img\6.png");

pictureBox1.Image = img;

}

if (GetBatteryFlag() == "Батарея відсутня")

{

img = Image.FromFile(@"img\8.png");

pictureBox1.Image = img;

}

}

Hashtable pow = new Hashtable();

string Active;

private void GetPowers()

{

RegistryKey Key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes");

string[] powers = Key.GetSubKeyNames();

Active = (string)Key.GetValue("ActivePowerScheme");

string Shema;

foreach (string str in powers)

{

Key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\" + str);

Shema = (string)Key.GetValue("FriendlyName");

try

{

Shema = Shema.Remove(0, Shema.LastIndexOf(",") + 1);

}

catch { }

pow.Add(Shema, str);

}

}

private void Create_radio()

{

RadioButton[] rb = { radioButton1, radioButton2, radioButton3, radioButton4, radioButton5, radioButton6 };

int i = 0;

foreach (DictionaryEntry de in pow)

{

rb[i].Visible = true;

rb[i].Text = (string)de.Key;

if (Active == de.Value.ToString())

{

rb[i].Checked = true;

}

i++;

}

for (int j = 0; j < i - 1; j++)

{

int h = this.Height + 23;

this.Size = new Size(this.Width, h);

groupBox3.Height = groupBox3.Height + 23;

}

}

private void Form1_Load(object sender, EventArgs e)

{

trackBar1.Value = 5;

val = (short)trackBar1.Value;

val = (short)(val * 25.5);

SetBrightness(val);

label2.Text = GetPowerStatus();

label3.Text = GetBatteryFlag();

label4.Text = GetBatteryPercent().ToString() + "%";

int total = GetBatteryTime();

if (total == -1)

label5.Text = "Невідомо";

else

{

int s, m, h;

s = total % 60;

total = total / 60;

m = total % 60;

h = total / 60;

label5.Text = h.ToString() + ":" + m.ToString() + ":" + s.ToString();

}

SwitchImg();

GetPowers();

if (pow.Count != 0)

{

int h = this.Height + 53;

this.Size = new Size(this.Width, h);

}

Create_radio();

}

private void trackBar1_Scroll(object sender, EventArgs e)

{

val = (short)trackBar1.Value;

val = (short)(val * 25.5);

SetBrightness(val);

}

private void timer1_Tick(object sender, EventArgs e)

{

label2.Text = GetPowerStatus();

label3.Text = GetBatteryFlag();

label4.Text = GetBatteryPercent().ToString() + "%";

int total = GetBatteryTime();

if (total == -1)

label5.Text = "Невідомо";

else

{

int s, m, h;

s = total % 60;

total = total / 60;

m = total % 60;

h = total / 60;

label5.Text = h.ToString() + ":" + m.ToString() + ":" + s.ToString();

}

SwitchImg();

}

private void radioButton6_CheckedChanged(object sender, EventArgs e)

{

ChangePow(radioButton6);

}

private void radioButton5_CheckedChanged(object sender, EventArgs e)

{

ChangePow(radioButton5);

}

private void radioButton4_CheckedChanged(object sender, EventArgs e)

{

ChangePow(radioButton4);

}

private void radioButton3_CheckedChanged(object sender, EventArgs e)

{

ChangePow(radioButton3);

}

private void radioButton2_CheckedChanged(object sender, EventArgs e)

{

ChangePow(radioButton2);

}

private void radioButton1_CheckedChanged(object sender, EventArgs e)

{

ChangePow(radioButton1);

}

private void ChangePow(RadioButton rb)

{

Active = (string)pow[rb.Text];

ProcessStartInfo prc = new ProcessStartInfo("Powercfg", "-setactive " + Active);

prc.WindowStyle = ProcessWindowStyle.Hidden;

Process.Start(prc);

}

}

}

#include "brightness.h"

#include "gammaramp.h"

extern "C" __declspec(dllexport) char * GetPowerStatus()

{

SYSTEM_POWER_STATUS sps;

if (GetSystemPowerStatus(&sps))

{

switch (sps.ACLineStatus) // печатаем статус питания

{

case 0:

return "Power off";

case 1:

return "Power on";

case 255:

default:

return "Невідомо";

break;

}

}

return "Unknown";

}

extern "C" __declspec(dllexport) char * GetBatteryFlag()

{

SYSTEM_POWER_STATUS sps;

GetSystemPowerStatus(&sps);

switch (sps.BatteryFlag) // статус заряда

{

case 1:

return "Високий";

case 2:

return "Низький";

case 4:

return "Критичний";

case 8:

return "Заряджається";

case 128:

return "Батарея відсутня";

case 255:

default:

return "Невідомий";

}

}

extern "C" __declspec(dllexport) int GetBatteryPercent()

{

SYSTEM_POWER_STATUS sps;

GetSystemPowerStatus(&sps);

return (int)sps.BatteryLifePercent;

}

extern "C" __declspec(dllexport) int GetBatteryTime()

{

SYSTEM_POWER_STATUS sps;

GetSystemPowerStatus(&sps);

return sps.BatteryLifeTime;

}

extern "C" __declspec(dllexport) int GetFullBatteryTime()

{

SYSTEM_POWER_STATUS sps;

GetSystemPowerStatus(&sps);

return sps.BatteryFullLifeTime;

}

extern "C" __declspec(dllexport) void SetBrightness(int Brightness)

{

CGammaRamp GammaRamp;

GammaRamp.SetBrightness(NULL, Brightness);

}

36

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]