c++ - 如何在我自己的 C++ 应用程序中显示简单(但自定义)对话框
问题描述
我正在寻找简单的解决方案,通过使用对话框从用户那里获取一些数据。
我不想使用 MFC,因为它应该是跨平台的。我已经阅读并运行了一些 QT 和 wxWidgets 的示例,但问题是它们使用自己的“自己的”主入口点,所以我不知道如何在我的应用程序中组合它们。
这是我正在尝试做的一个例子:
int main()
{
std::cout << "Please choose the dialog! Press 1 or 2" << std::endl;
int key = 0;
std::cin >> key;
if (key == 1)
{
Dialog1 dlg; //This is my question! how to do that?
dlg.show();
//Get data drom dialog:
std::string str1 = dlg.GetData(ID_EDIT_BOX_1);
std::string str2 = dlg.GetData(ID_EDIT_BOX_2);
}
if (key == 2)
{
Dialog2 dlg;
dlg.show(); //Show simple dialog with some edit boxes
//Get data drom dialog:
std::string str1 = dlg.GetData(ID_EDIT_BOX_1);
std::string str2 = dlg.GetData(ID_EDIT_BOX_2);
}
}
我的意思是我知道如何创建和调用对话框,但不知道如何在我的应用程序中组合它们并在特定行中调用它们......
谢谢。
解决方案
使用 wxWidgets,您可以使用 初始化库wxInitialize()
,使用wxDialog::ShowModal()
来显示您的对话框,然后使用关闭它wxUninitialize()
并根据需要重复。如果您需要显示许多对话框,每次都这样做显然不是很有效,但是如果您真的想制作一个完全独立的函数来询问用户的值,您可以这样做。
推荐阅读
- java - 在 C++ 类方法循环中创建 JVM - 调用 API
- r - 能够将 1 行现有列与 R 中的另一行现有列合并以创建第 3 列
- javascript - 如何让硒等到页面完全呈现?
- java - 是否可以在 Selenium 网格中注册自定义 webdriver?
- css - 如何在 CSS 中制作蛋形?
- mysql - 在多级时间序列数据中插入缺失的日期记录
- python - AttributeError:“张量”对象没有属性“_keras_shape”
- java - MPAndroidChart setData 多行
- r - 在不使用强度的情况下将颜色条添加到mesh3d(使用facecolor)
- c++ - 如何从 cpp 中的 std::list 中删除每隔一个元素?