OCX() Function

Purpose

Returns a Control object for a given window handle.

Syntax

Set co = OCX( hWnd )

co:Control Object
hWnd:Handle

Description

OCX() returns the general Ocx Control object for a given window handle. When the handle can't be found the return value is Nothing. The exact type of the Ocx can be obtained using the TypeOf(co) or TypeName() function. An alternative is to check for the name of the control using the Name property.

The function OCX() is in particular useful in the event subs _MessageProc and Screen_KeyPreview.

Example

Form frm1 = "GFA-Test", 10, 10, 250, 170

Ocx Command cmd1 = "But_1", 30, 100, 45, 25

Ocx Command cmd2 = "But_2", 80, 100, 45, 25

Ocx Command cmd3 = "But_3", 130, 100, 45, 25

Local ho As Intco As Control, h As Int

Do

Sleep

h = GetFocus()

If h <> ho

ho = h

Set co = OCX(h)

If ! IsNothing(co)

Print co.name

EndIf

EndIf

Loop Until Me Is Nothing

CloseW 1

Remarks

The Form() function does the same for a form window; it returns a Form object for a given window handle.

It is not possible to destroy an object created using OCX(); to get around this problem, simply set the Width property to 0 (zero).

See Also

Ocx, OcxOcx, Form, Form()

{Created by Sjouke Hamstra; Last updated: 20/10/2014 by James Gaite}