Win32 Programming Question

Started by
14 comments, last by Adam Hamilton 17 years, 8 months ago
When you're planning to reuse code, it's a good idea to document it. Some simple comments explaining what exactly a function does can make life easier later on. I see no comments in your code, which means you and I will have to read the low-level code itself to get an understanding of it's purpose.

What I did was commenting every function argument of those Win32 API calls. It might be overkill, but every time I need to get back to that sort of code, it's easy to pick it up again. I don't remember it myself - I let the comments do that for me. The same goes for all code you write, even if you never plan on reusing it. There may come a time you'll need to get back into it because of some obscure bug, and it'll save you time (and frustration) when all you need to read are some comments to understand what each part does. :)
Create-ivity - a game development blog Mouseover for more information.
Advertisement
Thanx for your help guys! Im going to try and make a template/cpp file and whenever i need a window, just including in within the project. Sound good? [smile]
I'm a beginner when it comes to Win32, but my advice would be to learn the code by heart. I too want to learn DirectX, so I started learning Win32 last week, and the method I use is basically memorizing the lines bit by bit. It helps a lot to understand the code too.

For the past week, whenever I had time, I practiced writing the full code to make a window from scratch, and now I can write it without any errors.
Quote:Original post by Darklighter
I'm a beginner when it comes to Win32, but my advice would be to learn the code by heart. I too want to learn DirectX, so I started learning Win32 last week, and the method I use is basically memorizing the lines bit by bit. It helps a lot to understand the code too.

For the past week, whenever I had time, I practiced writing the full code to make a window from scratch, and now I can write it without any errors.

I have to disagree with this. Dont memorize the code, understand it. If you dont remember the members of the WNDCLASSEX structure or how the parameters go for CreateWindowEx(), dont worry - there's a place which can tell you that stuff.
Quote:Original post by Colin Jeanne
I have to disagree with this. Dont memorize the code, understand it. If you dont remember the members of the WNDCLASSEX structure or how the parameters go for CreateWindowEx(), dont worry - there's a place which can tell you that stuff.


I do understand the code though. This is why it's so easy to remember. Also, I don't memorize the parameters for all the functions. If you have Visual Studio, you don't even have to consult the MSDN because it automatically tells you the function prototypes and the WNDCLASSEX members as you type.
I learn Win32 by reading the MSDN on the actual functions I will require most. So many times I see people copying code from something that has worked before and not actually know what the lines of code really do or if they even need it.

How many people stick TranslateMessage before DispatchMessage and never process a WM_CHAR message types.

I memorise everything it takes to write a window but I always understand each line of code that goes into making that window and so I can avoid using redundant code.

Nuclear Rabbit:

This line
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);

you can set to
wc.hbrBackground = NULL;

After all, you probably will clear the viewport in your render function anyway :)

All the best with your Win32 learning.


This topic is closed to new replies.

Advertisement