如何编写CPP GUI程序 [英] How to write CPP GUI program

查看:132
本文介绍了如何编写CPP GUI程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai每个人,
目前,我正在VB.NET中开发Windows项目.我正在寻找在CPP域中开发GUI的工具.
谁能帮我做到这一点.
即使我没有任何开发工具.
请给我建议任何开发工具.

解决方案

这似乎是一个完全合理的问题.如果您已经在使用Visual Studio,那么您已经拥有IDE.如果没有,则可以从此Microsoft网站获取Visual C ++ Express的副本. [ ^ ]. VS中有一些示例模板可帮助您入门,还有此处的文章 [
最接近我期望的C ++ gui库是Qt,但是该库很重(下面将详细介绍),并且使用代码生成器,对于C ++初学者来说,它的特殊语法和解决方案可能会非常复杂. />
MFC:糟糕的API,甚至不是完全C ++风格的(不是基于小部件的).它有很多方法,它们的名称与底层包装的winapi相同,但参数不同.尽管我非常擅长使用winapi创建gui,但当我启动MFC时,这使我感到困惑.可怜的api为简单的问题(例如拆分器)提供了如此复杂的解决方案,以至于您甚至在数年后都无法记住它,因此您必须搜索网络并将其每次都复制并粘贴到您的代码中.可调整大小的控件和对话框需要额外的精力和帮助程序库(您在codeproject上找到了一些).如果您不使用大量廉价的设计欠佳的自定义控件,则以此方式创建的gui可以看起来像Windows的本机.
wxWidgets:我的观点与MFC几乎相同,它是一种跨平台的MFC,其中添加了一些额外的sh * t以保持跨平台.请注意,MFC不仅是一个纯GUI库,它还是一个大型应用程序框架,它也为其他问题(网络,文件管理等)提供了很多帮助程序类,但我不建议您习惯于这些您是否要创建跨平台代码的帮助器.
C ++/CLI: .Net gui构建器非常好并且基于小部件.还没有混合使用c ++和.net,但是iam仍然是异构系统.我的一个朋友使用.net为C ++项目创建gui,遗憾的是这是一个很大的错误.调试问题,缓慢的用户界面,许多错误,因为当他们开始使用C ++和cli之间的门时,要花一些时间才能习惯ppl所犯的常见错误.学习曲线更长,因为您必须使用2种语言-即使使用C ++/cli,额外的学习复杂性也是正确的. .Net有一个非常不错的UI编辑器,它使用锚定来提供可调整大小的布局(我最喜欢的通用布局机制),因此,此选项乍看之下似乎很吸引人,但是它有很多缺点. Visual Basic,.net和delphi使用非常相似的精美gui生成系统.有人应该为c ++编写过一个,但是没有人开始这样做.通过使用与JFormDesigner for Java swing相同的工作流,将完全有可能.
Qt:基于小部件.具有与.net和delphi相似的快速思想,但我从未喜欢过它的布局机制和在这两种操作系统上都看不到的控件.它具有信号时隙机制(一种被炒作的和完全不必要的功能),可以在对象之间发送事件(例如单击按钮的事件),但我从来没有发现为什么它比事件侦听器更好,但是至少有必要使用代码我不喜欢的带有Qt的生成器.您使用c ++编写gui代码,并且在编译之前必须使用qt代码生成器对其进行预处理.我还要提到,Qt包含许多其他与gui不相关的辅助程序库,例如MFC,这使它变得非常庞大且笨重(但是,这在pc程序中并不总是一个问题). Qt的一个不错的功能是,一些复杂的控件具有数据模型(如Java swing中的数据模型),对于许多尚未使用现代gui库的ppl来说,这是一个很大的黑匣子,但是如果我编写了gui库,我会使用每个控件中的数据模型.

如果您想了解用于gui编程的底层C winapi,请购买通过Petzold购买Windows编程".如Aescleal建议.那是从C的一般winapi和GUI编程开始的最好的书.它是用C而不是C ++编写的,因为大多数基本winapi是不带c ++支持的纯C语言,因此即使从C ++开始,也将其用作C.即使您将完整的C ++库用于某种形式的东西,了解您的库所使用的基础C winapi也很不错.当您要开始编写自己的C ++快速gui开发工具时,这将非常有用. :D我应该开始基于Delphi,swing和JFormDesigner的最佳实践来编写一个,但是我只是不想为此而牺牲自己的时间.

我不好,我提到了JBuilder而不是JFormDesigner. :D *更正*
添加了有关小部件的一些说明.我认为小部件是什么?

另一个总是忘记提及 C ++ Builder ,那是Borland的Delphi的同级兄弟.如果我是对的,那么该产品仍在开发中.它由与Delphi完全相同的IDE和gui库驱动!我们只是停止使用它,因为它的自定义C ++编译器(我们首选VC ++)存在崩溃错误.我们在编译一些跨平台库时也遇到了一些问题,但这是一个小麻烦.也许他们已经修复了这些错误.我之所以没有使用它,是因为我很喜欢VC ++(大多数库都支持该编译器),并且因为C ++ Builder并不是跨平台的(至少在我使用它时没有用).不过,如果您想知道我对gui开发的含义,请务必查看Delphi(objectpascal)或C ++ Builder !!!我在Delphi中不喜欢它没有类型安全的容器(它们已经引入了泛型),而我从gui中错过的另一件事是它们应该具有数据模型,至少在复杂的控件中(列表视图,树,.). ..).由于内置的​​gui序列化支持和其他一些花哨的东西,例如用于处理gui事件的对象方法指针(代理),因此需要自定义编译器.
另一个问题是,我不知道您目前是否可以免费使用它.但是,如果定价不是问题,并且您可以坚持使用Windows和C ++ Builder的编译器,那么这绝对是Windows上非常非常好的开发和GUI生成环境!!!!尤其是如果您正在编写数据库处理应用程序,因为它还具有支持该功能的组件和表控件!


