Is there a mechanism in MFC to dynamically add controls
to a dialog (specifically, a dialog box I created using the
resource editor)?
Basically, I've got an object that may have an arbitrary
number of settings. For instance, maybe I have:
Object {
flavor
color
weight
}
and I want to view and add objects using a dialog. So, firstly
I created a CLIstCtrl and added 3 columns 'flavor', 'color' and
'weight'. Now I need some way to add input controls for each
of these attributes. (In this case combo boxes.)
So, how might I go about adding a vertical column of three
combo boxes? Can this be done in code and applied to an
existing dialog box?
thanks,
Lee Crawfor
craw...@anubisinc.com
I've done this several times. While it is a bit of a pain, it can be done
using CreateWindow. The trick is figuring out where the control you create
should be placed since a dialog box is not always the same pixel size (see
GetDialogUnits()). I most often get around this by creating empty static
text boxes in the resource editor as placeholders, and my code ends up
looking something like this:
CRect rect;
CWnd* placeholder = GetDlgItem(IDC_PLACEHOLDER);
placeholder->GetWindowRect(rect);
placeholder->ShowWindow(SW_HIDE);
ScreenToClient(rect);
m_dynListBox.Create(
WS_VISIBLE | WS_CHILD | LBS_HASSTRINGS | LBS_SORT |
LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP,
rect, this, (UINT) IDC_STATIC);
This sample creates a list box on the fly, but you get the idea. Send me
email if you've got more questions.
--
Steve Zimmerman / zim...@aros.net
"What prodigies of human inventiveness [are] being directed
to reading each other's mail!"--Carl Sagan, Contact