windows MFC CWinApp 程序中的输入框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3507085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Input Box in an MFC CWinApp program?
提问by T.T.T.
I need an input box in a UI program that is already written derived from the CWinnApp class and using MFC.
我需要一个已经从 CWinnApp 类派生并使用 MFC 编写的 UI 程序中的输入框。
I see it is using message boxes but I don't see any examples of input boxes....
我看到它正在使用消息框,但我没有看到任何输入框的例子......
How do I do this?
我该怎么做呢?
(Using Visual Studio 6.0 in C++)
(在 C++ 中使用 Visual Studio 6.0)
Thank You.
谢谢你。
回答by casablanca
I know it's something that's often required, but there isn't a built-in input box in MFC, so you'll have to create your own. I usually just create a simple dialog with a label and edit box (the dialog already comes with OK/Cancel buttons), then create a class, say CInputDlg
, add member variables for the label and edit box, and just call it like any other dialog:
我知道这是经常需要的东西,但是 MFC 中没有内置的输入框,因此您必须创建自己的输入框。我通常只是创建一个带有标签和编辑框的简单对话框(该对话框已经带有确定/取消按钮),然后创建一个类,比如说CInputDlg
,为标签和编辑框添加成员变量,然后像其他任何对话框一样调用它:
CInputDlg dialog;
dialog.m_label = TEXT("Enter a number:");
if (dialog.DoModal() == IDOK) {
// Do something
}
回答by sylvanaar
You have to create a dialog box and place an edit control on it. There is no automagic solution. You have to code it or find some code on the web.
您必须创建一个对话框并在其上放置一个编辑控件。没有自动解决方案。您必须对其进行编码或在网上找到一些代码。
回答by Mark Ransom
When you created your MFC App, which type of project did you tell the wizard to generate? Usually I do mine as a Dialog app, and then it's a simple matter of placing a text box on the dialog.
当您创建 MFC 应用程序时,您告诉向导生成哪种类型的项目?通常我把我的作为一个对话框应用程序,然后在对话框上放置一个文本框是一个简单的问题。
回答by Samer
In Visual Studio 2008 it is straightforward:
在 Visual Studio 2008 中,这很简单:
- In the resource view, right click on Dialog Directory and choose add resource... or insert dialog(choose this option id you are not sure what kind of dialog).
- Click on tools and add a static text and Edit Control and whatever tools you want to add type in the name of the dialog, and the name of the class, this will add a header file and .cpp file to your project directly.
- Add the controls that you want to add to your class
- 在资源视图中,右键单击对话框目录并选择添加资源...或插入对话框(选择此选项 id 您不确定是哪种对话框)。
- 单击工具并添加静态文本和编辑控件以及您要在对话框名称中添加类型和类名称的任何工具,这将直接向您的项目添加头文件和 .cpp 文件。
- 添加要添加到班级的控件