• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Windows Programming: Where to start?

bigfoot150

n00b
Joined
Jan 29, 2006
Messages
5
Hi all. Been a fan of the site for some time now and figured it was finally time to register in the forums.

Anyways, I am a relatively novice programmer. I have taken classes in college programming in C so I do know my way around the command line. The classes i took were typical programming classes starting out with the prerequisite helloworld going all the way to programming binary trees and other various data structures.

To expand my skillset, I want to learn how to do some gui programming with windows. I bought the book Programming Windows by Charles Petzold because I saw it recommended as the best book for the job. I also decided that as a small project I would take one of my command line programs that converted number bases(binary,octal, base10, hex) and do a windowed version. Well, I got thru chap1, chap2, and then somewhere between chap2 and 3 it all turned to greek. My beloved printf was no where to be seen.

At this point, I am thinking that I might be in over my head because it seems like alot of lines of code for a simple window with a line or 2 of text going by the examples in the text. Now the question is, am I going about this the wrong way? Is there a better way?
 
Yeah, win32 code looks more scary than the C/C++ code you've been exposed to.
I have done college programming classes in C and C++ so I know what you're saying.

I remember looking at the source code of a win32 app and did not understand 90% of it.
I'm not too interested in win32 programming but from time to time I do find myself staring at win32 code. I'm sure you will get used to the code you see in the book you're reading now,
as long as you will type the code in yourself and understand what you're writing.
There's a lot of code and a lot of information to learn. Others have done it before, so I'm sure you can do it too :)
 
You can always include stdio.h if you want classic printf style functions but windows includes a few that will get the job done. Most printing functions are prefixed with a w and string functions with an l. So you can do stuff like wsprintf into a buffer then pass that to textout etc with a length of lstrlen(string) etc. If its getting over your head set it down untill you get some project that you want to do that requires a little reading.

I just bought myself that logitech g15 keyboard and it got me to pull out the petzold ebook on the cd to readup on bitmaps a little. In no time I had gdi functions printing on my lcd which I thought was neat, I bet I could get opengl to render on it if I tried. (Althought I couldnt think of a practical reason to do this, lcd visualization maybe?)

