Home » Windows API

GetActiveWindow

說明:
GetActiveWindow 函式可取得呼叫此函式中活動的視窗代碼(Handle)


引用函式庫:
User32


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


函式原型:

Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" ( _
    ) 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 GetActiveWindow Lib "user32" ( _
	) As Long
 
Dim hwnd As Long
 
'取得呼叫此函數中活動的視窗(Handle)
hwnd = GetActiveWindow()

RB範例:

檢視原始碼 REALBasic
1
2
3
4
5
6
7
8
'RB的宣告
Declare Function GetActiveWindow Lib "user32" ( _
	) As Integer
 
Dim hwnd As Integer
 
'取得呼叫此函數中活動的視窗(Handle)
hwnd = GetActiveWindow()

VB.NET範例:

1
2
3
4
5
6
7
8
9
10
'VB.NET的宣告
<DllImport("user32.dll")> _
Shared Function GetActiveWindow( _
	) As IntPtr
End Function
 
Dim hwnd As IntPtr
 
'取得呼叫此函數中活動的視窗(Handle)
hwnd = GetActiveWindow()

C#範例:

1
2
3
4
5
6
7
8
9
//C#的宣告
[DllImport("user32")]
public static extern IntPtr GetActiveWindow(
	);
 
IntPtr hwnd;
 
//取得呼叫此函數中活動的視窗(Handle)
hwnd = GetActiveWindow();

註釋:
如果是要取得系統中前景程式視窗代碼(Handle)的話,則要使用 GetForegroundWindow 函式

發表迴響