请仔细阅读 ^ ]

该产品使用起来很有趣,视觉设计师也很棒.

您将能够像在VB.Net中一样快地创建工作程序.

最好的问候
Espen Harlinn


Hai Every one,
Presently i am developing windows projects in VB.NET. I am looking to develop GUI''s in CPP domain.
Can any one help me to do this.
Even i don''t have any Development tool.
Plss suggest me any development tool.

Thanks in ADV.

解决方案

This seems a perfectly reasonable question. If you are already using Visual Studio then you have the IDE already. If not then you can get a copy of Visual C++ Express from this Microsoft site[^]. There are sample templates within VS to get you started, and there are articles here[^] on CodeProject to give you even more useful ideas. However, as Sergey Alexandrovich mentions, you really need to get a book on C++ to learn properly.


If you need a short answer: There is no fine solution. I used a lot of gui libraries extensively (in many languages), and the best would be a not too heavyweight widget based library without hacky solutions. There is no really good, clean solution for C++ unfortunatlely.
First, what is a widget based system??? I give this honours only to a gui library that uses object oriented design. Every control every panel, and every window is an object. In optimal case all you do is creating widget objects and setting their properties. Even building a gui hierarchy is just about setting the ''parent'' property of the widgets. MFC and its friends are not widget based, and to make things worse, they are built on top of the heritage of low level win32 api solutions like dialog resources, and they are adding their own non-object oriented cr*p to the C winapi. These are so outdated solutions!!! Not to mention that its impossible to make such a program portable!!! (proting dialog resources???) If you are new to gui programming on win32, you have 2 choices. You can learn the the low level winapi + dialog resource stuff, and maybe later you learn MFC that builds on top of that, or you learn building gui with a nice widget based system. Using a well designed widget based system will eliminate a lot of bugs from your program, you will be able to build nicer guis faster, and usually a program based on a widget based system is much easier to make crossplatform, and its easier to change the gui system later. If you don''t wanna build heavily size-optimized small executables (4k intro :D) and you are not that interested in the gui related winapi, then you dont have to learn it and definately go on with learning about widget based systems.

The C++ gui library that is the nearest to my expectations is Qt, but that library is heavyweight (I''m detailing it below) and uses code generator, its special syntax and its solutions might be very complex for a C++ beginner.

