How to configure several groups of switches for the correct interaction with the scoreboard and keyboard (WIN32)?

First of all, this is not MFC.
Here is the cropped version of the GUI I was working on:

enter image description here

As you can see, I have (an attempt) to create two different groups: an icon and a button using the code:

index->hAddT.hwndIndex[2] = CreateWindowEx(NULL,L"BUTTON",L"Icon",WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 200,135,120,170,WINDOWHANDLE,(HMENU)IDC_RADIOGROUP,(HINSTANCE)GetWindowLong(WINDOWHANDLE,GWL_HINSTANCE),NULL); 

I have a problem, and maybe you see that there is only one button for the window. This means that the user could not select one switch from the group of icons and one from the group of buttons. I initialized each Radio button as follows:

  index->hAddT.hwndIndex[3] = CreateWindowEx(NULL,L"BUTTON",L"Information",WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE, 205,155,100,20,WINDOWHANDLE,(HMENU)IDC_RADIO1,(HINSTANCE)GetWindowLong(WINDOWHANDLE,GWL_HINSTANCE),NULL); 

I would like for me to have an “Icon” radio button group divided into a “Button” radio button group, if that makes sense, and therefore will have one radio button available for each group. How will it be possible, will I require a new window and a new callback procedure to have an additional switch. There must be another way to group children like this.

2 separate switch groups in the same form WINAPI (No MFC) The link was not used for my purpose.

I have programming for Windows Fifth Edition, Charles Petzold is next to me as a link, and he points out in the “Group Boxes” section: “Group boxes are often used to enclose other button controls,” but there is no real example of this.

+8
c ++ radio-button winapi window win32gui
source share
1 answer

Contrary to popular belief, you do not need a group box control or any other such external “container” (which a group box does not have anyway, its just an artifact of a button). The following describes how you can do this using the no group window requirement. If you want the group box to functionally help in the layout described here, go to the EDIT part of this answer, where I will explain how you can achieve specific OP desires.

Auto-radio "banks" operate using two key window style attributes, WS_GROUP and WS_TABSTOP . Do the following for the two “banks,” which I will affectionately call Bank1 and Bank2:

  • Bank 1: the first switch should have as WS_GROUP | WS_TABSTOP in management style. the rest of the switches should have none of them and should be in the order of marriage (which means the DIALOG script, they immediately follow each other, in dynamic creation they are created sequentially).

  • The first child control after your last switch in Bank1 should have at least the WS_GROUP and WS_GROUP | WS_TABSTOP if it is a tab control.

  • Bank 2: the first switch should have as WS_GROUP | WS_TABSTOP in management style. the rest of the switches should have none of them and should be in the order of marriage (which means the DIALOG script, they immediately follow each other, in dynamic creation they are created sequentially).

  • The first child control after the last switch in Bank2 must have at least WS_GROUP style, and WS_GROUP | WS_TABSTOP if it is a tab control.

A layout similar to the one above allows you to “insert” radio buttons into the bank and use the arrow keys to switch the selection. Then you press “Tab” again to leave this bank and move on to the next tab stop. Remember that the dialog manager will always move to the next WS_TABTOP child when you press Tab (or earlier with Shift-Tab). If the selected control is an automatic type, the selected control will be the "selected" control in the most recent WS_GROUP.

If this helps, take the thumbnail panel, draw it on paper and stick “T” on the tabs and “G” on the group attributes, as described above. This will probably be much clearer if visualized. Take a look at the script dialog resource to see how they work together for a deeper understanding.

Notes. If you want to use group fields around them, you can. The dialog manager works by associating controls with groups based on the last control labeled WS_GROUP, and the first control that has WS_TABSTOP is considered the tab entry point for that group. Turning on the group box first (which cannot be a tabstop), followed by radio button controls with WS_TABSTOP on the first switch (without WS_GROUP this time), will also work. It’s usually easier for me to simply arrange my switches, regardless of group boxes.

EDIT Image says a thousand words.

For your image, I will probably create the following children in the following order:

  • "Icon" groupbox, including the WS_GROUP style.
  • Information button automatically, including WS_TABSTOP
  • All other buttons of the Icon group. DO NOT enable WS_TABSTOP or WS_GROUP.
  • "Button" groupbox, including the WS_GROUP style. This closes the current control group and starts the next one.
  • AbortretryIgnore auto-share button, including WS_TABSTOP
  • All other buttons are "Button" groups. DO NOT enable WS_TABSTOP or WS_GROUP.
  • The next control after the "Button" switches should contain WS_GROUP. This closes the current control group and starts the next one.

Obviously, all other types of child control, visibility, etc. must also be used correctly, and of course, children must have unique identifiers. I assume that you already have the rest covered.

+12
source share

All Articles