简体   繁体   English

在没有GUI设计器的情况下实现GUI的最佳方法是什么?

[英]What is the best way to implement a GUI without a GUI designer?

if someone doesn't want to use an IDE (just an editor, a compiler and a debugger) what is the best way to impelement a GUI by hand? 如果某人不想使用IDE(仅仅是编辑器,编译器和调试器),那么手工实现GUI的最佳方法是什么?

I think about a WinAPI-Application in plain C or C++. 我考虑使用纯C或C ++的WinAPI-Application。

If all you have is the Windows API, you'll be using your text editor to create the UI widgets in code. 如果只有Windows API,那么您将使用文本编辑器以代码创建UI小部件。 There's no XAML or other intermediate language or markup involved. 没有涉及XAML或其他中间语言或标记。 If you want to do layout, you'd use pencil and paper or a graphical tool like Visio to mock up the UI so you can do the math about where you want everything to be. 如果要进行布局,则可以使用铅笔和纸或Visio之类的图形工具来模拟UI,以便可以算出所需的所有内容。

Or alternatively, you can just stick a rusty screwdriver in between your little toe and your little toenail. 或者,您也可以将生锈的螺丝刀插入小脚趾和小脚趾甲之间。 That might be less painful. 这样可能不会那么痛苦。

EDIT : Other posters have talked about using other frameworks like Qt or using layout panels and such. 编辑 :其他海报讨论了使用其他框架,如Qt或使用布局面板等。 But the question asked about the Windows API and C/C++. 但是问题是关于Windows API和C / C ++的。 That brings us back to Petzold . 这使我们回到了Petzold Not the crap he's written recently , but the "Programming Windows" stuff. 不是他最近写废话 ,而是“ Programming Windows”的东西。 Great in its day, and it was pretty much the way things were done 15 years ago, but I'd never go back without a very, very good reason to! 当时很棒,这几乎是15年前的工作方式,但是如果没有非常非常好的理由,我永远不会回头!

Qt的布局使您可以轻松实现基本的GUI,而无需手工布局GUI。

Most of the answers are plain wrong IMHO. 大多数答案都是错误的恕我直言。 You don't give precise coordinates without GUI editor using Pencil and Paper, that would be too much bad way. 如果没有使用Pencil and Paper的GUI编辑器,您不会给出精确的坐标,那将是非常糟糕的方法。

I used to create Forms using hand, but I used wxWidgets and sizer , it pretty easy to create forms using hands, just add a sizer and the control. 我曾经使用过手动创建表单,但是我使用了wxWidgets和sizer ,使用手来创建表单非常容易,只需添加一个sizer和控件即可。

Also there are various notations to do that in wxWidgets By Jorg http://www.xs4all.nl/~jorgb/wb , where you just specify form layout in one line, and it will generate the code. 在Jorg http://www.xs4all.nl/~jorgb/wb的 wxWidgets中,也可以使用各种符号来表示,只需在一行中指定表单布局,它就会生成代码。 I can't find the link. 我找不到链接。

I recommend Gtk+. 我推荐Gtk +。 TkInter also is usable. TkInter也可以使用。

All a GUI editor does is write code that reflects the properties of those items that you placed on the form. GUI编辑器所做的只是编写代码,以反映您放置在表单上的那些项目的属性。 Without a GUI editor, you will need to write all of the code yourself. 没有GUI编辑器,您将需要自己编写所有代码。

I am not sure if I'm answering your question, but I usually design a GUI using a pencil and a piece of paper. 我不确定是否要回答您的问题,但是我通常使用铅笔和纸来设计GUI。

I draw out the layout of the interface, then in faint lines draw boxes around the DIV tags and how control-sets that are grouped together. 我绘制了界面的布局,然后用淡淡的线条在DIV标签周围以及如何将控件集组合在一起的地方绘制了框。

Then I code the HTML from that. 然后,我从中编写HTML代码。 I find it more effective to use a pencil than a mouse in some circumstances. 我发现在某些情况下使用铅笔比使用鼠标更有效。

You can write .rc files by hand for dialog boxes. 您可以手动为对话框编写.rc文件。 For the main window frame and views etc you will need to write code by hand. 对于主窗口框架和视图等,您将需要手工编写代码。 You can get a jumpstart on that code if you use one of Visual Studio's wizards to stub in the project. 如果使用Visual Studio的向导之一在项目中存根,则可以快速获得该代码。

Mock it on paper or whereever you want. 将其模拟在纸上或任何需要的地方。

Be precise on margin, width, left alignement ... 在边距,宽度,左对齐上要精确...