MFC: Terrible API, not even fully C++ style (not a widget based one). It has lots of methods which have the same name as the underlying wrapped winapi, but with different parameters. This confused me when I started MFC despite the fact that I was very good at creating gui with winapi. The poor api gives so complex solutions to simple problems (like splitters) that you can''t memorize it even after years, you have to search the net and copy paste it right into your code every time. Resizable controls and dialogs need extra effort and helper libraries (you found some on codeproject). The gui you create with this can look nice windows native if you dont use a lot of cheap poorly designed custom controls.
wxWidgets: My opinion is nearly the same as about MFC, its a crossplatform MFC with some extra sh*t added to keep the stuff crossplatform. Note that MFC isn''t only a pure gui library, its a big application framework that provides a lot of helper classes for other problems too (networking, file management, ...) but I don''t recommend getting used to those helpers if you want to create crossplatform code.
C++/CLI: The .Net gui builder is nice and widget based. Haven''t mixed c++ and .net yet, but iam agains heterogenous systems. One of my friends used .net to create gui for a c++ project and it was a big mistake with regrets. Debugging problems, slow UI, lots of bugs because it takes some time to get used to the common mistakes ppl make when they start using the gate between C++ and cli. Longer learning curve because you have to use 2 languages - the extra learning complexity is true even if you use C++/cli. .Net has very nice UI editor that uses anchoring to provide resizable layout (my favorite general layout mechanism), so this option seems to be an attractive one at first, but it has a lot of drawbacks. Visual basic, .net, and delphi use very similar nice gui building systems. Someone should have made one for c++, but noone started doing it. It would be completely possible by using the same workflow as JFormDesigner for java swing.
Qt: Widget based. Has a similar rapid ide as .net and delphi but I never liked its layout mechanisms and the controls that look native on neither operating systems. It has a signal-slot mechanism (a hyped and totally unnecessary feature) to send events between objects (events like button clicking), I never found out why is this better than an event listener, but it at least makes necessary to use a code generator with Qt that I don''t like. You write your gui code in c++ and before compilation you have to preprocess it with the qt code generator. I would also mention that Qt contains a lot of other not gui related helper libraries like MFC that make this quite a big bloat and heavy-weight (however this isn''t always a problem in a pc program). A nice feature of Qt that some complex controls have data model (like in java swing) that is a big black box for a lot of ppl who haven''t worked with modern gui libraries, but if I wrote a gui library I would use data models in every controls.

If you want to understand the underlying C winapi for gui programming, then buy "Buy Programming Windows by Petzold." as Aescleal recommended. Thats the best book to start out with general winapi and GUI programming in C. Its in C and not C++ because most of the basic winapi is pure C without c++ support, so you use it as C even from C++. Even if you use a complete C++ library for some kind of stuff, its good to know the underlying C winapi that you library uses. This will be useful when you want to start writing your own rapid gui development tool for C++. :D I should start writing one based on the best practices of Delphi, swing and JFormDesigner, but I just dont want to sacrifice my time for it.

EDIT: My bad, I mentioned JBuilder instead of JFormDesigner. :D *corrected*
Added some explanation about widgets. What do I consider a widget?

ANOTHER EDIT: Always forgot to mention C++Builder, that was the sibling of Delphi from Borland. If I''m right that product is still in development. It is driven by exactly the same IDE and gui library as Delphi! We just stopped using it because of its custom C++ compiler (we preferred VC++) that had crash bugs. We also had some problems with compiling some crossplatform libraries but that was a minor headache. Maybe they have fixed those bugs already. I''m not using it because I''m a VC++ fun (most libraries support this compiler) and because C++Builder is not crossplatform (at least it wasnt when I used it). Still, if you want to know what I mean on gui development definately check out either Delphi(objectpascal) or C++Builder!!! What I didn''t like in Delphi that it had no typesafe containers (they already introduced generics) and another stuff I miss from the gui is that they should have a data model, at least in the complex controls (listview, tree, ...). The custom compiler is needed because of the built in gui serialization support and some other fancy stuff - like the object method pointers (delegates) that are used to handle gui events.
Another problem is that I don''t know if you can use it for free currently. But if pricing isn''t a problem and you can stick to windows and the compiler of C++Builder, then this is definately a very-very nice development and gui building environment on windows!!!!!!! Especially if you are writing database handling applications because it also has components and table controls that support that!


Take a good look at C++Builder XE2[^]

This product is fun to work with, and the visual designer is very good.

You''ll be able to create working programs just as fast as you are able to do it in VB.Net.

Best regards
Espen Harlinn


这篇关于如何编写CPP GUI程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