티스토리 뷰
SetForegroundWindow 메쏘드를 이용한 샘플 코드이다.
1초에 한번씩 노트패드에 "abc " 스트링을 입력을 하는 것이다.
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ControlHandle
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Interval = 1000;
this.timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
Process[] processes = Process.GetProcessesByName("notepad");
foreach (Process process in processes)
{
IntPtr hWnd = process.MainWindowHandle;
this.textBox1.Text += hWnd.ToString() + Environment.NewLine;
SetForegroundWindow(hWnd);
SendKeys.SendWait("abc ");
}
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
아래는 실행 결과 화면이다.
1초에 한번씩 노트패드에 "abc " 스트링을 입력을 하는 것이다.
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ControlHandle
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Interval = 1000;
this.timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
Process[] processes = Process.GetProcessesByName("notepad");
foreach (Process process in processes)
{
IntPtr hWnd = process.MainWindowHandle;
this.textBox1.Text += hWnd.ToString() + Environment.NewLine;
SetForegroundWindow(hWnd);
SendKeys.SendWait("abc ");
}
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
아래는 실행 결과 화면이다.
'Code > C#' 카테고리의 다른 글
[C#] Extension Methods 사용법 (0) | 2008.02.11 |
---|---|
[C#] const vs readonly (0) | 2008.02.11 |
Process Class Sample Code 1 (0) | 2008.01.14 |
GenericDictionaryXmlSerializer 클래스 2 사용 예제 (0) | 2007.12.16 |
Generic Dictionary Xml Serialization C# Example 2 (0) | 2007.12.16 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Phalanger
- ScreenHunter
- tagREADYSTATE
- iTextSharp
- 애드센스감추기
- Regular Expressions
- Sample Code
- download.com
- autohotkey
- java
- c#
- Service pack
- registry
- AdSense감추기
- Rollback Rx
- WinAutomation
- Automation
- iText
- .net framework
- jre
- 스크린캡쳐
- 유틸리티
- Microsoft
- READYSTATE_COMPLETE
- windows
- AxWebBrowser
- DotNetMagic
- AdSense숨기기
- 애드센스숨기기
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함