EnabledW
Windows management function.
The EnabledW function verifies that the specified window is enabled and can receive actions.
Syntax
ret=EnabledW(<window_name> [,<instance>])
Parameters
<window_name>, window name of the window to check.
<instance>, optional parameter, instance number of the window to check.
Return value
Ret, numeric return code. When the specified window is enabled, the function returns 1 ; if the window cannot receive any mouse/keyboard actions, the function returns 0.
Remarks
This statement 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.
This statement 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 the window <window_name> is really displayed before running the EnabledW.
See also
CheckedW for interaction with EnabledW in case of a check box or a radio button.
Example code
This example tests a button status in the window Display properties of the Control panel.
Function Button_test(win$,name$)
ret=ExistW(win$)
if ret=0 then
msgbox("There is no button "+name$,16,"")
stop
else
ret=EnabledW(win$)
if ret=0 then
msg$="Disabled"
else
msg$="Enabled"
endif
endif
Msgframe("The button "+name$+" is "+msg$,1,0,0,12,255)
pause 4
removeframe(1)
EndFunction
Shell("Control")
pause 2
UseWindow("EXPLORER.EXE|SHELLDLL_DefView|Control Panel|1",1)
ChooseItem(ListView,"1","Display",double)
UseWindow("RUNDLL32.EXE|#32770|Display Properties",1)
button_win$="RUNDLL32.EXE|Button|&Apply"
button_name$="Apply"
Button_test(button_win$,button_name$)
'Change button status
UseWindow("RUNDLL32.EXE|#32770|Background",1)
sendkeys("<Down>")
Button_test(button_win$,button_name$)
CloseWindow("RUNDLL32.EXE|#32770|Display Properties",1)
CloseWindow("EXPLORER.EXE|CabinetWClass|Control Panel",1)
This second example shows how to test if a button in a Toolbar is active or not, without clicking this button.
'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 untilbitmap(file_bmp$)
inWindow(win$)PauseOK
res=1
PauseFalse
res=0
EndPause
#Pausetimeout=buffer
is_control_enable=res
EndFunction
'Main program on a specific window toolbar
result=is_control_enable("C:\program files\wintask\scripts\button_toolbar.bmp","KODAKIMG.EXE|ToolbarWindow32|Imaging",10)
msgbox(result)