简体   繁体   English

将gui添加到c ++项目(visual studio 2010)

[英]Add gui to c++ project (visual studio 2010)

  1. I created a c++ project, and now I want to add a Graphical Interface to it. 我创建了一个c ++项目,现在我想为它添加一个图形界面。 When I click on Project-->Add New Item , and choose to add Windows Form , it creates a header and source file but with a lot of errors such as: 当我单击项目 - >添加新项目 ,并选择添加Windows窗体时 ,它会创建一个标题和源文件,但有很多错误,例如:

    (problems with "public, privte, this - 'this' may only be used unside a nonstatic member function", "System",...) What are these problems? (“public,privte,this - 'this'的问题可能只能用于非静态成员函数”,“系统”,......)这些问题是什么? How can I make the form show when the project is run? 如何在项目运行时使表单显示?

  2. When I open a new project "Win32 Application", all I see (and can edit) is the menu and dialog box...where can I go to see the main form?? 当我打开一个新项目“Win32应用程序”时,我看到(并且可以编辑)的是菜单和对话框...我在哪里可以看到主要表单?

Thanks! 谢谢!

There are 2 types of native C++ ways of making a gui (using the win32 api); 有两种类型的本机C ++制作gui的方法(使用win32 api); MFC, and straight API. MFC和直接的API。

MFC has a lot of pre-made components and classes - what you did (adding a form to a regular project) didn't work since the project wasn't set up for MFC. MFC有很多预制组件和类 - 你所做的(向常规项目添加表单)不起作用,因为没有为MFC设置项目。

When you create a new win32 project (not mfc or console) - the methods used to create windows+such are more similar to a tutorial here . 当你创建一个新的win32项目(而不是mfc或控制台)时 - 用于创建windows +的方法更类似于这里的教程。 You can visually design your windows using this approach, embedding them in resources - but you'll need at least the professional version of visual studio to do that. 可以使用这种方法直观地设计你的窗户,将它们嵌入资源中 - 但你至少需要专业版的visual studio来做到这一点。

If you're just starting out with GUIs however - you'd be better off using something like wxWidgets 如果你刚开始使用GUI,那么你最好使用像wxWidgets这样的东西

Not putting you down, but accept this fact - GUI programming in C++ is pain. 不是让你失望,而是接受这个事实 - 用C ++编写GUI程序很痛苦。 Though I would suggest you to start with MFC based application, since it is nicely integrated with Visual Studio, and you need not to install any third party library. 虽然我建议你从基于MFC的应用程序开始,因为它与Visual Studio很好地集成,你不需要安装任何第三方库。 MSDN is also there - samples, umpteen examples on net is also available. MSDN也在那里 - 样本,网络上的无数例子也可用。 You should start with Dialog-based application, VS has nice facilities to have GUI-MFC mapping. 你应该从基于Dialog的应用程序开始,VS有很好的设施来进行GUI-MFC映射。

Others may advice you to start off with QT, wxWigets, which are good options, but learning curve would be more and you'd simply get tired with issues you encounter. 其他人可能建议你从QT开始,wxWigets,这是很好的选择,但学习曲线会更多,你只会对遇到的问题感到厌倦。 You will need to download, install and configure the stuff. 您需要下载,安装和配置这些东西。

If you aren't faint hearted, you can start with native Windows GUI development - do everything from the core, which includes setting up the Window-structures, writing message-loop, the message-map (switch-case) and all. 如果你没有胆怯,你可以从本机Windows GUI开发开始 - 从核心做一切,包括设置Window结构,编写消息循环,消息映射(switch-case)等等。

  1. If type of your application was Console Application, the best way is to start over a new Win32 Application project (as you did) 如果您的应用程序的类型是控制台应用程序,最好的方法是重新启动一个新的Win32应用程序项目(就像您一样)

  2. Win32 Application is clean WinAPI application, you are generally cannot construct main window graphically. Win32应用程序是干净的WinAPI应用程序,您通常无法以图形方式构造主窗口。 You can try and create "Dialog Application" (afair it's some option in Win32 Application), but dialogs are not exactly the most versatile thing for a GUI. 您可以尝试创建“对话框应用程序”(这是Win32应用程序中的一些选项),但对话框并不是GUI的最通用的东西。

If you're unfamiliar with WinAPI programming, you can start a separate question where you describe your requirements for GUI and your knowledge and people will suggest the tool/framework/approach. 如果您不熟悉WinAPI编程,可以先创建一个单独的问题,在其中描述您对GUI和您的知识的要求,人们将建议工具/框架/方法。

It would be far easier to start a new project, and select "MFC Application" as the application type. 启动一个新项目会更容易,并选择“MFC Application”作为应用程序类型。 The project will then be properly configured for you. 然后将为您正确配置项目。 You can choose to have a dialog application (the main window is a single dialog box, or "form" if you're used to .NET), a single-document application (ala notepad), or an MDI document application (ala Visual Studio). 您可以选择具有对话框应用程序(主窗口是单个对话框,如果您习惯使用.NET,则为“窗体”),单文档应用程序(ala记事本)或MDI文档应用程序(ala Visual工作室)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM