MFC - 不直接创建控件
MFC - Control aren't created directly
我创建了一个类名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];
}
我的问题是,当我调用这个函数时,编辑框没有显示,我需要在CreateEdit
函数之外调用MoveWindow
。我不明白我为什么要这样做。
下面是我想如何使用NRGroupBox
和CreateEdit
函数的示例。
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;
}
谢谢你的帮助
CRect(120,60,100,20)
你的坐标顺序错了,正确的<左和下><前>前>左和下>
相关文章:
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- 我的主窗口在创建时或单击更新区域时是否会收到编辑控件?
- 创建带有限幅器的步进器控件
- GLFW & ImGui:从 main 以外的线程创建 ImGui 控件
- 如何正确删除一行控件并在该位置动态创建一个新控件
- 将事件分配给在运行时动态创建的 VCL 控件
- 如何在列表控件中创建右键单击菜单
- 在 QT 中创建带有表单的控件时的递归构造函数调用
- 如何使用面向对象的技术在 win32 和 c++ 中创建编辑控件
- 创建独立控件Direct2D的好策略
- Windows 7:MFC ActiveX 控件不会在任何文件夹中创建文件
- C MFC创建编辑控件可以拥有的最大数字
- 在 c++ 中创建自定义控件时扩展控件
- 隐藏-在运行时c++中显示或创建控件
- 具有动态创建控件的MFC应用程序突然停止响应
- 在MFC表单中创建控件周围的边框
- MFC - 不直接创建控件
- 是否有可能在c++中创建控件并在Java活动中使用?
- 在 MFC 应用程序中动态创建控件