선언:
C#
[DllImport("user32")]
public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
VB.NET
<DllImport("user32")> _
Public Shared Function FindWindow(lpClassName As [String], lpWindowName As [String]) As IntPtr
End Function
사용 예제:
C#
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
namespace ApiReference {
class ApiExample {
[DllImport("user32")]
public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
public static void Main(string[] args) {
IntPtr hNotepad = FindWindow("Notepad", null);
if ( hNotepad != IntPtr.Zero )
Console.WriteLine("메모장이 열려있습니다.");
else {
Console.WriteLine("메모장이 없습니다.");
Process.Start("notepad");
Thread.Sleep(1000);
hNotepad = FindWindow("Notepad", null);
if ( hNotepad != IntPtr.Zero )
Console.WriteLine("메모장이 열려있습니다.");
else
Console.WriteLine("메모장이 없습니다.");
}
Console.ReadKey(true);
}
}
}
VB.NET
Imports System
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports System.Threading
Namespace ApiReference
Class ApiExample
<DllImport("user32")> _
Public Shared Function FindWindow(lpClassName As [String], lpWindowName As [String]) As IntPtr
End Function
Public Shared Sub Main(args As String())
Dim hNotepad As IntPtr = FindWindow("Notepad", Nothing)
If hNotepad <> IntPtr.Zero Then
Console.WriteLine("메모장이 열려있습니다.")
Else
Console.WriteLine("메모장이 없습니다.")
Process.Start("notepad")
Thread.Sleep(1000)
hNotepad = FindWindow("Notepad", Nothing)
If hNotepad <> IntPtr.Zero Then
Console.WriteLine("메모장이 열려있습니다.")
Else
Console.WriteLine("메모장이 없습니다.")
End If
End If
Console.ReadKey(True)
End Sub
End Class
End Namespace
예제 실행 결과:
매개 변수 설명:
lpClassName - 찾을 윈도우의 클래스 이름을 입력합니다.
lpWindowName - 찾을 윈도우의 윈도우 창 제목을 입력합니다.
API 설명:
윈도우를 찾습니다.
참고:
FindWindow (MSDN)
요구 사항:
클라이언트: Windows 2000 Professional+
서버: Windows Server 2000+
비고:
클래스 이름이 생략된 경우(=NULL 값 또는 빈 문자열을 입력한 경우) 윈도우 이름으로 찾습니다.
윈도우 이름이 생략된 경우엔 클래스 이름을 이용하여 찾습니다. 이 때 클래스 이름은 반드시 입력되어야 합니다.
'API Reference' 카테고리의 다른 글
55. AccessMask (0) | 2015.09.13 |
---|---|
54. ShowWindow (0) | 2015.01.04 |
52. CommandLineToArgvW (0) | 2014.12.17 |
51. GetProcessMemoryInfo (0) | 2014.12.12 |
50. PROCESS_MEMORY_COUNTERS_EX (0) | 2014.12.12 |