• 0

[C++] Developing Windows applications with forms


Question

I want to develop a (native) Windows application in C++ with forms. Right now I am using CodeBlocks as my IDE. I found this link (http://www.winprog.org/tutorial/) under the thread titled "Newbie C++ Help" but I have heard that the tutorial is not very good (plus, it is in C not C++).

What is the best way to learn how to write C++ Win32 applications with forms? Is there an IDE available that can automate the generation of the code when designing the form?

Edit: Would Visual C++ 6 (before all this .NET crap started) be the best way to go?

Recommended Posts

  • 0

Well the win32 API is in C, so all the code interacting with it will be basic C calls. Of course, you can wrap these calls into a nice OO presentation logic layer, while the application and data access logic can be implemented separately in pure OO. That way if you decide to use a different gui at another time, the interface stays the same, only the presentation logic implementation needs to be reimplemented.

If you know C++, it should be a simple. It's just a matter of working with structs and handles rather than instances of classes.

Alternatively, you could use a widget toolkit like QT, which is very good and easy to use for C++ apps.

  • 0

I understand, I love C++, but can't stand .NET. However, like Joey S said, the win32 API is entirely written in C, and can be used to create very good (and fast!) Windows applications -- if you can figure out how to use it. Although I can properly interface with it now, that is only because I have years of experience. I understand exactly where you are coming from because I was once there myself, reading similar tutorials and getting similarly frustrated.

If you are interested in a very good wrapper for the win32 API that makes it easy to create programs, I recommend SmartWin++. Although it hasn't been updated in many years, it is still one of the best libraries available for creating native Windows GUI applications, at least that I have ever come across. In fact, its architecture lends itself very nicely to additional plug-ins and even new core functionality as Windows evolves and Microsoft adds new features to the API. I have used it for many of my Windows-only programs. So much so that I created my own fork of it which I have added a few new features to, numerous new plug-ins, and support for newer compilers (such as MinGW 4.6 and MSVC 2010).

Although it doesn't quite incorporate ALL of the functionality of SmartWin++, there is a nice WYSIWYG editor for it called SallyIDE. Despite the fact that I don't use it anymore, It was the main reason that I started using SmartWin++, long before I understood most of its advanced functionality. I think that this is exactly what you are looking for. (I have noticed, however, that although it works in Windows Vista and Windows 7, the nice design grid is only displayed when you run it under Windows XP (yuck!).)

To make the whole system work, you will need a compiler; the IDE does not ship with one. If you want to be able to install one and compile out-of-the-box, you should probably choose MinGW. In particular, you want the last release of the 3.x branch (which is version 3.4.5 if I remember correctly). When you add the compiler in SallyIDE, there are several templates with all options preconfigured. Assuming that you installed both MinGW and SmartWin++ in their default locations (C:\MinGW and C:\SmartWin, respectively) then you should have no problems using the MinGW 3.4.5 template with no alterations.

One thing that is very nice about both SallyIDE and SmartWin++ is that both packages ship with very good documentation and lots of examples. From personal experience, examples are the key to understanding. (You will need to look in both SallyIDE and SmartWin++'s installation directories to find the examples, they will not be linked to in the Start Menu or anywhere else.) SmartWin's documentation is also good to have open while viewing examples; it is excellent.

On a side note, please don't use Visual Studio 6. (Where are you going to get a copy of it anymore, anyway?) It is very old, doesn't reflect the current state of the win32 API, and doesn't even properly conform to the C++ standard (nasty hacks are sometimes required to get standards-compliant code, which compiles fine on other contemporary compilers, to work with VC6). However, if you do happen to have a copy of it and enjoy shooting yourself in the foot, it is supported by SmartWin++ and has a template configuration in SallyIDE.

  • 0

You can write native apps using Visual Studio 2010.

.net Isn't mandatory.

The compiler in VS2008 was hugely improved, these changes rolled over to 2010. I've always preferred using VS as my C++ IDE.

EDIT::

I don't understand all the hate for .net. If you don't like the framework, don't use it? Microsoft didn't remove any functionality when it added .net :\

  • 0

I concur with articuno1au that Visual Studio 2008's compiler is leaps and bounds better than anything Microsoft produced before it, and VS 2010 improved on it even further. While I also agree that Visual Studio is a good IDE, coupled with an outstanding debugger, I don't think that the OP was asking specifically if it could support native code, but more how to write native code. Also, correct me if I'm wrong, but I don't believe that Visual Studio has ever included a GUI editor for native win32 applications.

  On 12/12/2011 at 21:39, Joey S said:

Well the win32 API is in C, so all the code interacting with it will be basic C calls. Of course, you can wrap these calls into a nice OO presentation logic layer, while the application and data access logic can be implemented separately in pure OO. That way if you decide to use a different gui at another time, the interface stays the same, only the presentation logic implementation needs to be reimplemented.

If you know C++, it should be a simple. It's just a matter of working with structs and handles rather than instances of classes.

Alternatively, you could use a widget toolkit like QT, which is very good and easy to use for C++ apps.

I agree with this 100%; its solid advice. Especially if I am doing something multi-platform, QT is my toolkit of choice.

  • 0
  On 12/12/2011 at 22:31, xorangekiller said:

Also, correct me if I'm wrong, but I don't believe that Visual Studio has ever included a GUI editor for native win32 applications.

It does, used it myself before. It's by no means as nice as the one for Windows Forms/WPF, but it's there. Last time I used it, it reminded me of Visual Basic - in a good way as designing GUIs with VB was always a joy (compared to other systems).

  • 0
  On 12/12/2011 at 22:31, xorangekiller said:
I don't think that the OP was asking specifically if it could support native code, but more how to write native code.
That's exactly what I was asking.
  • 0
  On 12/12/2011 at 22:34, MFH said:

It does, used it myself before. It's by no means as nice as the one for Windows Forms/WPF, but it's there. Last time I used it, it reminded me of Visual Basic - in a good way as designing GUIs with VB was always a joy (compared to other systems).

I have never used Visual Basic before and I very rarely use Visual Studio, but thanks for the correction. I didn't know it could do that; I will have to try it.

  • 0

I prefer the good old command line to IDE's, but then again, once you've used vim, gcc, automake, and so forth, gui's just slow you down. I hate all that point and click nonsense personally.

  On 12/12/2011 at 22:34, MFH said:

It does, used it myself before.

It's been a long time since I used VS, but isn't that for MFC applications? The OP wants a pure win32 forms app from what I can tell.

  • 0

In other words you're looking for a WYSIWYG editor, like what you'd get if you were developing Winforms or WPF in C#, but would produce C++ code that calls directly into Win32.

As far as I know, that doesn't exist. It'd be a bit contradictory, anyway: if you really need to be programming at that level, you probably don't want generic code made by a tool. Inversely, if you can afford the convenience of an editor, then you probably don't need to program your UI in Win32 directly. So I doubt such a tool exists, because no one needs it.

Why do need to program in C++/Win32 ? If it's just a matter of having to call into some third-party native library, you can do that in pretty much any language, no need for the whole app to be native.

That said, the best free IDE on C++ is Visual C++ Express 2010. Especially in terms of error messages: I don't know if it's gcc in general but the error messages in Code::Blocks can be mind-blowingly verbose.

Visual C++ 6 is completely outdated. It's not even really C++, it has its own bunch of weird rules. Stay well away from it. VC++ gets better with each new version, just use the latest.

  • 0
  On 12/12/2011 at 22:48, Dr_Asik said:

In other words you're looking for a WYSIWYG editor, like what you'd get if you were developing Winforms or WPF in C#, but would produce C++ code that calls directly into Win32.

As far as I know, that doesn't exist. It'd be a bit contradictory, anyway: if you really need to be programming at that level, you probably don't want generic code made by a tool. Inversely, if you can afford the convenience of an editor, then you probably don't need to program your UI in Win32 directly. So I doubt such a tool exists, because no one needs it.

Why do need to program in C++/Win32 ? If it's just a matter of having to call into some third-party native library, you can do that in pretty much any language, no need for the whole app to be native.

Well, I really just want to learn C++ and I find console apps boring :p
  • 0
  On 12/12/2011 at 22:43, Joey S said:

I prefer the good old command line to IDE's, but then again, once you've used vim, gcc, automake, and so forth, gui's just slow you down. I hate all that point and click nonsense personally.

From your first post, I suspected that was where you were coming from. I think your direction is the logical progression of programmers as they become more proficient. The more I have learned, the more I have moved that direction myself. However, neither you nor I started there. The OP is asking for initial direction, not long term goals; those will probably happen on their own anyway. (Not to criticize you, so far I agree with everything you have said in this thread.)

  On 12/12/2011 at 22:50, whitebread said:

Well, I really just want to learn C++ and I find console apps boring :p

I completely understand. This is where I came from as well. Although C++ (especially Microsoft's implementation of a GUI in the win32 API) was hard to master, once I finally got a good handle on it, I found learning other languages much, much easier.

  • 0
  On 12/12/2011 at 22:50, whitebread said:

Well, I really just want to learn C++ and I find console apps boring :p

If that's the case, then I suggest using wxWidgets, QT, or another high level gui toolkit / application framework. That way you can get up and running quickly without getting bogged down in win32 details. As a bonus, your code also becomes much more portable to other platforms like Linux or OS X.

It should be noted though, you won't really learn the ins and outs of C++ by writing gui apps alone. You should start by exploring OO features such as classes, inheritance, polymorphism, operator overloading, as well as the standard template library. I find it's best to start small. But above all, write things that you find fun to do. Make some utility apps that you actually find useful and improve them overtime.

  • 0

Visual C++ (MFC), wxWidgets, QT or CodeGear C++Builder (VCL) if you want to develop native C++ programs with a form designer.

These are all fairy extensive C++ frameworks with a bunch of classes and vary in complexity.

Without using frameworks like these you're stuck doing everything in C using the WinAPI directly.

Out of these the VCL is probably the most mature and easiest to use. The .Net framework itself was designed by some of the people that designed the VCL.

  • 0
  On 12/12/2011 at 22:50, whitebread said:

Well, I really just want to learn C++ and I find console apps boring :p

Then I'd suggest programming something purely graphical (i.e. not Windows GUIs, just graphics - video games and stuff). You don't need to know anything about Win32 for that. Take a look at SFML. It's a general 2D/3D drawing API. It also offers useful functions for sound, timing, networking, maths, etc.

It'd be WAY more interesting and rewarding than trying to learn win32. It's clean, it's easy to use, it lets you do draw whatever you want however you want. It's not a good tool for designing GUIs, but designing GUIs in win32 is a pain in the butt.

To illustrate: here's a complete working C++ app that displays a sprite and allows you to move it around with the arrow keys and rotate it with +/-, using SFML. Doesn't that look fun?

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>

////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
// Load the sprite image from a file
sf::Image Image;
if (!Image.LoadFromFile("sprite.tga"))
return EXIT_FAILURE;
// Create the sprite
sf::Sprite Sprite(Image);
// Change its properties
Sprite.SetColor(sf::Color(0, 255, 255, 128));
Sprite.SetPosition(200.f, 100.f);
Sprite.SetScale(2.f, 2.f);
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Get elapsed time
float ElapsedTime = App.GetFrameTime();
// Move the sprite
if (App.GetInput().IsKeyDown(sf::Key::Left)) Sprite.Move(-100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Right)) Sprite.Move( 100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Up)) Sprite.Move(0, -100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Down)) Sprite.Move(0, 100 * ElapsedTime);
// Rotate the sprite
if (App.GetInput().IsKeyDown(sf::Key::Add)) Sprite.Rotate(- 100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Subtract)) Sprite.Rotate(+ 100 * ElapsedTime);
// Clear screen
App.Clear();
// Display sprite in our window
App.Draw(Sprite);
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}[/CODE]

  • 0

