Group dialog items to a single “Group” (Visual Stu

2020-05-03 10:17发布

问题:

I want to create a dialog window for change settings of an application. Below is a screenshot of Adobe Reader. After using Spy++, I guess that:

On the right side, all the control (buttons, combo boxes...ect) are belonged to a GroupBox.

For each category in the TreeView Control on the left side, there is a corresponding GroupBox which groups all the controls related to this category.

When users choose between different categories, it hides one GroupBox and shows another one GroupBox.

But in the source code (xxx.rc, resource file) below, I didn't see anywhere where I can specify the "parent" of a dialog item.

Even I open xxx.rc with "Resource View" (not viewed as codes), I can't find any option to specify the parent of a dialog item in its property page.

I would like to know how to assign a parent (which is a GroupBox in my case) to a dialog item, or group dialog items to a single group,in the .rc file, i.e when one create the dialog items. (I guess one can do so by modifying the .rc file.)

GROUPBOX        "View",IDC_SECTION_VIEW,101,6,228,88
LTEXT           "Default &Layout:",IDC_DEFAULT_LAYOUT_LABEL,107,19,108,9
COMBOBOX        IDC_DEFAULT_LAYOUT,215,17,108,64,CBS_DROPDOWNLIST | WS_TABSTOP
LTEXT           "Default &Zoom:",IDC_DEFAULT_ZOOM_LABEL,107,36,108,9
COMBOBOX        IDC_DEFAULT_ZOOM,215,34,108,149,CBS_DROPDOWN | WS_TABSTOP
CONTROL         "Show the &bookmarks sidebar when available",IDC_DEFAULT_SHOW_TOC,
                "Button",BS_AUTOCHECKBOX | WS_TABSTOP,107,53,216,9
...
...
...

回答1:

I would like to know how to assign a parent...

SetParent Windows API. You supply HWND of your control and the handle of the supposed new parent.

In resource script, the controls will be children of the dialog itself, but on runtime you are free to change this and group them into a hierarchy of your interest.

You might also want to consider putting the supposed child groups into separate dialog template and have it as "composite control" - to be instantiated separately and be a child of a higher level dialog.

UPD. Have a look at this simple project (C++/ATL): AtlChildDialog. In particular, at main dialog's WM_INITIDIALOG handler:

ATLVERIFY(m_ChildDialog.Create(m_hWnd, (LPARAM) this));
ATLVERIFY(m_ChildDialog.MoveWindow(50, 50, 200, 150));
m_ChildDialog.m_EditWindow.SetWindowText(_T("Some Text"));
m_ChildDialog.ShowWindow(SW_SHOWNORMAL);
m_ChildDialog.SetFocus();

All together on runtime: