Home > Language Reference > Windows Management Functions > EnabledW

EnabledW

The EnabledW function checks that the specified window is enabled and can receive actions.

Usage

Used to be sure that a window may receive keystrokes or mouse clicks when the content of a window is updated whereas the window title does not change. If the window name changes, UseWindow functions puts to foreground the specified window and the window is then ready for receiving actions (no need to check).  

Syntax

 ret=EnabledW(<window_name>)

Parameters

<window_name>, string, window name of the window to check. You can truncate <window_name> to check a window whose title starts with the specified characters.

Return value

ret, numeric return value. The function returns 1 if <window_name> is enabled, it returns 0 if not.

Remarks

EnabledW function can be used to test if a button is grayed or not. Buttons within a toolbar cannot be tested with EnabledW function because the only window seen by WinTask is the Toolbar window. The second script example listed below shows how to test if a button in a toolbar is active or not.

The function can be used for testing if a window is active when you receive the error message Unable to activate window (see the first example below).

EnabledW does not include a synchronization mechanism, so you have to wait that <window_name> is really displayed before executing EnabledW.

See also

UseWindow
CheckedW

Examples

'The function below returns the status of a button within a window.
'The function takes 2 arguments, the window name of the button and the button name
Function Button_test(win$,name$)
'Check first if the window name for the button exists
ret=ExistW(win$)
if ret=0 then
  msgbox("There is no button "+name$,16,"")
  stop
else
 'The window name exists, check now if the button is enabled or not
  ret=EnabledW(win$)
if ret=0 then
  msg$="Disabled"
  else
  msg$="Enabled"
  endif
endif
'Display the result for 4 secs
Msgframe("The button "+name$+" is "+msg$,1,0,0,12,255)
pause 4
removeframe(1)
EndFunction

'Call example in Control Panel, Display/Screen resolution screen
Shell("Control.exe DESK.CPL")
'UseWindow waits until the specified window is there
UseWindow("EXPLORER.EXE|CabinetWClass|Control Panel\All Control Panel Items\Display\Screen Resolution",1)

'Test if the Apply button is enabled or not
button_win$="EXPLORER.EXE|Button|&Apply"
button_name$="$Apply"
Button_test(button_win$,button_name$)

'Change button status
Msgframe("You have 4 seconds to make the "+name$+" button enabled",1,0,0,12,255)
pause 4
removeframe(1)
'If you did change something in the screen resolution, the Apply button is now enabled, and the function displays the new message
Button_test(button_win$,button_name$)

'Close Control Panel
CloseWindow("EXPLORER.EXE|CabinetWClass|Control Panel\All Control Panel Items\Display\Screen Resolution",1)

'This example shows how to test if an icon in a menu toolbar is greyed or not, without clicking the icon.
'
'Function testing if the bitmap specified in file_bmp$ is found within the window win$.
'After timeout seconds, if file_bmp$ is not found, the function returns 0.
'file_bmp$ contains the bitmap file for the button to be checked, when this one is active ;
'use Capturebitmap to create this file
Function is_control_enable(file_bmp$,win$,timeout)
local buffer,res
buffer=#Pausetimeout
#Pausetimeout=Timeout
res=0
Pause until
    bitmap(file_bmp$)
    inWindow(win$)
PauseOK
    res=1
PauseFalse
    res=0
EndPause

#Pausetimeout=buffer
is_control_enable=res
EndFunction

'Call example on the toolbar whose window name is "KODAKIMG.EXE|ToolbarWindow32|Imaging"
result=is_control_enable("C:\program files (x86)\WinTask\scripts\button_toolbar.bmp","KODAKIMG.EXE|ToolbarWindow32|Imaging",10)
msgbox(result)