Qt (btw not QT (QuickTime)). Qt is just a wrapper around win32. It is native. It will not look like wxWidgets, or GTK with and ugly non-native look. It comes with a standalone Designer application, which you can even make designer widget plugins of your custom widget, and have it display on the form. You can consider Qt the same as the .NET framework, but it being native. Developing imho is 50x faster than wasting time building the same application in win32, and reinventing the wheel of creating your own api around win32.

  • 0
  On 12/12/2011 at 22:53, xorangekiller said:

From your first post, I suspected that was where you were coming from. I think your direction is the logical progression of programmers as they become more proficient. The more I have learned, the more I have moved that direction myself. However, neither you nor I started there. The OP is asking for initial direction, not long term goals; those will probably happen on their own anyway. (Not to criticize you, so far I agree with everything you have said in this thread.)

I completely understand. This is where I came from as well. Although C++ (especially Microsoft's implementation of a GUI in the win32 API) was hard to master, once I finally got a good handle on it, I found learning other languages much, much easier.

Yes, but you need to learn on point and click.

I program primarily in .net with C#/ASP.net/WPF. I nearly never use the GUI, but it's useful for things where you don't need to customise them at all >.<

For instance: ASP.net authentication I just drag and drop the control in and theme it with CSS. The same approach is useful in WPF for the same reasons :)

