tags:

views:

417

answers:

13

Hello everyone,

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?

I think about a WinAPI-Application in plain C or C++.

+5  A: 

If all you have is the Windows API, you'll be using your text editor to create the UI widgets in code. There's no XAML or other intermediate language or markup involved. 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.

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. But the question asked about the Windows API and C/C++. That brings us back to Petzold. Not the crap he's written recently, but the "Programming Windows" stuff. 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!

Dave Markle
t's quite possible to implement a dynamic layout system that works directly with Win32 HWNDs, and offers all facilities that you see in Swing/WPF/Qt/whatever layouts.
Pavel Minaev
A: 

All a GUI editor does is write code that reflects the properties of those items that you placed on the form. Without a GUI editor, you will need to write all of the code yourself.

Michael Todd
And figure out the coordinates of all the controls on the form, and the form size. Lots of code/compile/run cycles to get it right.
Ken White
@Ken -- Every major modern GUI library provides layouts/sizers, and unless you have a very special case, you should be using them instead of manual positioning.
Steve S
@Steve: "I think about a WinAPI-Application"
Pavel Minaev
@Pavel: Good point. I would recommend picking a different lib, but if the OP is set on WinAPI, then Ken's comment is absolutely right.
Steve S
A: 

I am not sure if I'm answering your question, but I usually design a GUI using a pencil and a piece of paper.

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.

Then I code the HTML from that. I find it more effective to use a pencil than a mouse in some circumstances.

Joel Provost
A: 

You can write .rc files by hand for dialog boxes. 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.

Brian Ensink
Does this only work with microsoft compilers or does it work with gcc, too?
Inno
RC files are specific to creating Win32 apps and you need to use Microsoft's RC file compiler to compile the resources. You might be able to build the rest of the app with GCC but don't confuse that with any kind of cross platform support.
Brian Ensink
A: 

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 ?

Antoine Claval
+2  A: 

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.

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.

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. I can't find the link.

Priyank Bolia
Using a graphical API like wxWidgits does make your life easier - especially using sizers. In fact many windowing libraries offer such layout APIs - including Java's own Swing. I've written a portable GUI application using only text and wxWidgets that cross compiled for both Microsoft Windows and Linux and I was very happy with the result.
PP
I almost never use an IDE UI editor for Swing, as most of the apps I've done are data driven. Using an IDE is OK for one-off forms, but for anything where you want to abstract over tens or hundreds of views they are simply the wrong tool.
Pete Kirkham
A: 

The experience of developing a GUI is very different deppending on the graphical toolkit you're using. 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. Of course, you'll need to install the libraries on 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. 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.

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. 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.

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. It has visual editors, also, if you'll change your mind.

Khelben
A: 

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.

Square Rig Master
m4 would be good for creating the macros.
waffleman
+4  A: 

Qt has layouts that allows you to easily implement a basic GUI without resorting to hand-laying out your GUI.

doron
A: 

You'll need to learn the API's for your particular windowing system. Under MS Windows this would be the Windows API if you're going down as low as possible, or perhaps using MFC in C++. 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. You might want to try it once just to prove you can do it, but in my experience it's neither productive or necessary.

Bob Jarvis
A: 

I recommend Gtk+. TkInter also is usable.

vitaly.v.ch
A: 

Use Visio or some other programmable diagramming tool.

Write an exporter that converts your drawing into the C code for your library. Win32 if that's your flavor.

One day of work writing this exporter will save you hours of "compile-run-checkifitswhereiwantittobe".

Frank Krueger
A: 

I think the best way to design a GUI is to use a mark-up language like Mozilla XUL. However, Mozilla implemented XUL to be used with the Gecko engine, not for native Windows applications. That's why I am creating my own implementation on top of Windows, if you are interested you can check it out: XULWin.

StackedCrooked