Click button, or get checked state

Syntax1 - click, check, etc

but[+|-|*|%] hwndbutton

 

Syntax2 - click, check, etc

but[+|-|*|%] id|text window

 

Syntax3 - get checked state

int but(hwndbutton)

 

Syntax4 - get checked state

int but(id|text window)

 

Parameters

hwndbutton - button handle. To get button handle, use function id or child.

window - top-level parent window. The function searches only in the first found matching window.

id - button id.

text - button label. Can be partial, but from beginning. Underlined characters must be preceded with &. The window must not have other controls with the same text.

 

Options:

Default Click.
+ Check checkbox.
- Uncheck checkbox.
* Toggle checkbox.
% Click if unchecked.

 

Remarks

Syntax1 and 2

Clicks, checks or unchecks a button, check box or option (radio) button.

 

Option characters usually are used with check boxes. Option + also can be used with push buttons; often it is more reliable.

 

Syntax3 and 4

Returns check state of check box or radio (option) button: 0 - unchecked, 1 - checked, 2 indeterminate.

 

How it works; using in dialog procedure

All but versions can be used everywhere - with windows of other applications and with your custom dialogs.

 

The 'click' versions (but and but%) send BM_CLICK message to the button, which sends WM_LBUTTONDOWN etc and sets focus. May not work if the window is inactive, although may activate it. It seems that Acc.DoDefaultAction also uses this message.

 

The 'check' versions (but+, but-, but*) send BM_SETCHECK message to the checkbox. It does not set focus. Works with inactive windows.

 

but+, but- and but% do nothing if the checkbox already is in that state.

 

All 'click' and 'check' versions send notification (WM_COMMAND) to the parent dialog. To check a checkbox or option button in your dialog without notification, use CheckDlgButton or CheckRadioButton, or assign 1 to the dialog variable before ShowDialog.

 

Sends messages asynchronously. For example, if the button shows a dialog, but does not wait until the dialog is closed. Applies autodelay (spe). If the target window belongs to current thread, sends synchronously and does not apply autodelay.

 

The 'get checked state' version (syntax 3 and 4) sends BM_GETCHECK message. The alternatives are IsDlgButtonChecked and BM_GETSTATE. Look in MSDN Library.

 

Examples

but child(100 100 "Calc") ;;click button at 100 100 of "Calc" window
but id(306 "Calc") ;;click button with id=306 on window "Calc"
but+ 306 "Calc" ;;check check-button with id=306 on window "Calc"
but "&Open" "Open" ;;click button "Open" on window "Open"

 If radio button "Down" in "Find" dialog is unchecked, click it:
int h=child("&Down" "Button" "Find")
if(!but(h)) but h