23

In your opinion, what is the best way to create gui in Windows ? with gtk or win32 api ?

Do you recommend GTK for windows ? Yes ? NO ? Why ?

xRobot
  • 25,579
  • 69
  • 184
  • 304

10 Answers10

31

If you are making the gui only for windows, I would strongly recommend WIN 32 Api. I have Made many applications in GTK+ , pyGtk , FLTK and have learned Qt, MFC and SmartWin++. Believe me , But I like Win32 Api the best. It may have a steep learning curve, but for creating native windows applications , it is the fastest and the BEST. And the more complex youre program gets, the easier Win32 Api is compared to other toolkits. And there are things you can do in Win32 Api, which you can not do in any other toolkit.

TESTED:

starting time (simple gui with menu and buttons): GTK+ = 7 secs; Qt = 4 secs; WxWidgets = 3.32 seconds; FLTK = 1 second; Win32 Api = 0.34 seconds;

space taken: Gtk+ = 132 kb; Qt = 4.5 mb; WxWidgets = 4.5 mb; FLTK = 54 kb; Win32 Api = 6.5 kb;

Burning Prodigy
  • 319
  • 3
  • 2
  • Was these file sizes with or without debug symbols? – user877329 May 06 '15 at 14:58
  • 3
    Could you explain why it's so better (other than performance)? especially why the more complex the program gets, the easier it is compared to other toolkits? – MasterMastic Jul 03 '15 at 16:21
  • @MasterMastic Because Win32 is a wrapper around the Windows Kernel APIs (which are proprietary because Windows is proprietary), you literally cannot get lower level than Win32. Other GUI toolkits are simply wrappers around native Win32 or draw their own controls, but even the custom-drawn GUI toolkits need some method to create a window to draw to. That's where Win32 comes in. – HackerDaGreat57 Jul 10 '22 at 18:57
20

Let's see.

  • Win32 is very low-level, C based, and awkward to use.
  • MFC is considered obsolete.
  • C# (or C++) with .NET is probably your primary choice for Windows-specific development.
    • There are even semi-limited ways to port that code to other platforms (Mono).
  • Java is great for very platform-independent code that "just runs". Sorry, you said C++.
  • QT is relatively platform-independent.
  • GTK+, of course, although I personally don't have much experience with it.

Personally, if I do something Windows-specific, I use .NET - the tools in Visual Studio are very powerful, and it's a great all-encompassing suite.

For platform-independent stuff, I use Java, but that may not be your tool of choice. I've seen QT used a lot for that purpose.

EboMike
  • 76,846
  • 14
  • 164
  • 167
16

You really have a lot of GUI toolkits/frameworks to choose from: Qt, wxWidgets, GTK+/gtkmm, WinAPI, MFC, .NET WinForms/WPF... and those are only the popular ones.

Since you limit yourself to C++, I'd strike out .NET because C++ on .NET is intended to serve as a connection between the unmanaged and managed world. That doesn't mean you can't use it for other types of development, but given the awkward syntax and countless pitfalls I'd not go with it. Moreover, the WinForms code generator of VS puts the forms' code into the header file.. brrrr

As others have stated, WinAPI is written in C, very fast and powerful, but very low level and not easy to program/learn. MFC would be an option since it's written in C++, easier to use than WinAPI and also very powerful. However, it's pretty much obsolete (due to the presence of .NET, mostly).

I wouldn't recommend GTK+/gtkmm (a C++ wrapper for GTK+) for Windows since you don't get the native windows look, it's rather annoying to set up on your developer machine and it also drags around tons of dependencies that you have to install on the user machine. That's actually a pity because especially gtkmm has a very beautiful class hierarchy and design. Probably one of the best designed GUI libraries :)

That said, what would I recommend? Either Qt or wxWidgets. Both are written in (fairly modern) C++, actively developed, have a good library design, run multi-platform and offer lots of functionality. In any case, play around with a few of the libraries listed in the answers here and see which one lets you do the things you want to do most easily :)

Christian
  • 4,261
  • 22
  • 24
8

win32 api is too complicated, MFC is too annoying. I have used MFC, win32api, and Qt in windows. In my opnion, Qt is the best one. I havent tried GTK, so sorry knowing nothing about it.

Edit 2019: It looks all these options are outdated, how about the cross-platform solutions, react-native windows, electron

fangzhzh
  • 2,172
  • 21
  • 25
8

both are for c, but there is a good wrapper for gtk (gtkmm).

gtk has its own look, so theres no skinning of ui elements on the user side(with windows styles). but i like to programm with it more.

win32, mfc, .net are mostly limited to ms visual studio, while gtk is very hard to use with vs.

