선언:
C#
[DllImport("user32")]
public static extern IntPtr GetForegroundWindow();
VB.NET
<DllImport("user32")> _
Public Shared Function GetForegroundWindow() As IntPtr
End Function
사용 예제:
C#
using System;
using System.Runtime.InteropServices;
namespace ApiReference {
class ApiExample {
[DllImport("user32")]
public static extern IntPtr GetForegroundWindow();
public static void Main(string[] args) {
IntPtr hFgWnd = GetForegroundWindow();
Console.WriteLine("활성화된 윈도우 창의 핸들: 0x{0:X8}", hFgWnd.ToInt32());
Console.ReadKey(true);
}
}
}
VB.NET
Imports System
Imports System.Runtime.InteropServices
Namespace ApiReference
Class ApiExample
<DllImport("user32")> _
Public Shared Function GetForegroundWindow() As IntPtr
End Function
Public Shared Sub Main(args As String())
Dim hFgWnd As IntPtr = GetForegroundWindow()
Console.WriteLine("활성화된 윈도우 창의 핸들: 0x{0:X8}", hFgWnd.ToInt32())
Console.ReadKey(True)
End Sub
End Class
End Namespace
예제 실행 결과:
매개 변수 설명:
없음
API 설명:
활성화된(작업 중인) 윈도우의 핸들을 가져옵니다.
참고:
GetForegroundWindow (MSDN)
비고:
작업 중인 윈도우 창이 포커스를 잃는 도중에 이 API가 NULL(IntPtr.Zero) 값을 반환할 수도 있습니다.
'API Reference' 카테고리의 다른 글
30. GetWindowLong (0) | 2014.10.10 |
---|---|
29. SetWindowTheme (0) | 2014.10.09 |
27. AbortSystemShutdown (0) | 2014.10.08 |
26. InitiateSystemShutdown (0) | 2014.10.08 |
25. GetCurrentProcessId (0) | 2014.10.07 |