MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / ControlCheckRadioButton

Method ControlCheckRadioButton

source/script_gui.cpp:9600–9643  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9598
9599
9600void GuiType::ControlCheckRadioButton(GuiControlType &aControl, GuiIndexType aControlIndex, WPARAM aCheckType)
9601{
9602 GuiIndexType radio_start, radio_end;
9603 FindGroup(aControlIndex, radio_start, radio_end); // Even if the return value is 1, do the below because it ensures things like tabstop are in the right state.
9604 if (aCheckType == BST_CHECKED)
9605 {
9606 // Testing shows that controls with different parent windows never behave as though they
9607 // are part of the same radio group. CheckRadioButton has been confirmed as working with
9608 // both non-dialog windows (such as Static/Text) and Tab3's tab dialog. This is required
9609 // for this function to work on Radio buttons within a Tab3 control:
9610 HWND hDlg = GetParent(aControl.hwnd);
9611 // This will check the specified button and uncheck all the others in the group.
9612 // There is at least one other reason to call CheckRadioButton() rather than doing something
9613 // manually: It prevents an unwanted firing of the radio's g-label upon WM_ACTIVATE,
9614 // at least when a radio group is first in the window's z-order and the radio group has
9615 // an initially selected button:
9616 CheckRadioButton(hDlg, GUI_INDEX_TO_ID(radio_start), GUI_INDEX_TO_ID(radio_end - 1), GUI_INDEX_TO_ID(aControlIndex));
9617 }
9618 else // Uncheck it.
9619 {
9620 // If the group was originally created with the tabstop style, unchecking the button that currently
9621 // has that style would also remove the tabstop style because apparently that's how radio buttons
9622 // respond to being unchecked. Compensate for this by giving the first radio in the group the
9623 // tabstop style. Update: The below no longer checks to see if the radio group has the tabstop style
9624 // because it's fairly pointless. This is because when the user checks/clicks a radio button,
9625 // the control automatically acquires the tabstop style. In other words, even though -Tabstop is
9626 // allowed in a radio's options, it will be overridden the first time a user selects a radio button.
9627 HWND first_radio_in_group = NULL;
9628 // Find the first radio in this control group:
9629 for (GuiIndexType u = radio_start; u < radio_end; ++u)
9630 if (mControl[u]->type == GUI_CONTROL_RADIO) // Since a group can have non-radio controls in it.
9631 {
9632 first_radio_in_group = mControl[u]->hwnd;
9633 break;
9634 }
9635 // The below can't be done until after the above because it would remove the tabstop style
9636 // if the specified radio happens to be the one that has the tabstop style. This is usually
9637 // the case since the button is usually on (since the script is now turning it off here),
9638 // and other logic has ensured that the on-button is the one with the tabstop style:
9639 SendMessage(aControl.hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
9640 if (first_radio_in_group) // Apply the tabstop style to it.
9641 SetWindowLong(first_radio_in_group, GWL_STYLE, WS_TABSTOP | GetWindowLong(first_radio_in_group, GWL_STYLE));
9642 }
9643}
9644
9645
9646

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected