Thursday, July 9, 2009

How can I write a cross-platform GUI in C++?

I intend to write a small application in C++. However, I'm not sure how to code the GUI part of this app. All the tutorials I've looked at introduce C++ programming using the 'Command Prompt' as the interface. So how are applications such as Windows Media Player written? What about Mozilla Firefox; how is this written to support both Windows and UNIX?

How can I write a cross-platform GUI in C++?
You can use the APIs of some widget tools like





wxWidgets


GTK


FLTK


QT





Or you can even use some parts of the mozilla code used to make firefox and thunderbrid etc... I know people from activestate.com did it, but I don't think it's the easiest way. The above ones would be a better choice.





These all provide the same interface in Windows, Unix and Mac, so you only have to write the code once and the api does the rest to try to make it the most similar in all plataforms.





You could also use some interpreted (or semi interpreted) languages instead of C++ like, Java, Python, Perl, and use their respective GUI libraries.





If you really have to do some stuff in C++ you could do some native methods in Java or stuff like that.
Reply:The beauty of using Visual Studio is you can code the different objects in the software using different languages. For instance, you can write a web service in .NET that uses ASP, C#, and VB. It will work cross platforms.
Reply:I had to do something similear couple of times at my work. These are the 2 approaches you can take.





1. Code your logic in C++ and write the client GUI in Java, later you can use JNI to interact between Java and C++ native logic code. That why your GUI will be palform independent.





2. If you are having a Client-server architecture. Then its even better for you.





a) If you are using .NET/IIS , have server in C# and have a Java Applet client or a Java SWING client (with Java WebStart)





b) If you can write your own C++ server, your Java SWING stand-alone client can communicate with your server thru sockets.
Reply:You will have to write the code twice, this is called porting the code. Currently, the only cross platform GUI languages are all interpereted (i.e. Java).


No comments:

Post a Comment