Need help understanding c++ windows for a Java guy [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Thing is I'm learning how develop Win32 applications in C++. I'm using Visual Studio and windows.h and I'm having a bad time.
I come from Java and Android, where you create a class like MainWindow or OptionsWindow and then you write inside the behavior and instantiate them whenever you want.
But now I'm in C++ and I'm lost.
All examples I see with windows.h library are codes where Main is WinMain inside the window. So, here's is my question: Is there any way where you write different classes for different windows and instantiate them when you need it? something like
OptionWindow ow = new OptionWindow
Or should I write all the code of every window I will need inside the WinMain and then make it visible?
Help Is much appreciated. Thanks.

If you are committed to using just C++, I'd recommend creating a C++/MFC Application with VS2013. Microsoft Foundation Classes (MFC) was a framework that hides much of the drudgery of creating and manipulating windows. It is much easier to get started with than raw Win32 programming.
MSDN has a number of tutorials and articles that may help you get started. I also found this reasonable step-by-step guide to MFC programming. If you search for MFC Programming you should find a fair amount of information/code/examples.
Since you are using Visual Studio 2013 one suggestion by commenters isn't applicable to you. There is a suggestion you could use C++/CLI (it is effectively .NET C++). C++/CLI is often a shim that is used as a gateway for C++ developer migrating to C#. Microsoft no longer supports Winforms through the IDE for C++/CLI applications. There is no longer a Winforms application project for C++/CLI either. If you have VS2010 winforms is availale through the IDE.
If you are writing a GUI and don't wish to use MFC with C++ I would recommend jumping to C#. Find a good book on the subject. Microsoft has an online guide that is for Java developers migrating to C#.
Based on the OPs comment that he'd like to do things more programatically. There is a solution that was created by Microsoft and is still maintained by the open source community. That option is Windows Template Library (WTL). I personally still use it for light weight applications where I don't want to overhead of MFC. It is a set of Windows templates that sit a top ATL (Active Template Library). ATL was originally designed as a set of C++ templates to build reusable binary components using COM.
You can add WTL to VS2013 (it is not part of standard Visual Studio anymore). You can download WTL from http://sourceforge.net/projects/wtl/ . Installation is not straight forward but it does work once installed properly.

Winapi uses a plain C interface, so there are no premade classes available.
If you want to write .net Applications in C++ you can use wpf (Windows Presentation Foundation) or winforms as huseyin wrote in his comment.
If you want to develop native win32/64 applications you have to use a library/framework. Microsoft has the MFC (Microsoft Foundation Classes), but IMHO they are complicated and thus don't like them.
You also could have a look at cross-platform frameworks as qt, gtk or wxWidgets. However there you have to take care the license (qt is available as GPL, LGPL or a commercial license, so you either have to buy developer licenses, put your code also under the GPL or comply with the LGPL).

Related

Advantages of Windows API for C++ GUI Programming [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I started C++ programming not long before and I want to learn GUI programming in C++. I looked at windows programming and the syntax looks really difficult. So my question is, should I use windows api at all? If so, what are the advantages of windows api over a toolkit like Qt or Direct2D?
It somewhat depends what sort of application you are trying to build. Most frameworks provide a level of abstraction over the Windows API but do so at the cost of flexibility. You should try and pick a framework that's designed to build the sort of application that you are trying to build.
For building Windows client applications then the Windows API (I assume you mean the Win32 API) will do the job but is very low level. The advantage is it gives you a great deal of control and also forces you to learn how a Windows application really works. For a lot of people these aren't always positives.
If you are trying to create a more graphically rich application then Direct2D gives you this but also means that you have to learn COM and some would say this API is also quite complex.
If you are just learning C++ and want to build simple graphical applications then I would recommend checking out Cinder. It's perfectly possible to build simple graphically rich applications and games in a few hundred lines of C++. Here's an example of the Conway's Game of Life written in a couple of hundred lines.
Qt is also an option but I've not used it. Again it depends on you goal. For example one of Qt's features is cross platform portability, which may, or may not be important if you are just starting out with C++.
If you are just creating some projects for your own learning, then I would suggest that you create some GUI using Windows API without any framework. This will help you learn the internals on how things work (messaging, etc).
But to make any real world project you must choose existing framework (MFC, Qt etc) so that you can save a lot of time. You will understand the framework better if you create some GUI projects with plain Windows API SDK.
If you platform is only Windows, then you can in fact develop faster using .Net Framework. Of course there is also Xamarin that will allow you to write in C# for cross platform.
So what you choose depends on your goals.
With WinAPI you can use all Windows GUI features, controls, styles, respond to some rarely used messages etc.
It's easier to achieve native Windows look&feel.
Higher-lever GUI libraries, especially multiplatform ones, are usually "least common denominator", limited in many ways, with some controls (e.g. dialogs) reinvented just for the sake of it. You can patch your code with WinAPI calls, but that quickly turns into spaghetti.
For one, tools like Qt, OGRE, OSG, OpenGL etc are cross-platform. So you won't be stuck with using your program only on Windows.
If by windows API you meant VC++ with WM_PAINT etc, then it's worth learning it only for the sake of knowledge about how Windows works. The parts about dirty rectangles etc will intrigue you.
"I started C++ programming not long before.." - so I would advise to start with well-documented library such as QT. You'll have much to learn in C++ itself and to learn WinAPI at the same time will be twice (or more) difficult.
The answer in general depends on the requirements, and if you want to learn "GUI programming in C++" I'd say it means QT (or some other library/framework). I do not know any rich GUI projects now which are written on pure WinAPI (what for?). (If smb knows, please put a link here.)
But you can ask yourself another question - you want to learn C++ or GUI programming? :)

What do I need to know before switching from Qt to Visual C++?

I've been using Qt since I started to learn C++. It was the recommended SDK by professor so I didn't try another. Now that I want to learn to use Visual C++, it confuses me what the differences between those two SDKs are. I grew quite comfortable with all the signal and slot stuff of Qt. I wonder if I can find similar functionality in Visual C++. If for any chance, is there any tutorial that teaches you how to work with Visual C++?
Qt is a user interface library written in C++, available on multiple platforms; Visual C++ is a Windows IDE produced by Microsoft. They aren't really comparable -- in fact, I'm pretty sure that, if you felt like it, you could develop an application in Visual C++ which used Qt.
If what you are actually thinking of is the native Windows UI library, that's called MFC (Microsoft Framework Class). It's about 20 years old (!!) now, and contains a lot of historical quirks (including the STRING one which Neel Basu mentioned above); unless you specifically need to learn it, I would strongly recommend that you learn something else instead. If you want to learn one of Windows' native UI libraries, WinForms and WPF are more current, but are based on .NET, not C++. If you want to learn another C++ based UI library, you might want to try out wxWidgets; like Qt, wxWidgets is cross-platform.
Yes there is the Visual C++ help and the MS documentation on MFC and other component frameworks that MS provides

Modern, native way of creating WinAPI GUI apps in C++ [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
First, I know this is kind of common question, but I could not find the exact answer I am looking for.
I have done many projects in Java using Swing. Starting by just coding the GUI, then later moving onto GUI designers. This proved to be a very quick and easy way to build GUI apps.
But now, I need to move to C++. I am beginning a project which uses a lot of HW resources (DirectX, OpenCV, etc...) I know there are Java libraries for these technologies. However, C++ is definitely the right way to go, considering the internals of this project.
I know C and C++ languages well from MCU programming. Also, I have read many articles on native WinAPI programming, Windows internals, etc. I think I have enough knowledge to start. I don´t want to worry much about GUI design, but it must look appropriate.
I know there are few basic options: Pure WinAPI, MFC, WTL, Qt... I would be very glad if there were some kind of GUI designer tool, but from my research, there is not. There is the MFC wizard which helps to create a basic window, but it is not a designer. The closest thing I found was Qt. But from what I read, it is not using WinAPI for drawing, for in future look and feel of Qt written app can differ from native Windows look.
So, to summarize, please, if you are experienced with creating native Windows C++ Apps with GUI, what would you recommend to me? Specifically, is there any tool or designer I missed?
(I am using Visual Studio 2010 professional, since I have it free thanks to the DreamSpark project)
I recently used Qt4 and was very pleased with the API. I found it straightforward, well documented, and the code is extremely concise.
Qt does an extremely good job of emulating the target OS look and feel (as #In silico pointed out in the comments, Qt actually draws everything itself and does not use native components) Regardless, this can be coded by hand or visually through the GUI editor in their IDE, Qt Creator. If you go this route, I recommend creating your initial GUI project (.pro file) there, then importing it into Visual Studio via the Qt Visual Studio Add-In.
Slots and signals, Qt's event/messaging system, is also worth mentioning. Yes, it's critical to GUI programming, but could also be extremely useful in lower-level code.
I expect Qt would work well in your project, but as always, create a few simple tests to ensure the technologies will work together feasibly.
Here are a few hints:
Don't lock yourself into C++. C# and Java (for instance) can be easily interop'ed with C/C++. (Through PInvoke or C++/CLI for the former and JNI for the later). C++ may not be the ideal language to write a GUI quickly.
Your requirement for "native windows look" is arbitrary and you should think it over. Is that really what you need ?
Winforms. It's an older technology but is still widely used. You use the API from C++/CLI or C# (or any .NET) language.
WPF, a more recent API but that will be harder to deal with from C++, (better with C# or VB)
One of the many GUI toolkit available on the market that have a C or C++ API (QT, GTK, wxWidgets, the VCL, ... list here). Some have "native" looks, some don't. Some have designers some don't. Some are free, some aren't.
If you need simple user interface i recommend use WTL - is simple, lightweight, header-only library, very good wrapper over WinAPI. In Visual Studio you can use form designer for creating windows and use WTL classes for implement interaction with user. WTL have poor documentation but WTL is looking like MFC.
If you want rich possibilities i recommend use Qt. It's very powerful GUI framework with great community.
You can use the C++Builder XE2 (Part of the Rad Studio IDE), which includes the VCL (Visual Component Library), the VCL is a wrapper over the Windows controls (and also includes custom controls) which increase the development productivity.
The wxWidgets c++ class library comes with a screen builder.
VCL is a good way to go. It has a GUI designer tool (Embarcadero Rad Studio XE6) fully native gui developer for C++ and Delphi
Depending on how strict your definition is, you could use .NET Windows Forms or Windows Presentation Foundation and plug logic in from C++, C++/CLI, and C#. That would not be a pure C++ solution. In fact, I wouldn't even necessarily advise using C++ in that situation. Simply using C# would be more intuitive and maintainable. WinForms and WPF have pretty awesome GUI designers though.

MFC extension libraries (GUI/Controls) recommendations [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
We're developing/supporting 2 large MFC applications, using VS 2005. Currently, we are looking at various MFC GUI/controls component libraries:
www.bcgsoft.com : "BCGControlBar Pro"
www.codejock.com : "Toolkit Pro"
www.prof-uis.com : "Prof-UIS"
others?
The samples/demos provided for those look all great, and the feature sets seem to match more or less between those libraries.
Has anyone used/reviewed one/more of those?
How is the learning curve?
Advantages/disadvantages?
Toolkit pro seems to be quite popular, id software and Crytek use it for example for their editors. I looked at the BCG once, and the documentation at least was quite bad; didn't have a chance to actually work with the Toolkit pro stuff, but their trial was looking nice.
You could try Visual C++ 2008 Feature Pack available for Visual Studio 2008. It is official part of Visual Studio powered by BCGSoft.
From personal experience: When the need in using Property Grid control have arisen, I've tried BCGSoft solutions, but it was less convenient than using .NET PropertyGrid (through C++/CLI wrapper).
Parts of BCG have been incorporated into MFC in VS2008, so I assume at least Microsoft likes it.
I know one of our products use BCG, and we haven't had any major problems with it. Then again, I rarely work with UI, so I can't really share any first-hand experience.
I used codejock's a couple of years ago. The library was really good, simple to use, good documentation and good, fast support (they even wrote a sample for me to demonstrate what I was asking for.)
I would recommend them, although I have not tried the others you have mentioned.
We're using the new MFC classes from Visual Studio 2008 in a product. Previously we were using BCGControlBar Pro, the conversion to the new MFC classes had to be done by search and replace.
One important thing that BCGControlBar Pro lacks is a resizable layout manager, for this we use a 3rd party codeproject component (which is a pain to use). Codejock has a resizable layout manager.
Another interesting thing that Codejock has is XAML support. Here is their development forum XAML section and (bit dated) XAMLPad like test tool. This would have saved me the time used for creating nice GDI+ gradient buttons (Codejock uses GDI+ for XAML and I had to clone the buttons from a WPF project)
The resizable layout manager and XAML support make "Toolkit Pro" from Codejock a winner in my eyes, even though I haven't used it.
Visual C++ 2008 Feature Pack was included in Visual Studio 2008 SP1. It's not as powerful as BCGControlBar Pro. And it's not for Visual C++ 2005.
Microsoft will provide better official GUI libraries for its Visual C++ and Visual C# products.
I tried both Prof-UIS freeware and BCGControlBar Pro. Prof-UIS is slower than BCGControlBar Pro, but it's easier to use.
Another vendor:
http://www.prof-uis.com
Prof-UIS is an easy-to-use MFC extension library that enables you to deliver Windows applications with a professional and user-friendly interface. More than 200 thoroughly tested and documented C++ classes,

Which Windows GUI system should I choose with C++? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
There are now so many ways to write windows apps, win32, MFC, ATL, .NET, WinForms, and probably some others that I don't know of. Which one should I choose? I'd like one that works on a fresh install of Vista, and is modern and easy to use.
I highly recommend Qt. It's cross-platform, very easy to use and LGPL licensed.
If you are amateur with C++ you'll have much easier time learning WinForms than any of the native Visual C++ frameworks (Win32, MVC, etc.). WPF will give you best versatily. It's a bit harder to master than WinForms but managed and so keeps you away from the nasty Win32 stuff.
The native frameworks are good mainly if you want to crunch the last bits of performance or need to keep the footprint small for stuff such as shell extensions.
I'd recommend checking WinForms at least first to get some quick understanding of the principles. If WinForms doesn't suit you, you can then move to either C++ if you feel you need more low level control or WPF if you wish more shiny features like skinning and theming.
Edit:
Though if you have a look at WPF, remember that fresh Vista contains only .Net 3.0 so 3.5 and 3.5 SP1 features require a separate runtime installation.
actuallly it's very easy to start with Qt - you get a complete SDK incl. a very nice IDE as a simple package and a smart integration into VisualStudio.
Plus the LGPL licensing which allows anybody to write opensource and closed source/commercial apps without paying any fees - the commercial support/licenses are optionally!
The biggest advantage of Qt is the very easy to learn and very very clean C++ API, which can do more than just building GUI apps (it supports low leven networking and file io etc.).
Best regards,
Chris
Short answer... It depends.
Whats your skillset/background? Why are you developing a desktop app? Is it for work or as an experiment for you to learn something new? Will there be multiple other developers working on it and whats they're skillset?
My personal preference would be winforms because that's what I spend most time coding in (in C#). They're very quick to put together and the VS IDE is very quick & stable for building the UI elements of your application. And you can publish/deploy them using Click Once which allows easy updating of the clients when you make changes & updates.
Alternatively, you might want to look at WPF which is the new Presentation Foundation in .NET 3.5. This will allow you to leverage a newer "shinier" UI experience for desktop applications.
Straight up Win32 is getting better with the Scenic Ribbon. Will work on Vista and Windows 7.
I'm probably biased (aren't we all?), but since your question states you're interested in Windows development and you want a modern and easy to use GUI framework that's works with Vista out of the box, the obvious answer is .NET WinForms.
I personally prefer gtkmm. Although it doesn't look as good as Qt or the native frameworks on Windows, I think the API is the most transparent among all frameworks I tried. It feels very OOish, and is very easy to learn. You can easily create GUI layouts with Glade, but you can also create decent designs with nothing but code. In this regard, gtkmm is similar to Java GUI programming.
I would recommend WxWidgets. The API is easy to understand; it is very well documented with samples; and it is cross-platform. If you are programming an application that is going to have any a large number of users, you will eventually want to have the option of running it on a different operating system. By choosing a Microsoft only API you will permanently put yourself into the Microsoft corner. Getting out will require a serious refactoring of your software which will require that you learn yet another API. Take my advice and start with a cross-platform API - it will save you a lot of grief in the future.
I would recommend C++Builder 2009, which can create applications that work with Windows 2000, XP and Vista.
If you go the Microsoft route, be sure to check which frameworks they are putting the most muscle behind lately. For instance, MFC is an older framework that should NOT be used for new development because MS isn't putting any time into it, and the marketplace for add-on MFC components has dried up and blown away.
Basically, when choosing MS backed technology, make sure you pick one that isn't already on the outs.
So you're a student with only PHP knowledge? Well before even considering a GUI you'll need to come up to speed in a proper language. I would suggest C# as you are already used to curly braces and you want to program Windows. WinForms is part of .Net, not a separate thing. Just download Visual Studio 2008 Express and you're up and running. By the way, GUI programming can be hard in any language, especially after you move past the stage of toy programs to real apps.
If you knew C++ to a higher degree I would have suggested Qt. Simply because the new LGPL licensing removes the final impediment. It's also cross-platform, high quality, high performance and now has the financial backing of a huge company (Nokia) to ensure further development.