quote:
Originally posted by mathieumg
Possibly there is a way to improve it by making ToggleEnableControl()
You don't always want to 'toggle' the control. In most cases you want to set the enabled state (after some event or in a certain case).
Anways, you could use something like this:
code:
function ControlEnable(pPlusWnd, sControlId, bState) {
// Get handle of the specified control on the specified window
var hCtrl = pPlusWnd.GetControlHandle(sControlId);
// If function is called with a 3rd parameter, set the state of the control
if (arguments.length === 3) Interop.Call("User32", "EnableWindow", hCtrl, bState);
// Return the current state of the control
return Interop.Call("User32", "IsWindowEnabled", hCtrl);
}
Usage:
example 1: Disable control:
ControlEnable(mywindow, "mycontrol", 0);
example 2: Enable control:
ControlEnable(mywindow, "mycontrol", 1);
example 3: Get current state of control:
var TheState = ControlEnable(mywindow, "mycontrol");
---------
Or even (to add the toggle functionality):
code:
function ControlEnable(pPlusWnd, sControlId, bState) {
// Get handle of the specified control on the specified window
var hCtrl = pPlusWnd.GetControlHandle(sControlId);
// If function is called with a 3rd parameter, set the state of the control
if (arguments.length === 3) {
// If bState doesn't equal 0 or 1, toggle the state of the control
if (bState != 0 && bState != 1) bState = Interop.Call("User32", "IsWindowEnabled", hCtrl) ^ 1;
Interop.Call("User32", "EnableWindow", hCtrl, bState);
}
// Return the current state of the control
return Interop.Call("User32", "IsWindowEnabled", hCtrl);
}
Additional usage to the above examples:
example 4: Toggle control:
ControlEnable(mywindow, "mycontrol", 2);