MFC - 控制不是直接创建的

时间:2014-07-11 07:54:42

标签: c++ visual-studio mfc

我创建了一个clss名称NRGroupBox来管理自定义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;
  ...
}

以下是其中一个辅助函数的代码:(这四个函数非常相似)

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];
}

我的问题是,当我调用此功能时,编辑框没有显示,我需要在MoveWindow功能之外调用CreateEdit。我不明白为什么我需要这样做。

以下是我希望如何使用NRGroupBoxCreateEdit功能的示例。

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;
}

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

的CRect(120,60,100,20)

您的坐标顺序错误,右边&lt;左和右&lt;顶