It's all preferential anyways. What works for xorangekiller isn't likely to work for a new programmer, and what I use isn't likely to work for anyone because I customise the hell out of VS.

I've always thought that intellisense + addons was VS's greatest strength (and possibly human readable compile errors >.<)

  • 0
  On 12/12/2011 at 23:03, Joey S said:

It should be noted though, you won't really learn the ins and outs of C++ by writing gui apps alone. You should start by exploring OO features such as classes, inheritance, polymorphism, operator overloading, as well as the standard template library. I find it's best to start small. But above all, write things that you find fun to do. Make some utility apps that you actually find useful and improve them overtime.

I agree. This is exactly what you should be doing if you are just starting out. While GUI applications are nice, they don't really teach you the features of the language, in most cases. If you are interested in some simple C++ tutorials that are fairly quick and easy to understand, cprogramming.com has some really nice ones. (Disclaimer: They won't teach you how to write a GUI though, since that is not a standard feature of the language.) If you really want to learn the language well and have a firm grasp on its features and libraries, I highly recommend the book Thinking In C++. It is an excellent resource that taught me much of what I know today about the features of the language. You can get it for free electronically if you don't mind reading it on your computer (or tablet) or you can order it on Amazon if you prefer a physical book.

Don't wait too long to learn your libraries. You will never achieve your full potential as a programmer if you don't know what is available to you. The programmer's adage "Know thy standard library." is very applicable here. The first thing I should have done after learning the language was to delve into the STL and Boost libraries, but I didn't. I would have been able to do much more, more rapidly by knowing what was available.

  • 0
  On 13/12/2011 at 00:15, xorangekiller said:

