全部显示

Hwnd 属性

       

使用 hWnd 属性可以确定一个唯一的 Long Integer 值,该值是 Microsoft Windows 指定给当前窗口的句柄Long 型,可读写。

expression.Hwnd

expression  必需。返回“Applies To”列表中的一个对象的表达式。

说明

该属性仅在使用Visual Basic 时才可用。

可以在 Visual Basic 中使用该属性,来调用 Windows 应用程序编程接口 (API) 函数或其他外部例程,这些函数或外部例程需要将 hWnd 属性作为它们的参数。很多 Windows 函数都要求将当前窗口的 hWnd 属性值作为其参数之一。

注意  因为该属性值在程序运行时可能会更改,所以不要将 hWnd 属性值保存在公用变量中。

示例

下面的示例同时使用 hWnd 属性与 Windows API 的 IsZoomed 函数以确定窗口是否最大化。

' Enter on single line in Declarations section of Module window.
Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long

Sub Form_Activate()
    Dim intWindowHandle As Long
    intWindowHandle = Screen.ActiveForm.hWnd
    If Not IsZoomed(intWindowHandle) Then
        DoCmd.Maximize
    End If
End Sub