创建 Windows GUI .exe 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3909867/
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
Creating a Windows GUI .exe application
提问by Abhishek
I have a C/C++ algorithm that I want to create a GUI application for. I would prefer a .exe application that I can pass around to people. I would preferably want to create a dll of my c/c++ algorithm and then bundle it into the Windows GUI application which is basically just a wrapper around the main c/c++ application. How can I create this GUI in VC++ all with a couple of buttons, a text box and a file chooser/browser/opener?
我有一个 C/C++ 算法,我想为其创建一个 GUI 应用程序。我更喜欢可以传递给人们的 .exe 应用程序。我最好创建一个我的 c/c++ 算法的 dll,然后将它捆绑到 Windows GUI 应用程序中,该应用程序基本上只是主 c/c++ 应用程序的包装器。如何在 VC++ 中使用几个按钮、一个文本框和一个文件选择器/浏览器/打开器创建这个 GUI?
Can someone throw some light on this problem?
有人可以解决这个问题吗?
Thanks,
谢谢,
Abhishek
阿布舍克
回答by Emil H
There's a number of different options. First we have the microsoft-supported libraries:
有许多不同的选择。首先我们有微软支持的库:
- MFC- The most heavy-weight library for the windows api.
- ATL- A somewhat smaller, lightweight library.
- Windows API- Use the Windows API directly.
- MFC- 最重量级的 windows api 库。
- ATL- 一个稍微小一些的轻量级库。
- Windows API- 直接使用 Windows API。
Beyond that there's a number of third party GUI toolkits, notably:
除此之外,还有许多第三方 GUI 工具包,特别是:
- GTK+
- WxWidgets
- GTK+
- 窗口小部件
If you want to make it as small as compact as possible and avoid external DLLs, you should use the Windows API directly or possibly ATL. This also gives you additional flexibility, but it's a bit more complicated. Take a look at for example theForger's tutorial. It's a bit old, but the api has remained more or less the same for the last ten years anyway.
如果您想让它尽可能小并且避免使用外部 DLL,您应该直接使用 Windows API 或可能使用 ATL。这也为您提供了额外的灵活性,但它有点复杂。看看例如theForger 的教程。它有点旧,但无论如何,api 在过去十年中或多或少保持不变。
Here's some additional pointers for using the API directly:
以下是直接使用 API 的一些额外提示:
- What is usually known as controls is called "windows" and are created using CreateWindowEx(). This function creates different things depending on the specified "window class", such as edit, button and static (described below). You create a regular window by registering a custom class.
- You can use a function called GetOpenFileName()to invoke an open dialog.
- The common text box is known as the edit controlin the API.
- Buttons are simply called button controls.
- Labels are called static controls.
- If it's enough for your purposes, you can also create a dialog window using CreateDialog(). This is possibly a bit easier, since dialogs can be designed using the resource editor, while you have to create all the controls in a regular window programmatically.
- 通常称为控件的东西称为“窗口”,是使用CreateWindowEx()创建的。该函数根据指定的“窗口类”创建不同的东西,例如编辑、按钮和静态(如下所述)。您可以通过注册自定义类来创建常规窗口。
- 您可以使用名为GetOpenFileName()的函数来调用打开的对话框。
- 公共文本框在 API中称为编辑控件。
- 按钮简称为按钮控件。
- 标签称为静态控件。
- 如果这足以满足您的目的,您还可以使用CreateDialog()创建一个对话窗口。这可能更容易一些,因为可以使用资源编辑器设计对话框,而您必须以编程方式在常规窗口中创建所有控件。
回答by virious
In Visual Studio:
在 Visual Studio 中:
File -> New Project
In the left panel choose "Visual C++" (or C# if you prefer) and in the right panel choose Windows Forms Application. Click Ok.
When your project is created, in the Toolbox panel you can find Button, Edit Box, OpenFileDialogs and SaveFileDialogs (which you need). If you can't find Toolbox panel, you can enable it in View->Toolbox menu.
Place the controls you need on the program window as you wish by simply dragging them over.
文件 -> 新建项目
在左侧面板中选择“Visual C++”(或 C#,如果您喜欢),然后在右侧面板中选择 Windows 窗体应用程序。单击确定。
创建项目后,在“工具箱”面板中,您可以找到按钮、编辑框、OpenFileDialogs 和 SaveFileDialogs(您需要)。如果找不到 Toolbox 面板,可以在 View->Toolbox 菜单中启用它。
只需将您需要的控件拖过来,即可根据需要将它们放置在程序窗口中。