API함수
FindWindow(string lpClassName, string lpWindowName)
가장 최상위의 핸들을 찾는 함수.
인자값 - 찾을 클래스이름, 찾을 캡션값
프로그램의 최상위 핸들 값만 리턴
FindWindowEX(int hWnd1, int hWnd2, string lpsz1, string lpsz2)
자식 핸들을 찾는 함수
인자값 - 부모핸들값, 0 or null, 찾을 클래스명, 찾을 캡션명
Spy++
캡션명과 클래스이름을 확인할 수 있는 프로그램
C# 소스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// 외부 라이브러리 사용하기 위해 선언
using System.Runtime.InteropServices;
namespace HandleSearch
{
class Program
{
// 외부 라이브러리 선언
// extern : 메서드가 C# 코드 외부에서 구현
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2);
// STA : Single Threaded Apartment
// 최초 애플리케이션 스레드의 모델을 단일 스레드로 지정.
// 컴포넌트 오브젝트 모델과 상호 운용하기 위해 필요.
// <-> MTAThread
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("알캡처의 핸들값?");
Console.WriteLine("캡션값만 입력한 핸들값 : " + FindWindow(null, "알캡처").ToString());
Console.WriteLine("클래스명만 입력한 핸들값 : " + FindWindow("AlCapture_ScreenCaptureWnd", null).ToString());
int AlCapHw = FindWindow(null, "알캡처");
int AlCap_NewCap = FindWindowEx(AlCapHw, 0, "Button", "새 캡처");
Console.WriteLine("압캡처 핸들값 : " + AlCapHw.ToString());
Console.WriteLine("알캡처_새캡처 핸들값: " + AlCap_NewCap.ToString());
}
}
}
실행결과
'프로그래밍 > .NET' 카테고리의 다른 글
| DB 연결(오라클 10g) (0) | 2012.07.30 |
|---|---|
| 프로그램 제어(핸들값 이용) (0) | 2012.07.26 |
| Alert창 (0) | 2012.07.25 |
| 이미지 크기 변환 (0) | 2011.10.07 |
| 수평, 수직 히스토그램 (0) | 2011.10.07 |