Once you get a precise idea of the position of each element on the screen, you "just" have to translate it. 一旦您对每个元素在屏幕上的位置有了准确的了解,您就可以“翻译”它。

It's that a punition or something ? 那是惩罚,还是什么?

The experience of developing a GUI is very different deppending on the graphical toolkit you're using. 开发GUI的经验与您所使用的图形工具包的依赖截然不同。 In Windows the most typical (and I think that low level) is MFC API, but it's not the only possibility, as you can also use a higher approach with tools like GTK+ or Tk. 在Windows中,最典型的(我认为是低级别的)是MFC API,但这不是唯一的可能性,因为您还可以对GTK +或Tk等工具使用更高的方法。 Of course, you'll need to install the libraries on Windows. 当然,您需要在Windows上安装这些库。

For example, in GTK+, you can use XML files to describe most of the GUI, which could be easier than making them hard-coded. 例如,在GTK +中,您可以使用XML文件来描述大多数GUI,这比将它们进行硬编码更容易。 Also you can make a VBox object and add other objects to it, and automatically the objects will be positioned one below the previous, instead of having to measure and describe its XY position. 您也可以制作一个VBox对象并向其中添加其他对象,然后自动将这些对象放置在前一个对象的下方,而不必测量和描述其XY位置。

Making a GUI without a visual editor is perfectly possible (I have made some), but having a visual editor is almost always a great great advantage. 不用可视化编辑器来制作GUI是完全有可能的(我做了一些),但是拥有可视化编辑器几乎总是一个很大的优势。 But, with actual technology, it's better to use the higher level possible tool available. 但是,使用实际技术,最好使用可用的更高级别的工具。 Programming any GUI on C/C++ with raw MFCs and without visual editor could be really hard. 在C / C ++上使用原始MFC在没有可视编辑器的情况下对任何GUI进行编程可能真的很难。

I recommend you at least taking a look on GTK+ ( http://www.gtk.org/ ) You can use it from C++ (also other languages like Python and C#) and it's not very difficult to use withouta visual editor. 我建议您至少看看GTK +( http://www.gtk.org/ )。您可以从C ++(以及其他语言,如Python和C#)中使用它,并且没有可视化编辑器也很难使用。 It has visual editors, also, if you'll change your mind. 如果您改变主意,它还具有可视化编辑器。

It is hard work so I recommend using a text editor that supports text substitution macros and creating your own "syntax" for handling repetitive tasks. 这项工作很辛苦,因此我建议使用支持文本替换宏的文本编辑器,并创建自己的“语法”以处理重复性任务。 Some good text editors allow you to define your own "intellisense" and have Win32 API intellisense already built in. 一些优秀的文本编辑器允许您定义自己的“ intellisense”,并已内置Win32 API intellisense。

You'll need to learn the API's for your particular windowing system. 您需要学习特定窗口系统的API。 Under MS Windows this would be the Windows API if you're going down as low as possible, or perhaps using MFC in C++. 在MS Windows下,如果您希望降低运行速度,或者使用C ++中的MFC,则将使用Windows API。 In any case it's a process of try it and fix it and try it again and fix it some more, etc, ad nauseum. 无论如何,这都是一个尝试并修复它的过程,然后再次尝试并修复它,等等,等等。 I had to do this years ago under X/Windows and it was slow and painful. 几年前,我不得不在X / Windows下进行此操作,它既缓慢又痛苦。 You might want to try it once just to prove you can do it, but in my experience it's neither productive or necessary. 您可能只想证明它可以尝试一次,但是根据我的经验,这既没有成​​效,也没有必要。

Use Visio or some other programmable diagramming tool. 使用Visio或其他一些可编程的图表工具。

Write an exporter that converts your drawing into the C code for your library. 编写一个导出程序,将图形转换为库的C代码。 Win32 if that's your flavor. Win32,如果那是您的口味。

One day of work writing this exporter will save you hours of "compile-run-checkifitswhereiwantittobe". 工作一天,编写此导出程序将为您节省数小时的“ compile-run-checkifitswhereiwantittobe”。

I think the best way to design a GUI is to use a mark-up language like Mozilla XUL. 我认为设计GUI的最好方法是使用Mozilla XUL等标记语言。 However, Mozilla implemented XUL to be used with the Gecko engine, not for native Windows applications. 但是,Mozilla实现了XUL与Gecko引擎一起使用,而不是用于本地Windows应用程序。 That's why I am creating my own implementation on top of Windows, if you are interested you can check it out: XULWin . 这就是为什么我要在Windows之上创建自己的实现的原因,如果您有兴趣,可以查看一下: XULWin

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

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