Writing your own minimalist gui library

I downloaded the source code of DC++ in order to learn C++ from it. If someone does not know it is a p2p file sharing utility. Anyway, while browsing the source I noticed it uses its own library named DWT (based on another library SmartWin) to display window, menu, buttons, etc..

So I decided to go through on the DWT source to harvest knowledge from it, but I find it rather complicated and I am at the point of giving up. So far I gathered some info, like it has classes for:
Application.h - Wraps around the WinMain() function,
Dispatcher.h - handles events, WindowProc
Widgets\*.h - button, listbox, edittext, etc..

All these classes heavily rely on windows api like SendMessage, CreateWindow, RegisterClass, PostQuitMessage, etc... I am familiar with all of these APIs, even I had created gui programs in C using pure windows api, but not in C++. But to be more precise, what I want is not using a libary, I want to create THAT library, not using it. To have an inner look how a gui engine works.

I find DWT's source amazing and something godlike. I think a lots of advanced inspiring stuffs have been put into it (or maybe it just seems advance to me, because I am new to C++), which I will never be able to understand completely, but I would be happy if I could just implement 10% of it on my own. I do not need to implement everything that such a GUI class has to offer, just something very simple basic classes like to create a MainWindow class add a button to it and add a working button->OnClicked() method. I would have been satisfied with just one button, because once you have implemented a button you could add any new widget you want. But again, I find the source code so intimidating all the classes crossreferences each other with templates and multiple inheritances that I just feel lost.

So I wonder how difficult would it be to create a simple gui class with just one widget implemented for demonstration? Is it too big a bite for a beginner? I have seen people - just for demonstrations and learning - creating their own string class (similar to std::string). Is there somewhere... does anyone know a good example of such a GUI example class? (hello world style).
Last edited on
I've worked with such things some, and in a minute I'll post some links to get you started, but first I'd like to tackle some philosophical issues.

I think the ultimate GUI library for Windows is the Win32 C based Api itself, of which you already have some knowledge. When you attack it with C++ Classes, multiple inheritance, templates, i.e., throw the book at it, so to speak, what additional functionalities does it expose? I'll answer that question. An emphatic None!

No wrapper system can expose any more functionality than is provided already by the underlying technology being wrapped. And that's all wrapper libraries do.

Having said that, as programmers we can have all sorts of fun playing with such things as the newest features of C++ and how they can be used to create wrapper libraries around low level C Apis, but don't fool yourself into thinking you are providing additional new functionality. And the downside to it is that you are almost certainly going to create bugs (memory leaks, resource leaks, etc.) not present in the low level C api.

If you really want to play with it, here is some starter material I've posted elsewhere....

http://www.jose.it-berater.org/smfforum/index.php?topic=4409.0

It'll get you started anyway at the cost of having to digest some more of my rantings! :)

My peculiar bent is to kind of go the other way from what you are doing. Instead of complicating things I try to make them simpler. I'm a 'minimalist'. I'm one of those folks you kind of referred to that writes his own libraries - string class and all. I've written my version of the C Standard Library and parts of the C++ Standard Library, and I strictly use the features of the core C++ language and nothing from the C or C++ Standard Libraries. With my system I can create a stand alone 2.5 k x64 GUI program. Linking in my String Class makes it about 3 k. To me, this is more intellectually appealing than creating wrapper libraries which bloat applications created with them into the multi-megabyte size range. But to each his own. Maybe my code will help you get started on your particular brand of madness! :)
Topic archived. No new replies allowed.