가끔 개발하다보면 프로그램이 항상 활성화 되어야 하는 경우가 있습니다.
아래의 예제는 타이머를 이용하여 프로그램 비활성화 되었을 경우 활성화 시키는 예제입니다.
using System.Runtime.InteropServices;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string StrWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern void SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private const int SW_SHOWNORMAL = 1;
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
IntPtr procHandler = FindWindow(null, this.Text);
if (IntPtr.Zero != procHandler)
{
ShowWindow(procHandler, SW_SHOWNORMAL);
SetForegroundWindow(procHandler);
}
timer1.Enabled = true;
}
'C#' 카테고리의 다른 글
[C#/PDA]PDA에서 MySQL 접속 예제 (0) | 2016.01.29 |
---|---|
[C#]File 클래스를 이용한 파일 생성 예제 (0) | 2016.01.29 |
[C#]텍스트 파일의 라인수 구하기 예제 (0) | 2016.01.28 |
[C#]폼 또는 프로그램 종료, 닫히는 원인 확인하는 예제 (0) | 2016.01.28 |
[C#/PDA]가상키보드(Inputpanel) 위치 변경 예제 (0) | 2016.01.28 |