you should have a look on win32, .net, gtkmm and qt. just try to write and compile a simple hello world program with them

upsides of win32:

  • native windows code
  • fast

downsides:

  • no classes, only c with handles (very crappy)
  • in my opinion very bad documented

upsides of gtk(mm):

  • easy to learn/programm
  • good documented

downsides:

  • somehow difficult to install the development files
  • no native windows look
M3t0r
  • 182
  • 9
  • 2
    Another downside of gtk(mm) is that that you have lots of dependencies (glib, gdk, pango etc) and that you always need to drag tons of DLLs to the user machine :/ – Christian Oct 29 '10 at 05:38
  • 1
    @Christian I think you mean that the downside of windows is that it can't handle dependencies at all – alternative May 23 '13 at 22:43
  • +1 for the "in my opinion very bad documented" I hate the documentation as well. You can't get it offline easily unlike GTK. GTK actually looks native now – Xantium Apr 07 '19 at 14:34
  • 1
    @Simon you can download them as PDF, I'd have preferred they made HTML bundles available. – BroVic Jan 09 '20 at 07:59
  • @BroVic I partially use the WinApi, if you could point me to a place where I could get a pdf of the documentation of the reference that would be amazing – Xantium Jan 30 '20 at 07:42
  • @Simon visit the API reference https://learn.microsoft.com/en-us/windows/win32/api/. From here, you can access any of the docs that interest you. Download PDF using the button at the bottom of the navbar on the left. – BroVic Jan 30 '20 at 11:47
  • @BroVic That is only helpful if you need *one or two* pages, not if you need the entire reference – Xantium Jan 30 '20 at 12:25
  • On the contrary, @Simon, I've downloaded 5,000+ pages that way. – BroVic Jan 30 '20 at 17:32
6

If Linux (or Mac) compatibility is your concern, then Qt. Else Win32.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
5

I have used GTK+ in the past for a multi-platform application. I found it relatively simple to learn and use. To my mind the main advantage of GTK+ is that you will be able to port your application to other windowing systems. And the main disadvantage is that it will not look exactly like other windows applications. If you are doing cross platform work or are already very familiar with GTK+ (and don't have time to spend learning a new toolkit), I would recommend it.

Bowie Owens
  • 2,798
  • 23
  • 20
5

Personally I prefer Qt, but it really depends on what kind of user interfaces you want to make.

Against Win32:

  • low-level, high complexity to accomplish trivial things. You have to do EVERYTHING

  • if you go this route I would recomment a book like the one from Petzold.

Pro Qt:

  • Good looking GUIs

  • Can change the look and feel very easily by creating stylesheets

  • Signal and slots mechanism notifies you of UI events such as "button clicked" etc.

  • Nice layout system

  • Integrated with Visual Studio IDE

  • Modern object oriented c++ code, easy to understand and use

  • Qt Assistant (Very good documentation)

  • Relatively liberal licensing (LGPL)

  • Qt Designer - WYSIWYG design tool you can use for form design

  • Comes with a wealth of other c++ functionality including XML, networking, eventloops, threading, database access, etc

Against Qt:

  • Intermediary step of using MOC compiler

Pro WPF:

  • if you want the new WPF capabilities of the new Windows platforms, WPF is the way to go.
Ralf
  • 9,405
  • 2
  • 28
  • 46
  • 1
    Some of the pro's of Qt also apply to Win32, when used from Visual Studio. Integration with VS - check. Forms designer - check. Liberal licensing - duh. Mechanism for capturing button clicks - check. – Seva Alekseyev Nov 02 '10 at 18:12
  • Absolutely love Qt. Best GUI library man has yet created. – Anti Earth Jul 13 '12 at 15:52
  • @SevaAlekseyev haven't checked win32 in visual studio but really? There's a form designer for win32 in Visual Studio? – puerile Sep 22 '21 at 01:22
  • Sure is. Forms were known as dialogs back in the day. The level of service is somewhat below what people are expecting now (e. g. no visual event wireup, no automagical variable/control association). – Seva Alekseyev Sep 22 '21 at 02:36
2

You may want to try Winforms or WPF. If you're limited to using C/C++, you can embed .NET code using the /clr option for the compiler to embed .NET code for Winforms or WPF. Sources:

http://msdn.microsoft.com/en-us/library/k8d11d4s(VS.71).aspx
http://msdn.microsoft.com/en-us/library/ms754130.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx
Personal experience

bbosak
  • 5,353
  • 7
  • 42
  • 60
2

For platform independent development, I would recommend Qt instead of the current GTK. GTK2 drawing was very slow compared to Qt as well as Win32. If you love native look feel, wxWidgets is made for you.

Vantomex
  • 2,247
  • 5
  • 20
  • 22