Returns a Form object for a given window handle or window number.
Set form = Form( wh% )
form:Form Object
wh%:iexp
Form(handle) returns a Form object for a given window handle. When the handle can't be found the return value is Nothing. This type of function Form() is in particular useful in the event subs _MessageProc and Screen_KeyPreview.
Form(n) designates the window-form created with OpenW or ChildW. Where n is a number between 0 and 31, the name of froms is predefined as Win_n, where n is a number between 0 and 31. This name is introduced in the global variable list and is accessible throughout the program. These variable names can be used in accessing properties, methods, and events. For instance, Win_1.Name returns "Win_1". Windows created with a number greater than 31 don't declare global variable names implicitly and can only be accessed using Form(n).Name. However, there is no variable name introduced, but their name still consists of "Win_n", where n is the window number.
Dim frm As Form
OpenW 1
Set frm = Form(Win_1.hWnd)
frm.Caption = "Window 1"
Form(1).BackColor = $8000000f
Win_1.FontTransparent = True
Print frm.Name
Do : Sleep : Until Win_1 Is Nothing
// Using frm is the Do...Until statement will cause the program into an infinite loop
// ...as closing Win_1 does not set frm to Nothing but does delete the object so
// ...that frm can no longer be accessed.
Trace IsNothing(frm)
Set frm = Nothing
Global key$, i%
Form test = , 0, 0, _X / 2, _Y / 2
For i% = 1 To 15 : OpenW i% : Next
PrintScroll = True
Do
Try
Print Form(GetActiveWindow()).Name
Catch
EndCatch
Sleep
Until key$ <> ""
For i% = 1 To 15 : CloseW i% : Next
test.Close
Sub Screen_KeyPreview(hWnd%, uMsg%, wParam%, lParam%, Cancel?)
If uMsg% = WM_CHAR Then key$ = wParam%
EndSub
The OCX(handle) function does the same as Form(Handle) for an Ocx control by returning a general Control object for a given window handle.
OCX(), Ocx, OcxOcx, Form, Screen_KeyPreview
{Created by Sjouke Hamstra; Last updated: 15/07/2015 by James Gaite}