728x90
반응형
728x170
▶ ExecutionState.cs
using System;
namespace TestProject
{
/// <summary>
/// 실행 상태
/// </summary>
[FlagsAttribute]
public enum ExecutionState : uint
{
/// <summary>
/// ES_AWAYMODE_REQUIRED
/// </summary>
ES_AWAYMODE_REQUIRED = 0x00000040,
/// <summary>
/// ES_CONTINUOUS
/// </summary>
ES_CONTINUOUS = 0x80000000,
/// <summary>
/// ES_DISPLAY_REQUIRED
/// </summary>
ES_DISPLAY_REQUIRED = 0x00000002,
/// <summary>
/// ES_SYSTEM_REQUIRED
/// </summary>
ES_SYSTEM_REQUIRED = 0x00000001
}
}
728x90
▶ SleepModeHelper.cs
using System.Runtime.InteropServices;
namespace TestProject
{
/// <summary>
/// 절전 모드 헬퍼
/// </summary>
public static class SleepModeHelper
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Import
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 스레드 실행 상태 설정하기 - SetThreadExecutionState(state)
/// <summary>
/// 스레드 실행 상태 설정하기
/// </summary>
/// <param name="state">실행 상태</param>
/// <returns>실행 상태</returns>
[DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
private static extern ExecutionState SetThreadExecutionState(ExecutionState state);
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public
#region 절전 모드 방지하기 - Prevent()
/// <summary>
/// 절전 모드 방지하기
/// </summary>
public static void Prevent()
{
SetThreadExecutionState
(
ExecutionState.ES_CONTINUOUS |
ExecutionState.ES_SYSTEM_REQUIRED |
ExecutionState.ES_AWAYMODE_REQUIRED |
ExecutionState.ES_DISPLAY_REQUIRED
);
}
#endregion
#region 절전 모드 허용하기 - Allow()
/// <summary>
/// 절전 모드 허용하기
/// </summary>
public static void Allow()
{
SetThreadExecutionState(ExecutionState.ES_CONTINUOUS);
}
#endregion
}
}
300x250
▶ MainForm.cs
using System;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.button.Click += button_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 버튼 클릭시 처리하기 - button_Click(sender, e)
/// <summary>
/// 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void button_Click(object sender, EventArgs e)
{
if(this.button.Text == "방지하기")
{
SleepModeHelper.Prevent();
this.button.Text = "허용하기";
this.messageLabel.Text = "화면 보호기/절전 모드 방지중";
}
else
{
SleepModeHelper.Allow();
this.button.Text = "방지하기";
this.messageLabel.Text = "화면 보호기/절전 모드 허용중";
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] Graphics 클래스 : DrawString 메소드를 사용해 회전 텍스트 그리기 (0) | 2020.12.26 |
---|---|
[C#/WINFORM] PointF 구조체 : 포인트 밀접 여부 구하기 (0) | 2020.12.26 |
[C#/WINFORM] RichTextBox 클래스 : 테이블 추가하기 (0) | 2020.12.26 |
[C#/WINFORM] RichTextBox 클래스 : 이미지 캡처하기 (0) | 2020.12.25 |
[C#/WINFORM] Bitmap 클래스 : 합성 이미지 만들기 (0) | 2020.12.25 |
[C#/WINFORM] Form 클래스 : CreateParams 속성을 사용해 작업 전환기(Tab Switcher)에서 애플리케이션 숨기기 (0) | 2020.12.19 |
[C#/WINFORM] SVG 이미지 사용하기 (0) | 2020.12.19 |
[C#/WINFORM] 관리자 권한으로 실행하기 (0) | 2020.12.18 |
[C#/WINFORM] 화면 캡처 방지하기 (0) | 2020.12.17 |
[C#/WINFORM] Control 클래스 : WndProc 메소드를 사용해 데이터 수신하기 (0) | 2020.12.05 |
댓글을 달아 주세요