Home » Windows API

GetForegroundWindow

說明:
GetForegroundWindow 函式可取得目前系統中前景程式的視窗代碼(Handle)


引用函式庫:
User32


適用系統:
Windows NT 3.1 或 Windows 95以上


函式原型:

Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" ( _
    ) As Long



參數型態及說明:


回傳值:
Long 呼叫成功的話,將會回傳視窗代碼(Handle);若呼叫失敗的話,則回傳 NULL

.NET Framework API:
System.Windows.Forms.Form.ActiveForm


VB範例:

檢視原始碼 Visual Basic
1
2
3
4
5
6
7
8
'VB的宣告
Private Declare Function GetForegroundWindow Lib "user32" ( _
	) As Long
 
Dim hwnd As Long
 
'取得目前系統中前景程式的視窗(Handle)
hwnd = GetForegroundWindow()

RB範例:

檢視原始碼 REALBasic
1
2
3
4
5
6
7
8
'RB的宣告
Declare Function GetForegroundWindow Lib "user32" ( _
	) As Integer
 
Dim hwnd As Integer
 
'取得目前系統中前景程式的視窗(Handle)
hwnd = GetForegroundWindow()

VB.NET範例:

1
2
3
4
5
6
7
8
9
10
'VB.NET的宣告
<DllImport("user32.dll")> _
Shared Function GetForegroundWindow( _
	) As IntPtr
End Function
 
Dim hwnd As IntPtr
 
'取得目前系統中前景程式的視窗(Handle)
hwnd = GetForegroundWindow()

C#範例:

1
2
3
4
5
6
7
8
9
//C#的宣告
[DllImport("user32")]
public static extern IntPtr GetForegroundWindow(
	);
 
IntPtr hwnd;
 
//取得目前系統中前景程式的視窗(Handle)
hwnd = GetForegroundWindow();

發表迴響