See Also Example1 Example2
Applies To
Form, MDI form
Description
Specifies a handle Not available at design time; read-only at run time.
Usage
[form.][control.]hWnd
Remarks
The Windows environment identifies each form and control in an application by assigning it a handle, or hWnd. The hWnd is used with Windows API calls. Many Windows environment functions require the hWnd of the current window as an argument.
Note Because the value of this property can change while a program is running, never store the hWnd value in a variable.
Data Type
Integer
Help:
Declare Statement
hDC Property
Icon Property
Programmer's Guide:
Chapter 22, "Calling Procedures in DLLs"
The example forces a form to always remain on top. To try this example, create a form (not an MDI child form) and set its Caption property to "Always on top." Then give the form a menu containing a menu item named "mnuTopmost." Make sure the Declare statement is all on one line. Paste the code into the Declarations section of the form and press F5. (This example requires Microsoft Windows version 3.1.)
' Declare the Windows 3.1 API routine.
Declare Sub SetWindowPos Lib "User" (ByVal h1 As Integer, ByVal h2 As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal f As Long)
' Set some constant values (from WINAPI.TXT).
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Sub mnuTopmost_Click ()
' Add or remove the checkmark from the menu.
mnuTopmost.Checked = Not mnuTopmost.Checked
If mnuTopmost.Checked Then
' Turn on the TopMost attribute.
SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW
Else
' Turn off the TopMost attribute.
SetWindowPos hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW
End If
End Sub
The example automatically drops down the list portion of a combo box whenever the combo box gets the focus. To try this example, create a new form containing a combo box and option button (the option button is used only to receive the focus). Make sure the Declare statement is all on one line. Paste the code into the Declarations section of the form and press F5. Use the Tab key to move the focus to and from the combo box.
Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal Msg As Integer, ByVal Wp As Integer, Lp As Any) As Long
Const WM_USER = &H400
Sub Combo1_GotFocus ()
Const CB_SHOWDROPDOWN = WM_USER + 15
Dim Tmp
Tmp = SendMessage(Combo1.hWnd, CB_SHOWDROPDOWN, 1, ByVal 0&)
End Sub