As for easier than the raw api, you can try mfc, which wraps c++ classes around the winapi (although I couldnt tell you how much easier it is, as I've yet to buy a book or set aside time to read another book.) You could also try C# which has some c++ windows programming stuff that is a big part of using the language. Im sure other people on this forum could let you know of other languages / methods that may make things easier for ya if you give them time.
 
Thanks for the replys so far.

Also I am going on the cheap and using dev-C++ since i don;t have the resources to get visual studio or something like it. However, I did see microsoft is offering a free download of visual c++ express.
 
In my mind, win32 gui programming is dead. Maybe try MFC(which can be just as awful as win32) or C#. Might as well download C# Express and give that a shot. In my mind, it is the future(with the whole .NET framework) of Windows programming. There will probably be a lot more current tutorials involving C# as well.
 
Whilst you are probebly right with .NET being the future of Windows Development, I am not so sure that theres nessesarily more tutorials for .NET Gui development - it is after all new , whereas GUI Development on C++ has been around for many years.

Having a understanding of GUIs in C++ would be beneficial to moving onto other languages in any event.

You could also look at cross-platform GUI APIs as one other approch.
 
bigfoot150 said:
Also I am going on the cheap and using dev-C++ since i don;t have the resources to get visual studio or something like it. However, I did see microsoft is offering a free download of visual c++ express.

Yep. Once you download it and start using it, I think that you'll find that it's far more robust than Dev-C++.

If you can ask specific questions about what's confusing you, I'll be happy to help answer. Petzold's book is the seminal reference for C-based Win32 API programming without a framework. I've heard he's working on a C# version that covers the framework and WinForms, but I don't know when he plans to publish it.

Thing is, the structure of the current book isn't so great. Chatper 2 is about Unicode, which you might not find incredibly germaine to your project. Chapter 3 and Chapter 4 is where the book gets relevant to your project; you'll want to understand messaging even if you end up going with .NET.

Perhaps part of the problem is that there's many ways to skin the cat: you could come up a few different UI designs for what you're using, and you wouldn't really know which one to choose, or which ones were better, until you already knew a little bit about Windows programming.

Have you thought about how you'd like your UI to look and work?
 
Well I have thought about the UI. Since this is gonna be my first attempt i was gonna go basic and have something like windows calc in scientific view but with just 4 square buttons(instead of radio buttons). Just type the number in and and hit a button for the base you want.

For the most part I understand the concept of what is going on. You draw the first instance of the window and the message loop runs to get incoming info and the window redraws and does other stuff when needed based on what is specified in wndproc.

I believe the part that is really tripping me up is the redrawing and otherstuff going on not too mention how to start throwing in the stuff I really need to make the number conversion work.
 
bigfoot150 said:
Well I have thought about the UI. Since this is gonna be my first attempt i was gonna go basic and have something like windows calc in scientific view but with just 4 square buttons(instead of radio buttons). Just type the number in and and hit a button for the base you want.

That sounds like a pretty decent design for the UI.

But is the user's interaction path really right? Let's think about it a little more. If I understand you, you've got one edit field and four buttons. Each button is for a base; decimal, octal, binary, hex. Right?

These are pushbuttons, then?

So if I start the app, I've got a blank edit field. I type in "3421". Then, I press "Hex".

What happens? Is "3421" assumed to be a decimal value? That is, can I only input decimal? What if I want to start with hex or octal or binary, and covnert it back to decimal? Do you want the user to be able to do that?

bigfoot150 said:
For the most part I understand the concept of what is going on. You draw the first instance of the window and the message loop runs to get incoming info and the window redraws and does other stuff when needed based on what is specified in wndproc.

Yep. Thing is, for this application -- particualrly, given the way you say you'd like to design it, you don't need to do any drawing at all. The edit control and all the buttons will be windows themselves, and they'll be implemented by the User part of the Windows operating system. (See User32.DLL on page 8 of Petzold.)

You'll code the top-level window, sure. When it creates, you'll want to just once create the edit control and pushbuttons, and get 'em positioned in the right place. That's it: whenever the window needs to repaint, it just asks the controls to repaint themselves, and it's done.

You can read about using controls (like the edit and button controls) in Chatper 9 of Petzold. Chatpers 4 through 6 (or so) are about drawing on the screen yourself: drawing lines and writing text, and so on; very directly, at a low level, not reusing any control.

One way to think of designing Windows programs is to go looking for reusable stuff for your UI. Can I express the way I interact with the user in some simple, Windows-supplied controls? Usually, the answer is yes: the user can fill out forms, and so on. No problem!

For other applications, there's no control you can use and you have to draw everything yourself. chapters 4 through 6 are aimed at beginning to understand that kind of app. Unfortunately, nothing comes before chapters 4 thu 6 to help you understand this difference -- any maybe you've died of boredom or frustration before you get to Chatper 9!

bigfoot150 said:
I believe the part that is really tripping me up is the redrawing and otherstuff going on not too mention how to start throwing in the stuff I really need to make the number conversion work.
Well, if you get through Chapter 3 of Petzold, you'll see that your Windows application just sits around and waits for messages. One important message is to quit; other messages tell the application that Windows is requesting something of the program: draw yourself, move yourself, or that the user is movign the mouse around or pressing buttons on the keyboard.

The messages Petzold describes in those first few chapters are about that low-level window management and painting stuff. You'll be interested in WM_INITDIALOG or WM_CREATE, which is the message that tells you your main window is creating. You'll use that message to implement a function that draws the controls you want.

But when the user presses one of the buttons, what happens? A message is sent, of course -- the "Button Look" app from page 362 shows some of the messages. WM_COMMAND can let you know someone pressed a button. So, in response to that message (with the right parameters), you'll want to code a function that gets the number in the text box, converts it however, and then sets the answer back to the text box.

Does that help out?
 
Wow this is very good info. Thanks alot. I now have renewed determination at getting this project up and running. However, regarding the Petzold, would it be a good idea to use it as sort of a reference guide as opposed to reading it straight thru or is that really a matter based on personal preference?



That sounds like a pretty decent design for the UI.

But is the user's interaction path really right? Let's think about it a little more. If I understand you, you've got one edit field and four buttons. Each button is for a base; decimal, octal, binary, hex. Right?

These are pushbuttons, then?

So if I start the app, I've got a blank edit field. I type in "3421". Then, I press "Hex".

What happens? Is "3421" assumed to be a decimal value? That is, can I only input decimal? What if I want to start with hex or octal or binary, and covnert it back to decimal? Do you want the user to be able to do that?

Hmm. I didn't even think of that. Perhaps I should stick with the radio buttons instead. On second thought, I could default to a message that says input a number and then hit the desired base. Once the cursor is moved to the box the message is cleared for the user automatically. Not sure if this would be more difficult than radio buttons though.
 
I went from 0 (HS C++ = useless) to MFC skill(example here, the CCCP Insurgent for the CCCP) using only google and lotsa research, and I'm not even to college yet. With enough studying of example code, and learning the tools you need whilst coding an app, you should be able to learn a hella lot. Using MFC Controls like CEditBox and CButton and their references from MSDN (uber-useful), you should be able to make an efficient GUI app.
 
bigfoot150 said:
Wow this is very good info. Thanks alot. I now have renewed determination at getting this project up and running. However, regarding the Petzold, would it be a good idea to use it as sort of a reference guide as opposed to reading it straight thru or is that really a matter based on personal preference?

As I've said, everyone learns differently. If you're teaching yourself, you shouldn't hesitate to do what feels good instead of following any set pattern. If you're not making progress, ask for help or choose a different path.

I can't imagine reading a book like Petzold's, or even my own, cover-to-cover and in order. Getting started is more about playing with the tools getting comfortable, and looking up the things you don't quite get.

So use it as a reference, sure. But you might also try skipping around and reading through it to figure out what else is there.

bigfoot150 said:
Hmm. I didn't even think of that. Perhaps I should stick with the radio buttons instead. On second thought, I could default to a message that says input a number and then hit the desired base. Once the cursor is moved to the box the message is cleared for the user automatically. Not sure if this would be more difficult than radio buttons though.

I'm not sure I understand the message. So I type "3413", and the message says that I should "hit the desired base". Am I using the button to indicate the base that I've entered, or the base that I want to convert to? You must mean that I hit a button to indicate the source base, then hit another button to indicate my destination base.

I guess that would work, but using radio buttons (like CALC.EXE does) seems more intuitive. If the "Decimal" button is marked, then I must be entering a decimal quantity.

Or, maybe you could enforce some simple parsing. "1134" is decimal, "0x1134" is hex, and "01134" is octal, or something.
 
^^ Doh! I didn't even realize that you needed to tell it what base you are putting in. As a matter of fact in my old command line program required you input the starting base aswell. At this point I think i will stick with the radio buttons.

So at this point, I went ahead and installed VS C++ Express and even went so far as to build a form/window. However, to be honest it was too easy. All i had to do was drag and drop the buttons and textbox. It sorta seems like I cheated. One other thing I noticed, though, was all the source for both the form and the rest of the project seemed to be in C# or more than likely C++. It looked nothing like the code in Petzold. Is this the new(better?) way of programming in windows?
 
bigfoot150 said:
So at this point, I went ahead and installed VS C++ Express and even went so far as to build a form/window. However, to be honest it was too easy. All i had to do was drag and drop the buttons and textbox. It sorta seems like I cheated. One other thing I noticed, though, was all the source for both the form and the rest of the project seemed to be in C# or more than likely C++. It looked nothing like the code in Petzold. Is this the new(better?) way of programming in windows?

At this distance, I can't guess what it is you did. Visual C++ supports numerous project types. You might have made a C# project using WinForms, which results in C# code. You might have made a managed C++ program that uses WinForms. Or, you could've made a native C++ program that uses MFC.

When starting out with a new project, you need to ask Visual C++ for the proper project type. Are you using Visual Studio 2005? If so, here's what I would do to start a Win32 project, where you'll have to do everything by hand:

1) Fire up Visual Studio
2) Use the "Project..." command in the "New" tear-off from the "File" menu
3) Expand the "Visual C++" node in the "Project types" list in the resulting "New Project" dialog
4) Click the "Win32" node under "Visual C++"
5) Select "Win32 Project" from the "Templates" list
6) Name and locate your project by providing a name and a location in the appropriate edit fields.
7) Press "Next" to get past the first step of the Win32 Application Wizard
8) Mark "Windows application" under "Application type".
9) Make sure that neither the "ATL" nor the "MFC" checkboxes are marked
10) Make sure that "Empty project" is not marked in the "Additional options" heading
11) Press "Finish"

The resulting project has a WinMain() implementation that registers a window class, loads a menu for that window class, and so on. It has a message pump, too. I don't think it implements anything else; there's an "About Your App" choice on the menu that brings up an about box.

If you don't even want this much, you can ask for an "Empty project" in step #10 and start completely from scratch.
 
c++ express doesn't have the mfc/atl project templates.

You made a .NET winforms control. If you like it, there are tutorials on how to do stuff with it.

http://samples.gotdotnet.com/QuickS...spx?url=/quickstart/winforms/doc/default.aspx


It's a new way of programming, it's *better* in that it's far less of a learning curve that mfc, and is a way to nicely integrate code in libraries/dlls written in .net to GUI objects.

For now, it's "the" new way of programming... doesn't make it the best or most preferred though :)
 
Back
Top