Skip to main content
GameDev.net gamedev.net
🔒 Locked

Beginning Windows Programming

Started by Runicode Oct 26, 2009 at 8:44 PM 10 replies 1.6k views
Original Post
Runicode
Runicode
I'm new to GUI and windows programming, but not new to programming. Can someone recommend an up to date book or two for a beginner to learn some windows GUI programming from the ground up? I am interested in WIN32 and .Net. I'll be using C++. Is there any value in learning WIN32 or is .Net the way to go with Managed C++? Thanks for your help!
Runicode
Runicode
Hmm... everyone speaks so highly of this book, but it's 11 years old. Will it really be useful for a beginner? Any ideas on C++.net?
stupid_programmer
stupid_programmer
Quote:
Original post by Runicode
Hmm... everyone speaks so highly of this book, but it's 11 years old. Will it really be useful for a beginner? Any ideas on C++.net?


Win32 pretty much hasn't changed in 11 years. So yeah if you want the bible on Win32 programming that is the book to get. As long as you have a grasp of C (book uses all C style and not C++) then even a beginner can learn a lot from it. But anymore .NET is the way to go if you want to do basic Windows programming. While you can do .NET with C++/CLI, using C# is probably the easier choice to get things going at a decent pace.
burnthepc
burnthepc
Seconded. Petzold is the way to go.

It's huge, but a great jumping off point into Win32.
jpetrie
jpetrie
Quote:

Hmm... everyone speaks so highly of this book, but it's 11 years old. Will it really be useful for a beginner? Any ideas on C++.net?

You mean "C++/CLI," and you want to stay as far away from that as possible. It's not a beginner-friendly language and its main utility is for building interoperability layers between managed and native code -- as stupid_programmer says, you want to use C# if you're going to write managed code.
Fenrisulvur
Fenrisulvur
Quote:
Original post by Runicode
Can someone recommend an up to date book or two for a beginner to learn some windows GUI programming from the ground up? I am interested in WIN32 and .Net. I'll be using C++. Is there any value in learning WIN32 or is .Net the way to go with Managed C++?

The .NET variant of C++, C++/CLI, is not C++. For more information, read what C++'s creator, Bjarne Stroustrup, has to say on the matter.
Another vote for C#.NET from me if you're planning on doing .NET development, btw, even if Stroustrup disagrees. >_>

As for Win32? theForger should get you started. Like Petzold, though, the language of choice is C.
Runicode
Runicode
So a mastery of C would be required to step through the book and recommended resource? Does anyone know of any resources that focus specifically on C++ & WIN32? I have experience with C++, but not C (I know they're similar) and I'm not sure if that will impact how quick I can learn the material.
nobodynews
nobodynews
I haven't read it, but I really doubt you don't need a 'mastery' of C to learn the Win32 API from the Petzold book. It will probably just use some aspects of the C Standard Library you probably aren't too familiar with and he probably declares all variables at the start of a function block.

What you should try to do is replace the C-style for more C++-style code. Using const variables in place of macros. std::string for strings when possible. If a Win32 function asks for a buffer try to use std::vector for the buffer. If that buffer is for a null terminated string you can then convert the std::vector buffer to a std::string using the C++ Standard Library.

There are also some tutorials on the internet that describe how to create Window classes that may also be of assistance. Oluseyi wrote an article somewhere on gamedev.net that describe how to do this, for instance.
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) ,
Runicode
Runicode
What about MFC, if I read up on MFC would that cover any WIN32 or is MFC on its way out the door? Isn't MFC entirely C++? I guess if I do go with Petzold, I would need approach each section and attempt to understand it from a C++ perspective as you mentioned.
MJP
MJP
Quote:
Original post by Runicode
What about MFC, if I read up on MFC would that cover any WIN32 or is MFC on its way out the door? Isn't MFC entirely C++? I guess if I do go with Petzold, I would need approach each section and attempt to understand it from a C++ perspective as you mentioned.


Yeah MFC is old news. It was released at a time when C++ wasn't even standardized, which led to some "interesting" design choices. Frameworks like Qt or wxWidgets are generally considered to be superior.

As for Win32 with C++, basically everything in raw Win32 can be used with C. So if you want to set the text of a window there's no "Window" class with a "SetText" method, instead you call SetWindowText and pass a handle to your window. This usually means you end up writing a lot of tedious low level code, and at times trying to wrap it in your own C++ class. It's not a path I particularly recommend, unless you're really interested in the low-level mechanics of windows programming.
Fenrisulvur
Fenrisulvur
Quote:
Original post by Runicode
So a mastery of C would be required to step through the book and recommended resource? Does anyone know of any resources that focus specifically on C++ & WIN32? I have experience with C++, but not C (I know they're similar) and I'm not sure if that will impact how quick I can learn the material.

I should mention that you're probably making far too much of the distinction between C and C++. It's going to largely look like C++-minus-classes*, and with char arrays for strings - and you won't have to undertake some sort of arduous transliteration task (though as with any complicated and powerful low-level API, you'll probably end up wanting to encapsulate it into your own library anyway), your compiler probably won't complain about any of the sample code at all.
Just flip through the tutorial I linked above to get an idea of the C involved.

*Despite however many thousand flame wars this statement has sparked. >_>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.