如何在 Visual C 中创建非托管 Windows GUI?
当我创建“Windows 窗体应用程序”时,生成的程序是托管程序。创建“Win32 应用程序”会生成本机应用程序,但当我尝试添加表单时,我被告知如果继续,该项目将转换为 CLI。如何使用 Visual C++ 2008 Express Edition 设计本机 Windows GUI?我在这里可能很傻,但我就是想不通。
When I create a 'Windows Forms Application', the resultant program is a managed one. Creating a 'Win32 Application' results in a native one, but when I try to add a form I'm informed that the project will be converted to CLI if I continue. How do I design a native Windows GUI with Visual C++ 2008 Express Edition? I'm probably being very silly here, but I just can't figure it out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
使用 MFC、WTL 或直接 Win32 API。如果不切换到托管代码,则无法使用表单(或任何 .NET)。
Either use MFC, WTL, or straight Win32 API. You can't use forms (or any of .NET) without switching into managed code.
您只需要避免托管库即可。最有可能的是,这意味着使用 MFC 作为 GUI,而不是 Windows 窗体。有关详细信息,请参阅 MSDN 的 MFC 页面。
不幸的是,VC++ Express Edition 不直接支持 MFC,因此您将受到更多限制。可以使用 Express 版本编译 MFC 项目,但您会丢失所有内容如果您认真进行非托管 GUI 开发,则应考虑升级到更高级别的 SKU。
另一种选择是使用 Qt 来实现 GUI。它现在是 LGPL,因此可以免费使用,甚至可以在商业 C++ 项目中使用,并且包含完整的设计器。
You just need to avoid the managed libraries. Most likely, this will mean using MFC for the GUI, instead of Windows Forms. For details, see MSDN's MFC pages.
Unfortunately, VC++ Express Edition doesn't support MFC directly, so you'll have be more limited. It is possible to compile MFC projects using the Express Edition, but you lose all of the Wizards, etc. If you are serious about doing non-managed GUI development, you should consider upgrading to a higher level SKU.
Another option would be to use Qt for for GUI. It is now LGPL, so usable, for free, in even commercial C++ projects, and includes a full designer.
这是链接问题的答案。不幸的是,罗伯特·哈维已经关闭了该网站,因为他认为这是重复的。事实并非如此,抱歉鲍勃。
创建 xll 的最佳库是 http://xll.codeplex.com。您可以使用它来使用 Excel 宏创建基本的用户界面。其中一个示例可以在 xll/error.cpp 中的 ALERT.FILTER 宏中找到
This is an answer to the linked question. Unfortunately, that has been closed by Robert Harvey because he thinks it is a duplicate. It is not, sorry Bob.
The best library for creating xll's is http://xll.codeplex.com. You can use that to create rudimentary user interfaces using Excel macros. One example of that can be found in the ALERT.FILTER macro in xll/error.cpp
正如 Reed Copsey 所说,MFC 将是在 Windows 平台上创建本机非托管 GUI 的“默认”方式。但是,MFC 不包含在 Visual Studio Express 中。因此,您要么需要升级到完整版本,要么可以考虑使用免费的 C++ GUI 库,例如 wxWidgets 。
如果您想要 GUI 编辑器,还有 wxFormsBuilder。
您还可以进入“裸机”并直接编写 Win32 API,也许可以从 常用控件库。但你将进入一个痛苦的世界;)
As Reed Copsey, MFC would be the "default" way of creating a native unmanaged GUI on the Windows platform. However, MFC is not included with Visual Studio Express. Consequently, you would either need to upgrade to the full version or you could look into using a freely available C++ GUI library such as wxWidgets.
There is also wxFormsBuilder if you want a GUI editor.
You could also go down to the "bare metal" and code right to the Win32 API, maybe take some help from the common controls library. But you'll be entering a world of pain ;)
您需要使用本机应用程序框架。对于 Windows,这意味着 MFC 或裸 Win32 库。 WinForms 在后台使用.NET 库,因此需要进行管理。
You would need to use a native application framework. For Windows this means MFC or the bare Win32 libraries. WinForms use .NET libraries in the background and therefore need to be managed.
本机应用程序不使用“表单”。例如,对于本机应用程序,您可以创建 MFC 应用程序。如果您希望它是基于表单的应用程序,您可以告诉向导您想要一个基于对话框的应用程序,或者(在向导的最后一页上)让您的视图从 CFormView 而不是 CView 派生。
或者,您可能想要使用 WTL——尽管这意味着基本上用手编写所有代码,而不是使用向导等。
Native applications don't use "forms". For a native application, you could create, for example, an MFC application. If you want it to be something like a form-based application, you can tell the wizard you want a dialog-based application, or (on the last page of the Wizard) have your view derive from CFormView instead of CView.
Alternatively, you might want to use WTL -- though that means writing essentially all your code by hand instead of using wizards and such.
Windows 窗体是作为 Microsoft .NET Framework 一部分包含的图形应用程序编程接口 (API) 的名称,通过将现有 Windows API 包装在托管代码中来提供对本机 Microsoft Windows 界面元素的访问。 >
Windows Forms is the name given to the graphical application programming interface (API) included as a part of Microsoft's .NET Framework, providing access to the native Microsoft Windows interface elements by wrapping the existing Windows API in managed code.
上面的大多数答案都很好地解释了事情 - 如果您想研究创建纯 Win32 本机应用程序表单(无 MFC/WTL 等),请查看此处的教程: http://www.zetcode.com/tutorials/winapi/ 对于初学者来说。这是我第三次链接到这个网站,但他的教程非常好。
注意 - 在这个阶段,除了结果之外,没有任何“视觉”内容 - 这一切都是在代码中完成的,尽管我并不认为这真的太困难。这绝对会是很好的编程体验。
Most of the above answers explain things pretty well - if you want to look into creating a pure Win32 Native App form (no MFC/WTL etc) take a look at the tutorials here: http://www.zetcode.com/tutorials/winapi/ for starters. That's the third time I've linked to this site on here, but his tutorials are very good.
Note - at this stage there's nothing "visual" about it except the result - it is all done in code, although that said I don't think it is too difficult really. It will definitely be good programming experience.
Windows 窗体是用托管代码编写的 GUI 框架,因此您无法在本机应用程序中使用窗体。
对于本机应用程序,您必须创建窗口。 Charles Petzold 的Windows 编程是这方面的权威指南书。与使用一个好的框架相比,这是一项大量的工作。 MFC(Microsoft 基础类)是本机 Windows GUI 的框架。不知道VC++ Express 是否自带。
Windows Forms are a GUI framework written in managed code, so you cannot use Forms in a native application.
With a native application, you have to create windows. Programming Windows by Charles Petzold is the definitive how-to book for this. It's a lot of work compared to using a good framework. MFC (Microsoft Foundation Classes) is a framework for native Windows GUIs. I don't know if it comes with VC++ Express.
我注意到没有人提到 JUCE 可以用来在 C++ 中构建跨平台用户界面。我觉得这很酷。自从我使用它以来,它似乎也已扩展到支持移动设备。
个人和教育许可证是免费的。 “专业”和“独立”许可证相对便宜。
I noticed that no one mentioned JUCE which can be used to build cross platform user interfaces in C++. I thought it was pretty cool. Looks like it's been expanded to support mobile devices too since I used it.
Personal and Educational licenses are free. 'Pro' and 'Indie' licenses are relatively cheap.