1

I created a clss name NRGroupBox to manage a custom GroupBox style. I had some helpers to add controls in the groupbox :

NRGroupBox
{
  ...
  NRButton   * CreateButton(std::string id, CRect position, std::string content);
  NREdit     * CreateEdit(std::string id, CRect position);
  NRStatic   * CreateStatic(std::string id, CRect position, std::string text);
  NRComboBox * CreateComboBox(std::string id, CRect position);
  ...
  std::map<std::string, NREdit     * > edits;
  std::map<std::string, NRStatic   * > labels;
  std::map<std::string, NRButton   * > buttons;
  std::map<std::string, NRComboBox * > comboBoxes;
  ...
}

Here is the code of one of the helper functions : (the four functions are quite similar)

NREdit * NRGroupBox::CreateEdit(std::string id, CRect position)
{
    if(!edits.count(id))
    {
        NREdit * buff = new NREdit();
        buff->Create(WS_CHILD | WS_VISIBLE, position, this, editIds++);
        buff->MoveWindow(position);
        edits[id] = buff;
    }

    return edits[id];
}

My problem is that when I call this function the edit box doesn't show, I need to call MoveWindow outside the CreateEdit function. I don't understand why I need to do this.

Here is an example of how I want to use NRGroupBox and CreateEdit function.

BOOL ConfigWindow::OnInitDialog()
{
    if(!CDialog::OnInitDialog())
    {
        NRthrow("Impossible de créer la fenêtre");
        return FALSE;
    }

    MoveWindow(0,0,800,800);

    ShowWindow(SW_SHOW);

    groupBox = new NRGroupBox();
    groupBox->Create("Test GroupBox", CRect(0,0,500,500), this);
    groupBox->SetNRStyle();

    bouton  = groupBox->CreateButton("bouton", CRect(230,60,100,20), "Test Bouton");
    label   = groupBox->CreateStatic("label", CRect(10,60,100,20), "Test label");
    editBox = groupBox->CreateEdit("editBox", CRect(120,60,100,20));

    // Actually I need those lines, but I don't want to need it.
    //editBox->MoveWindow(120,60,100,20);
    bouton->MoveWindow(230,60,100,20);
    label->MoveWindow(10,60,100,20);

    NRDebug::Notice("Création d'une fenêtre de Paramétrage");


    return TRUE;
}

Thanks for your help

AMDG
  • 955
  • 1
  • 9
  • 25
  • might be a refreshing problem, are you invalidating the window after adding stuff to it? I don't see that – Marco A. Jul 11 '14 at 08:18
  • In an OnInitDialog, I create the NRGroupBox, then call CreateEdit(). If I stop here the edit doesn't show, if I call MoveWindow on the edit I just create, the edit is displayed. – AMDG Jul 11 '14 at 08:21
  • Nothing change if I add `Invalidate()` of `buff->Invalidate()` before or after `buff->MoveWindow` – AMDG Jul 11 '14 at 08:35
  • Try both [UpdateWindow](http://msdn.microsoft.com/en-us/library/dd145167%28VS.85%29.aspx) and Invalidate to get immediate redraw – Marco A. Jul 11 '14 at 08:37
  • Neither `UpdateWindow`, `Invalidate` and `RedrawWindow` works. I'm so confused... – AMDG Jul 11 '14 at 08:44
  • Take a look at the coordinates you're using, it might be related to http://stackoverflow.com/q/12368777/1938163 – Marco A. Jul 11 '14 at 08:48
  • I think it's Ok, with coordinates. MoveWindow use coordinates relative to the parent window which are [0,0,800,800]. The coordinates I pass to buff->MoveWindow are in that range. So it must be ok. – AMDG Jul 11 '14 at 08:55

1 Answers1

1

CRect(120,60,100,20)

You have the coordinates in the wrong order, with right < left and bottom < top

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15