I agree. This is exactly what you should be doing if you are just starting out. While GUI applications are nice, they don't really teach you the features of the language, in most cases. If you are interested in some simple C++ tutorials that are fairly quick and easy to understand, cprogramming.com has some really nice ones. (Disclaimer: They won't teach you how to write a GUI though, since that is not a standard feature of the language.) If you really want to learn the language well and have a firm grasp on its features and libraries, I highly recommend the book Thinking In C++. It is an excellent resource that taught me much of what I know today about the features of the language. You can get it for free electronically if you don't mind reading it on your computer (or tablet) or you can order it on Amazon if you prefer a physical book.

Don't wait too long to learn your libraries. You will never achieve your full potential as a programmer if you don't know what is available to you. The programmer's adage "Know thy standard library." is very applicable here. The first thing I should have done after learning the language was to delve into the STL and Boost libraries, but I didn't. I would have been able to do more much, more rapidly by know what was available.

Boost is great, if you can actually understand their overly complex documentation on a lot of stuff. It is very powerful and worth learning. I would have to disagree with your choice on Thinking in C++. I would recommend A Guide to Programming in C++. I learn my C++ from it.

  • 0
  On 12/12/2011 at 23:44, articuno1au said:

Yes, but you need to learn on point and click.

I program primarily in .net with C#/ASP.net/WPF. I nearly never use the GUI, but it's useful for things where you don't need to customise them at all >.<

