WPF 秒表 计时器 定时关机 到计时关机
public const uint WM_SYSCOMMAND = 0x0112;
public const uint SC_MONITORPOWER = 0xF170;
[DllImport("user32")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, uint wParam, int lParam);
///
/// 关闭显示器
///
public void CloseScreen()
{
IntPtr windowHandle = Process.GetCurrentProcess().MainWindowHandle;
SendMessage(windowHandle, WM_SYSCOMMAND, SC_MONITORPOWER, 2); // 2 为关闭显示器, -1则打开显示器
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using IniFiles;
namespace StopWatch
{
///
/// shutdonwCtrl.xaml 的交互逻辑
///
public partial class shutdonwCtrl : UserControl
{
DispatcherTimer timer1;
DispatcherTimer timer2;
public shutdonwCtrl()
{
InitializeComponent();
timer1 = new DispatcherTimer();
timer1.Tick += new EventHandler(OnTimer1);
timer1.Interval = new TimeSpan(0, 0, 1);
timer2 = new DispatcherTimer();
timer2.Tick += new EventHandler(OnTimer2);
timer2.Interval = new TimeSpan(0, 0, 1);
btn_cancel.IsEnabled = false;
cancel1.IsEnabled = false;
}
IniFile INI = new IniFile(IniFile.AppIniName);
public void LoadIni()
{
cbo_hour.Text = INI.ReadString("定时关机", "时", "0");
cbo_Minute.Text = INI.ReadString("定时关机", "分", "0");
cbo_Second.Text = INI.ReadString("定时关机", "秒", "0");
cbo1.Text = INI.ReadString("到计时关机", "分", "0");
1