Windows Programming


One of the biggest obstacles to game programming for new programmers is learning to write games that work on the Windows operating system. Windows programming is a huge and complex topic. But don't worry; you'll be able to sidestep most Windows programming issues. The LlamaWorks2D game engine enables you to write games for Windows without having to deal much with the operating system itself.

WinMain()

If you write a Windows program without using the LlamaWorks2D game engine, the first task you'll need to tackle is writing a WinMain() function. In a Windows program, the WinMain() function replaces the normal main() function used in other types of C++ programs. Your WinMain() function must define the type of window that the program uses by creating what is called a window class. Also, it must declare the window class, which is conceptually similar to declaring a variable in a function. Next, WinMain() has to display the window. When the window is on the screen, WinMain() dispatches messages to its message-handling function (more on this in a moment).

Getting all of the WinMain() function's tasks done usually takes a couple of hundred lines of code. Yes, I did say hundred. Every Windows program must go through this sequence of tasks in order to operate. The difference in the code from program to program is really minimal. Most people just write WinMain() once and reuse it in all their different Windows programs with minor variations. However, writing WinMain() isn't easy the first time you do it.

To save you a considerable amount of work, the LlamaWorks2D game engine provides a WinMain() function for you, so you don't have to write it. To set up your Windows program the way you want, you must pass LlamaWorks2D some initialization information that WinMain() uses. I'll show you how to do that in the next chapter. Other than passing in the initialization information, you don't need to do anything to get your game's window set up.

Note

If you want to see what Win-Main() looks like, you can look in the source code for the game engine on the CD. You'll find the WinMain() function in a file called LW2DApp.cpp, which is in the \Tools\LlamaWorks2D folder.


Messages and Message Processing

Windows is based on the idea of passing messages to a program's windows. In fact, everything in Windows is a window. That includes buttons, menus, menu items, sliders, and, of course, windows. Nearly everything in Windows can send or receive messages. As a result, most of Windows programming is learning how to respond to messages. I'll demonstrate techniques for doing this throughout the rest of this book.

Windows messages are generated by events. Most events are a result of the program's interaction with a person. For example, if the program's user clicks an onscreen button or selects a menu item, Windows triggers events. The events generate messages, and your program responds to the messages in a special message-handling function.

LlamaWords2D simplifies the process of handling messages in Windows somewhat. As much as possible, the game engine provides the help and tools you'll need to handle messages. As a result, you'll find that the techniques I demonstrate are remarkably simple when compared with regular Windows programming.



Creating Games in C++(c) A Step-by-Step Guide
Creating Games in C++: A Step-by-Step Guide
ISBN: 0735714347
EAN: 2147483647
Year: N/A
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net