slide1
Download
Skip this Video
Download Presentation
GAM666 – Introduction To Game Programming

Loading in 2 Seconds...

play fullscreen
1 / 13

GAM666 – Introduction To Game Programming - PowerPoint PPT Presentation


  • 179 Views
  • Uploaded on

GAM666 – Introduction To Game Programming. Windows Programming in C++. You must use special libraries (aka APIs – application programming interfaces) to make something other than a text-based program. The C++ choices are: The original Windows SDK (Software Development Kit), a C library

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' GAM666 – Introduction To Game Programming' - alicia


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

GAM666 – Introduction To Game Programming

Windows Programming in C++

You must use special libraries (aka APIs – application programming interfaces) to make something other than a text-based program. The C++ choices are:

  • The original Windows SDK (Software Development Kit), a C library
  • MFC (Microsoft Foundation Classes), a sophisticated wrapper around the Windows SDK
  • ATL (Active Template Library), a light-duty wrapper around the Windows SDK
  • .NET, Microsoft\'s new technology
slide2

GAM666 – Introduction To Game Programming

Why Use the Windows SDK?

  • Games generally take over the whole screen
  • Windows SDK is the simplest route to getting to the point where the screen has been taken over
  • .NET not univerally installed yet
  • We cover MFC/ATL/.NET in other courses
slide3

GAM666 – Introduction To Game Programming

Basic Windows SDK Concepts

  • Write a WinMain(), not a classical main()
  • #include <windows.h> and probably <windowsx.h>
  • Often #define WIN32_LEAN_AND_MEAN before those #includes to cut down on further #includes of rarely used header files
  • Use many #define- and typedef-created data types from those header files (e.g. BOOL, HWND)
  • Use MS-specific declaration modifiers (e.g. WINAPI, CALLBACK) for functions
slide4

GAM666 – Introduction To Game Programming

Basic Windows SDK Concepts

Some Data Types are:

  • BOOL - a boolean value (TRUE or FALSE)
  • HWND - “handle” to a window
  • UINT - unsigned integer (32 bit)
  • WPARAM - “word” parameter (32 bit, originally 16, for passing an integer value, for example)
  • LPARAM - “long” parameter (32 bit, for passing an address, for example)
  • LRESULT - 32 bit return code from a function
  • HINSTANCE - “handle” to a running instance of a program
slide5

GAM666 – Introduction To Game Programming

Messages

  • MS Windows uses Messages to communicate with the windows in a program
  • Every window in a windows program (which includes Controls, which are preprogrammed sub-windows like buttons and list boxes) has a Window Procedure, which is the code to handle any message that may be sent to the window
  • A window is customized by writing a custom window procedure for it, and supplying that procedure\'s address to Windows, which will call the procedure when needed.
slide6

GAM666 – Introduction To Game Programming

Messages

A window procedure is passed four things:

  • An HWND, identifying the window for whom the message is intended
  • A UINT, identifying which message it is
  • A WPARAM, containing a piece of data
  • An LPARAM, containing another piece of data (typically a pointer to more data, but not necessarily)

The WPARAM and LPARAM meaning and usage varies between different messages

slide7

GAM666 – Introduction To Game Programming

Messages

Messages can come from:

  • Windows, based on user interaction or some other operating system activity
  • Another window (in the same program or another)
  • The program code itself, using either SendMessage() (waits until message is handled) or PostMessage() (puts the message on a queue but doesn\'t wait for it to be handled)
slide8

GAM666 – Introduction To Game Programming

Messages

  • Controls (like buttons) have a window procedure that you don\'t see
  • Controls will send a WM_COMMAND message to the parent window when the user interacts with them, its WPARAM identifies the control and the operation
  • Macros LOWORD() and HIWORD() can extract the low- and high-order 16 bits of a WPARAM or LPARAM (or you can do the bit manipulation operations yourself)
slide9

GAM666 – Introduction To Game Programming

Dialogs

  • A Dialog is a pop-up window that typically contains a bunch of controls
  • A dialog can be laid out using a resource file (extension .rc) to describe the controls, rather than creating the controls from within the C++ code
  • A header file is typically used to interlink the C++ code with the resource code by using symbolic names for IDs, since both languages understand the #define and #include syntax
slide10

GAM666 – Introduction To Game Programming

Dialogs

  • A dialog is supplied the address of a Dialog Procedure, which is a window procedure specifically designed to handle a dialog (return value is BOOL rather than LRESULT)
  • Can get the HWND of a control on a dialog using GetDlgItem()
  • Can send a message to a control on a dialog using SendDlgItemMessage() or PostDlgItemMessage() [alternative to calling GetDlgItem() then Send/PostMessage()]
slide11

GAM666 – Introduction To Game Programming

Dialogs

  • WM_INITDIALOG is the ID of the message sent to a dialog just after it is first created, giving you a chance to initialize its controls and do other one-time setup
  • WM_COMMAND is the ID of the message sent to a window when (among other things) one of its controls (ID in low order 16 bits of WPARAM) has something to pass along
  • IDCANCEL is a predefined control ID that corresponds to a user request to close the window
slide12

GAM666 – Introduction To Game Programming

Dialogs

  • Each kind of control has different messages that can be sent to it
  • E.g. CB_GETCURSEL is the ID of the message you send to a ComboBox to get the index of the item in the combobox that is currently selected
  • E.g. LB_ADDSTRING is the ID of the message you send to a ListBox to add another string (passed in the LPARAM) to the listbox
slide13

GAM666 – Introduction To Game Programming

Dialogs

  • Dialogs can be modal (application waits until dialog has been completed) or not (dialog and other application windows can be used at the same time)
  • Modal dialogs can be created by calling DialogBox()
  • Modal dialogs should be terminated by calling EndDialog()
ad