Home > Language Reference > Windows Management Functions > TopInstance

TopInstance

The TopInstance function returns the instance number of the foreground window.

Usage

Used to acquire dynamically the instance number of the foreground window.   

Syntax

var=TopInstance()

Parameters

None.

Return value

var, integer, instance of the top window.

See also

UseWindow
Top$

Example

'Launch a first instance of notepad
Shell("notepad")
'Wait until the notepad window is displayed
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
a=TopInstance()
'The instance number of the notepad window on top is 1
msgbox(a)

'Launch a second instance of notepad
Shell("notepad")
'Wait 50 ticks, a tick is 1/100 sec, just to be sure that the second instance of notepad window is displayed
pause 50 ticks
'Return the instance number of the top window, a returns 2
a=TopInstance()
msgbox(a)

'Put the first instance of notepad on top
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
'a returns now 1
a=TopInstance()
msgbox(a)