Can you program a GUI in C++ that works on both Windows and Linux operating systems? - c++

I have been learning C++ for a while now, and so far I love it. But I have been stuck at the console application level. I have built C# programs for a few years so I love having a GUI and not do everything via console.
Console programs when compiled will work on both windows and linux, which is great. When I was searching GUI C++ tutorials I could only find tutorials for windows specific GUI applications.
So my question is this, can you program a GUI in C++ that when compiled with run on both windows and linux? If this is not possible, can someone point me to a great place to learn windows and linux GUI?

I suggest you to use Qt by Nokia:
http://qt.nokia.com/products/
It is free, very powerful, very easy to use, and well designed. And there is also a Visual Studio Add-in available:
http://developer.qt.nokia.com/wiki/QtVSAddin
but you can use their own cross-platform IDE called Qt Creator as well.

You can use wxWidget library.

Yes, you need to use a cross platform GUI toolkit like WxWidgets

gtk and gtkmm http://www.gtkmm.org/en/

Indeed, using cross-platform GUI libraries (like Qt, Gtk, WxWidgets) help you to have the same source code working on Linux and Windows. I recommend Qt if coding in C++.
But there is no way to build an executable working on both systems (unless you use wine to emulate Windows on Linux, which I don't recommend in your case).

Related

c++ gui window cross platform

I would like to make c++ that will work both on Linux and windows as I understand if I use the win32 template in visual studio then it will only work on windows is there something built into c++ like java's jframe that I can use. Also I would like to use any external library at this time.
Here are some cross platform alternatives QT, wxWidgets, Ultimate++. I have used QT, it is intuitive with a huge collection of tools to use in your code. The others are also popular but I have never used them.
I make used of wxWidgets due to it's cross platform and even cross architecture, native look on the OS where it appear. Binary application yields by wxWidgets is small enough thus make it possible to linking statically as portable application. Qt produce huge binary if linked statically (and may be violate qt licensing scheme).
Another reason are licensing flexibly, well documentation and supported by huge community arround the world. wx is considered as mature framework since it first release about 20yrs ago. It's use standard C++ syntax and preprocessor that will make you easily switch from plain C or C++. Complete library are available ranging from appeal window GUI, string, network, stream, webview, xml, and wx is playing very well with 3rd party library as such database SOCI, Asio, etc ....
You may try start to code with wxWidgets easily using Eclipse-IDE and wxFormBuilder as GUI designer. Plese check my experience for ease setup it's IDE+Toolchain. This wx installer can be used do develop, test and run wx application on Linux desktop, and then deploy the binary on Raspberry Pi is available for another board target beside Linux x86_64.
http://yasriady.blogspot.co.id/2016/01/raspberry-pi-toolchain.html
There is a cross-platform application & UI development framework called Qt. I think it meets your requirements. Click here for more info.
There is a long list of both active and dead cross-platform C++ UI libraries here: https://philippegroarke.com/posts/2018/c++_ui_solutions/

Is it possible to create a C++ GUI with Visual Studio?

Can we create C++ GUI applications with Visual Studio or do we need QT like cross platform softwares?
(By the way, I am assuming if I create a GUI with C++ it would be a cross platform application because as far as I know C++ is a cross platform language)
For some of you maybe this is a very obvious question but I couldn't figure out.
The C++ language is cross-platform, but its standard libraries don't provide anything specifically for any GUI development. For that, you need a C++ GUI framework/library. Qt happens to provide just that and it's also cross-platform.
So no, without the use of some cross-platform GUI framework, your application not only won't be cross platform, it simply won't have a GUI at all, since C++ standard libraries don't provide this functionality.
If you use one of the GUI frameworks available only for Windows, like MFC or Windows Runtime, you're not cross-platform.
There are no GUI libraries built directly into c++. Therefore, any GUI you built using c++ would not be cross-platform. There are a couple GUI libraries that come with Visual Studio - MFC and ATL are both fairly common. Neither are cross-platform, however. That doesn't stop you from using some other GUI framework, of course, if you include it. There are plenty to choose from, including ones that are cross-platform.
Just because a language is system-independent, doesn't mean people haven't written frameworks for it that aren't system-independent.
C++ has no standard, built-in GUI library. If you want to make cross-platform GUIs you must use an add-on library like C++, GTKmm, wx, etc.
If you're OK with targeting Windows only, MFC exists and is included with Visual C++.
If You want multi platform application, You should concern using Qt. It makes multi platform development easier by providing API for handling both Windows and Linux (and others). You can use Qt in Visual Studio easily. And is really easy to learn. Check official Qt docs for integration tips.
OK, the point is that qt claims (and prooves) to be platform independent. It shouldn't matter at least if you compile it on a windows platform using either the MinGw GCC or MSVC toolchain.
The difference is, if you use Visual Studio's integrated GUI support, you'll end up with their proprietary, non portable CLR/CLI implementations, and the code won't be portable for other platforms.

Alternate of win32 framework for windowing system on windows

I want to develop a custom window system in c++ that should not depend on win32 library. As an example, Google Chrome has an interface that is not similar to windows own interface. Similarly MPCstar and adobe products have their own interfaces. Please help me where to start for such a project?
You can use cross platform
Qt
or
wxWidgets
but in my opinion Qt is better.
Qt is awesome even if you don't need cross platform support. I assure you after using it you won't understand how anyone could ever develop native GUI on frameworks like Win32 and MFC. Its only shortcoming is the size of the DLLs you'll have to distribute with your app.
BTW is C++ a prerequisite? if not, and you only need windows, use .Net.
I believe Qt should do the trick. I've never used it myself but it is platform independent. I know a few applications that use it, and it seems fine.
Qt and WxWidgets are the better options. And since its GUI I think Qt performs better and has greater support and lots of libraries.
Find Qt here!

Can MFC application run on operating system other than windows?

I need to create a dialog based GUI using VC++/MFC. I am sure it will work with windows OS, but will it work on Linux/Unix or other OS other than windows?
Is QT an alternative good option?
An application written using MFC classes would most probably not work on Linux or Unix, sourcecode-wise. You would have to reimplement most of MFC using X Windows. Qt is a good alternative when the sourcecode has to be used on multiple platforms, e.g. Windows and Linux.
If you just want to run a compiled .exe on Linux, there's the Wine project on Linux that lets you run the application using a "translation layer" that runs on Linux.
No, MFC is for Windows development. I have some vague memory of there being a version of MFC for Solaris or something about 12-15 years ago, but I can't find any information about that now. There is however two other commercial solutions that are supposed to be useful for porting MFC apps to unix:
Mainsoft for UNIX and Linux
Bristol Wind/U (I don't know if this exists anymore though since Bristol was bought by HP a few years ago).
All in all though, if you need an app to run on both Windows and Unix/Linux I'd suggest looking at QT since that's what usually gets recommended for that.

C++ open window hello world

How can you write a C++ program to open a window like this one...
Is it possible or can apps only be ran from the command line?
I'm using the G++ compiler... Do I need something else like visual studio?
Can I do it just by writing code?
Take a look at Qt which is a cross-platform framework that easily builds GUIs.
Then check out a Qt tutorial, do a google search. Here is one that will get you to "hello world"
Also, you might want to check out Code::Blocks as an IDE. It will use your already installed g++ compiler.
You can use Borland C++, Visual C++ they has GUI or wxWindow or GTK library.
GUI programming requires the use of additional libraries. There is a C++ GUI library supplied by Microsoft for Windows called MFC. There are many other GUI libraries out there.
If you use these GUI libraries, you don't need to run the application from the command line.
Search for WinApi Tutorials like this one
there are alot
or you can also you the Visual Studio MFC application wizard and create a dialog application
Microsoft provides a tuturial for doing that:
http://msdn.microsoft.com/en-us/library/bb384843.aspx
The best and most low-level way of doing this would be by using the Windows API:
https://learn.microsoft.com/en-us/windows/win32/learnwin32/learn-to-program-for-windows
Microsoft itself provides excellent tutorials and documentation on how to program with their Windows Application Programming Interface, but there are also numerous other tutorials out there that can be found quickly with a google search.
To create a window like the one you ask about in the question, you would be looking for the following link:
https://learn.microsoft.com/en-us/windows/win32/learnwin32/your-first-windows-program
It might seem daunting at first, but the Windows API is extensive and provides a huge amount of functionality, on top of just creating GUIs. It would probably be worthwhile familiarising yourself with it if you are interested in Windows programming.
You need to use the Windows api from within C++.