hWnd Property

See Also4LM30JD              Example11XRXYUF>Low               Example21XRXYUG>Low

Applies To

Form14TJ2LN, MDI form1ILMZQ7, check box9P3BU5, combo box1YZXFF6, command buttonXJSPC0, directory list boxO9U5A0, drive list box5WJO0PW, file list box1M6S8UX, frame1KX6ZP8, grid2VGT0PT, list boxG11UCK, OLE control2HQDVVU, option buttonJYBO08, picture box31MYIWX, scroll bar1JSJOS7, text boxYPYZDG.

Description

Specifies a handle164OMS7 to a form or control.  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 APIDEFAPI 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

IntegerDOKXHY


See Also

Help:

Declare StatementN31O9K

hDC PropertyZVPW3G

Icon Property2S1DMPP

 

Programmer's Guide:

Chapter 22, "Calling Procedures in DLLs"


hWnd Property Example 1

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


hWnd Property Example 2

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