For instance: ASP.net authentication I just drag and drop the control in and theme it with CSS. The same approach is useful in WPF for the same reasons :)

Fair enough. I don't really program too much in Windows anymore (at least with GUI's) and I have never really liked "the Microsoft way". That said, a GUI may be useful for some things, such as your example of ASP.net (which I have never used, and probably never will).

  On 12/12/2011 at 23:44, articuno1au said:

It's all preferential anyways. What works for xorangekiller isn't likely to work for a new programmer, and what I use isn't likely to work for anyone because I customise the hell out of VS.

I completely agree with this. What works for me is not a cookie cutter layout. Every programmer needs to find his stride -- and stick with what works best for him. We are not programmers because we enjoy doing things the way everyone else does them. We are programmers because we enjoy creating new things. If something doesn't work as desired, the average user will either accept it or work around it; the average programmer will try to improve it.

  On 12/12/2011 at 23:44, articuno1au said:

I've always thought that intellisense + addons was VS's greatest strength (and possibly human readable compile errors >.<)

Really? I have always thought that the debugger was its greatest strength. Don't get me wrong, I think that intellisense (and to a lesser extent, the error messages) are great too, but Microsoft really does have a nice debugger. I love GDB, and use it on a regular basis, but there is just something about the ease-of-use of Visual Studio's debugger that is really appealing.

  • 0
  On 12/12/2011 at 21:27, whitebread said:

I want to develop a (native) Windows application in C++ with forms. Right now I am using CodeBlocks as my IDE. I found this link (http://www.winprog.org/tutorial/) under the thread titled "Newbie C++ Help" but I have heard that the tutorial is not very good (plus, it is in C not C++).

What is the best way to learn how to write C++ Win32 applications with forms? Is there an IDE available that can automate the generation of the code when designing the form?

Edit: Would Visual C++ 6 (before all this .NET crap started) be the best way to go?

Visual C++ 6 is obsolete and shouldn't be used. It might be ok for a one-off school project though.

Try Visual Studio Express C++ 2010. It has a built in forms designer, but I can't remember if it needs .NET.

Alternatively, you could try FLTK - Fast Light Toolkit:

http://fltk.org

  • 0
  On 13/12/2011 at 00:35, xorangekiller said:

Really? I have always thought that the debugger was its greatest strength. Don't get me wrong, I think that intellisense (and to a lesser extent, the error messages) are great too, but Microsoft really does have a nice debugger.

Agreed. VC++ isn't a particularly good C++ editor - the syntax coloring is very basic, there are no refactorings, intellisense is flaky - but the debugger is great. The way it lets you look inside templated containers with all the object information - gdb usually just shows me meaningless pointers.
  • 0

I think Microsoft ignored C++ for the last 10 years since .Net came along, and C# started getting all the attention. Hence the lack of good options for C++ Windows development. MFC is really outdated and poor. Plain-C Win32 API is OK, but it's crazy to design GUI programs in plain-C in 2012. Although it's very good for system level programming.

However, I think Microsoft is once again treating C++ as a first class citizen in WinRT. What I don't like is how they are messing with the standard C++ syntax by introducing hat operators etc.

  • 0
  On 13/12/2011 at 05:58, england_fanboy said:
What I don't like is how they are messing with the standard C++ syntax by introducing hat operators etc.
You're referring to C++/CLI, which is a different language. It's not C++. Microsoft did not introduce non-standard features in C++: they created their own language to interface with .NET, while providing a standard C++ implementation as well.
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.