0

I want to create a dialog that allows the user to set the same attributes for several instances of an object. Something like:

Several rows of the same controls

It has been suggested that I create a titleless, modeless dialog for the row then instantiate it multiple times and maintain an array the objects for the row class. I tried that I got partway there but not quite. It seems my issue may have been clipping. I now have something working:

BOOL CPropPageDI::OnInitDialog()
{
    CPropertyPage::OnInitDialog();

    CRowDI* row = new CRowDI();

    CRect rect;
    CWnd* pos = GetDlgItem(IDC_POS_DI);
    pos->GetWindowRect(&rect);
    // Make sure that the row fits
    rect.right = rect.left + 492;
    rect.bottom = rect.top + 55;

    ScreenToClient(&rect);
    row->Create(IDD_ROW_DI, this);
    row->MoveWindow(&rect);
    row->ShowWindow(SW_SHOW);

I see the property page but it seems empty. Is there something else I have to do to make the row show up?

Chris Nelson
  • 3,519
  • 7
  • 40
  • 51
  • Design question: Any reason why you don't use a CListCtrl in report style? – rrirower Mar 06 '15 at 16:32
  • Create a CWnd derived class that is a container for the group of controls. Btw do you need to use MFC? I've moved to Qt and it's much easier to do those things in it, and still C++. – sashoalm Mar 06 '15 at 16:46
  • @rrirower, old as MFC is, I'm new to it. I'm not sure what a CListCtrl is. I'll look. – Chris Nelson Mar 06 '15 at 18:40
  • @sashoalm, I'm maintaining/enhancing an old application built with MFC. I have no choice of tools. – Chris Nelson Mar 06 '15 at 18:41
  • If you need things a list control in report style won't handle, a good place to start would probably be Chris Maunder's [MFC Grid Control](http://www.codeproject.com/Articles/8/MFC-Grid-control). – Jerry Coffin Mar 08 '15 at 20:33

1 Answers1

0

If each row is a child dialog then issues of control arrays and control IDs disappear. All you have to write is the code for one 'Thing' and then manage an array of 'Things'.

In this case a child dialog would be a modeless dialog with the titlebar style turned off, so the visual result would be the same as your example.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • Wouldn't it be better to derive directly from CWnd instead of CDialog? – sashoalm Mar 06 '15 at 16:44
  • That sounds promising. Can I add a dialog to a dialog with the resource editor / toolbox or do I have to do it in code? – Chris Nelson Mar 06 '15 at 19:13
  • The child dialog can be built independently in the resource editor, but then it has to be created and positioned in code (in parent dialog's OnInitDialog). – ScottMcP-MVP Mar 06 '15 at 22:47
  • Thanks, Scott. Given that I'm an MFC newbie, would you tell me the name of the method I'd use to do that? – Chris Nelson Mar 08 '15 at 22:54
  • The modeless dialogs can be sized and positioned with MoveWindow. It is convenient to put an invisible static control on the parent dialog to serve as a landmark for where you want the first modeless dialog to be placed. GetWindowRect on the static control + ScreenToClient will give you the location to use in MoveWindow. Then offset the rect down and place the 2nd modeless dialog... – ScottMcP-MVP Mar 08 '15 at 23:20