Unit alWin

DescriptionUsesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

Windows specific stuff. Note that this unit compiles only on Windows.

In most cases, a Windows program that uses the Allegro library doesn't need this unit; however, if it also needs to directly call non portable Win32 API functions, it must include this Windows-specific unit.

Windows integration

When creating the main window, Allegro searches the executable for an ICON resource named "allegro_icon". If it is present, Allegro automatically loads it and uses it as its application icon; otherwise, Allegro uses the default IDI_APPLICATION icon. See the manual of your compiler for a method to create an ICON resource, or use the wfixicon utility from the tools/win directory.

DirectX requires that system and video bitmaps (including the screen) be locked before you can draw onto them. This will be done automatically, but you can usually get much better performance by doing it yourself: see the al_acquire_bitmap function for details.

Due to a major oversight in the design of DirectX, there is no way to preserve the contents of video memory when the user switches away from your program. You need to be prepared for the fact that your screen contents, and the contents of any video memory bitmaps, may be destroyed at any point. You can use the al_set_display_switch_callback function to find out when this happens.

On the Windows platform, the only return values for the al_desktop_color_depth function are 8, 16, 24 and 32. This means that 15-bit and 16-bit desktops cannot be differentiated and are both reported as 16-bit desktops. See below for the consequences for windowed and overlay DirectX drivers.

GDI routines

The GDI routines are a very platform specific thing, to allow drawing Allegro memory bitmaps onto a Windows device context. When you want to use this, you'll have to install the neutral system driver (AL_SYSTEM_NONE) or attach Allegro to an external window with al_win_set_window.

There are two ways to draw your Allegro bitmaps to the Windows GDI. When you are using static bitmaps (for example just some pictures loaded from a datafile), you can convert them to DDB (device-dependent bitmaps) with al_convert_bitmap_to_hbitmap and then just use Win32's BitBlt to draw it.

When you are using dynamic bitmaps (for example some things which react to user input), it's better to use al_set_palette_to_hdc and al_blit_to_hdc functions, which work with DIB (device-independent bitmaps).

There are also functions to blit from a device context into an Allegro AL_BITMAP, so you can do things like screen capture.

All the drawing and conversion functions use the current palette as a color conversion table. You can alter the current palette with the al_set_palette_to_hdc or al_select_palette functions. Warning: when the GDI system color palette is explicitly changed, (by another application, for example) the current Allegro palette is not updated along with it!

Overview

Functions and Procedures

FUNCTION AL_DIGI_DIRECTX (CONST n: INTEGER): AL_LONG; INLINE;
FUNCTION AL_DIGI_DIRECTAMX (CONST n: INTEGER): AL_LONG; INLINE;
FUNCTION AL_DIGI_WAVOUTID (CONST HighQuality: BOOLEAN): AL_LONG; INLINE;
FUNCTION AL_MIDI_WIN32 (CONST n: INTEGER): AL_LONG; INLINE;
FUNCTION al_win_get_window: HWND; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_get_window';
PROCEDURE al_win_set_window (wnd: HWND); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_set_window';
PROCEDURE al_win_set_wnd_create_proc (proc: __AL_WIN_CREATE_PROC__); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_set_wnd_create_proc';
PROCEDURE al_win_set_msg_pre_proc (proc: __AL_WIN_MESSAGE_PROC__); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_set_msg_pre_proc';
FUNCTION al_win_get_dc (bmp: AL_BITMAPptr): HDC; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_get_dc';
PROCEDURE al_win_release_dc (bmp: AL_BITMAPptr; dc: HDC); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_release_dc';
PROCEDURE al_set_gdi_color_format; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'set_gdi_color_format';
PROCEDURE al_set_palette_to_hdc (dc: HDC; VAR pal: AL_PALETTE); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'set_palette_to_hdc';
FUNCTION al_convert_palette_to_hpalette (VAR pal: AL_PALETTE): HPALETTE; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'convert_palette_to_hpalette';
PROCEDURE al_convert_hpalette_to_palette (hpal: HPALETTE; VAR pal: AL_PALETTE); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'convert_hpalette_to_palette';
FUNCTION al_convert_bitmap_to_hbitmap (bitmap: AL_BITMAPptr): HBITMAP; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'convert_bitmap_to_hbitmap';
FUNCTION al_convert_hbitmap_to_bitmap (bitmap: HBITMAP): AL_BITMAPptr; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'convert_hbitmap_to_bitmap';
PROCEDURE al_draw_to_hdc (dc: HDC; bitmap: AL_BITMAPptr; x, y: AL_INT); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'draw_to_hdc';
PROCEDURE al_blit_to_hdc (bitmap: AL_BITMAPptr; dc: HDC; src_x, src_y, dest_x, dest_y, w, h: AL_INT); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'blit_to_hdc';
PROCEDURE al_stretch_blit_to_hdc (bitmap: AL_BITMAPptr; dc: HDC; src_x, src_y, src_w, src_h, dest_x, dest_y, dest_w, dest_h: AL_INT); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'stretchblit_to_hdc';
PROCEDURE al_blit_from_hdc (dc: HDC; bitmap: AL_BITMAPptr; src_x, src_y, dest_x, dest_y, w, h: AL_INT); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'blit_from_hdc';
PROCEDURE al_stretch_blit_from_hdc (dc: HDC; bitmap: AL_BITMAPptr; src_x, src_y, src_w, src_h, dest_x, dest_y, dest_w, dest_h: AL_INT); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'stretchblit_from_hdc';

Types

__AL_WIN_CREATE_PROC__ = FUNCTION (p: WNDPROC): HWND; CDECL;
__AL_WIN_MESSAGE_PROC__ = FUNCTION (w: HWND; m: UINT; wp: WPARAM; lp: LPARAM; p: AL_INTptr): AL_INT; CDECL;

Constants

AL_SYSTEM_DIRECTX = $44582020;
AL_GFX_DIRECTX = $44584143;
AL_GFX_DIRECTX_ACCEL = $44584143;
AL_GFX_DIRECTX_SAFE = $44585341;
AL_GFX_DIRECTX_SOFT = $4458534F;
AL_GFX_DIRECTX_WIN = $4458574E;
AL_GFX_DIRECTX_OVL = $44584F56;
AL_GFX_GDI = $47444942;
AL_MIDI_WIN32MAPPER = $5733324D;
AL_JOY_TYPE_DIRECTX = $44582020;
AL_JOY_TYPE_WIN32 = $57333220;

Description

Functions and Procedures

FUNCTION AL_DIGI_DIRECTX (CONST n: INTEGER): AL_LONG; INLINE;

Use DirectSound device n (zero-based) with direct mixing.

See also
al_detect_digi_driver
Detects whether the specified digital sound device is available.
al_install_sound
Initialises the sound module.
al_install_sound_input
FUNCTION AL_DIGI_DIRECTAMX (CONST n: INTEGER): AL_LONG; INLINE;

Use DirectSound device n (zero-based) with Allegro mixing.

See also
al_detect_digi_driver
Detects whether the specified digital sound device is available.
al_install_sound
Initialises the sound module.
al_install_sound_input
FUNCTION AL_DIGI_WAVOUTID (CONST HighQuality: BOOLEAN): AL_LONG; INLINE;

High or low quality WaveOut device.

Parameters
HighQuality
Tells if use high (True) or low (False) quality.
See also
al_detect_digi_driver
Detects whether the specified digital sound device is available.
al_install_sound
Initialises the sound module.
al_install_sound_input
FUNCTION AL_MIDI_WIN32 (CONST n: INTEGER): AL_LONG; INLINE;

Use win32 device n (zero-based)

See also
al_detect_midi_driver
Detects whether the specified MIDI sound device is available.
al_install_sound
Initialises the sound module.
al_install_sound_input
FUNCTION al_win_get_window: HWND; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_get_window';

Retrieves a handle to the window used by Allegro. Note that Allegro uses an underlying window even though you don't set any graphics mode, unless you have installed the neutral system driver (AL_SYSTEM_NONE).

PROCEDURE al_win_set_window (wnd: HWND); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_set_window';

Registers an user-created window to be used by Allegro. This function is meant to be called before initialising the library with al_init or installing the autodetected system driver (AL_SYSTEM_AUTODETECT). It lets you attach Allegro to any already existing window and prevents the library from creating its own, thus leaving you total control over the window; in particular, you are responsible for processing the events as usual (Allegro will automatically monitor a few of them, but will not filter out any of them). You can then use every component of the library (graphics, mouse, keyboard, sound, timers and so on), bearing in mind that some Allegro functions are blocking (e.g. al_readkey) if the key buffer is empty) and thus must be carefully manipulated by the window thread.

However you can also call it after the library has been initialised, provided that no graphics mode is set. In this case the keyboard, mouse, joystick, sound and sound recording modules will be restarted.

Passing Nil instructs Allegro to switch back to its built-in window if an user-created window was registered, or to request a new handle from Windows for its built-in window if this was already in use.

PROCEDURE al_win_set_wnd_create_proc (proc: __AL_WIN_CREATE_PROC__); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_set_wnd_create_proc';

Registers an user-defined procedure to be used by Allegro for creating its window. This function must be called before initializing the library with al_init or installing the autodetected system driver (AL_SYSTEM_AUTODETECT). It lets you customize Allegro's window but only by its creation: unlike with al_win_set_window, you have no control over the window once it has been created (in particular, you are not responsible for processing the events). The registered function will be passed a window procedure (WNDPROC object) that it must make the procedure of the new window of and it must return a handle to the new window. You can then use the full-featured library in the regular way.

PROCEDURE al_win_set_msg_pre_proc (proc: __AL_WIN_MESSAGE_PROC__); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_set_msg_pre_proc';

Set a user callback to be called on window events. This callback function takes the same parameters as a normal window callback procedure plus an additional pointer to an integer. This pointer should be filled with a return value that must be set if the callback has completely processed the window event. If the callback has completely processed the window event, it should return 0 and fill retval with a proper value (the default is zero), otherwise it should return a non-zero value, and event processing will continue in Allegro's default window callback procedure.

FUNCTION al_win_get_dc (bmp: AL_BITMAPptr): HDC; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_get_dc';

Retrieves a handle to the device context of a DirectX video or system bitmap.

See also
al_win_release_dc
Releases a handle to the device context of the bitmap that was previously retrieved with al_win_get_dc.
PROCEDURE al_win_release_dc (bmp: AL_BITMAPptr; dc: HDC); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'win_release_dc';

Releases a handle to the device context of the bitmap that was previously retrieved with al_win_get_dc.

See also
al_win_get_dc
Retrieves a handle to the device context of a DirectX video or system bitmap.
PROCEDURE al_set_gdi_color_format; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'set_gdi_color_format';

Tells Allegro to use the GDI color layout for truecolor images. This is optional, but it will make the conversions work faster. If you are going to call this, you should do it right after initialising Allegro and before creating any graphics.

PROCEDURE al_set_palette_to_hdc (dc: HDC; VAR pal: AL_PALETTE); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'set_palette_to_hdc';

Selects and realizes an Allegro palette on the specified device context.

FUNCTION al_convert_palette_to_hpalette (VAR pal: AL_PALETTE): HPALETTE; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'convert_palette_to_hpalette';

Converts an Allegro palette to a Windows palette and returns a handle to it. You should call DeleteObject when you no longer need it.

See also
al_convert_hpalette_to_palette
Converts a Windows palette to an Allegro palette.
PROCEDURE al_convert_hpalette_to_palette (hpal: HPALETTE; VAR pal: AL_PALETTE); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'convert_hpalette_to_palette';

Converts a Windows palette to an Allegro palette.

See also
al_convert_palette_to_hpalette
Converts an Allegro palette to a Windows palette and returns a handle to it.
FUNCTION al_convert_bitmap_to_hbitmap (bitmap: AL_BITMAPptr): HBITMAP; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'convert_bitmap_to_hbitmap';

Converts an Allegro memory bitmap to a Windows DDB and returns a handle to it. This bitmap uses its own memory, so you can destroy the original bitmap without affecting the converted one. You should call DeleteObject when you no longer need this bitmap.

See also
al_convert_hbitmap_to_bitmap
Creates an Allegro memory bitmap from a Windows DDB.
FUNCTION al_convert_hbitmap_to_bitmap (bitmap: HBITMAP): AL_BITMAPptr; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'convert_hbitmap_to_bitmap';

Creates an Allegro memory bitmap from a Windows DDB.

See also
al_convert_bitmap_to_hbitmap
Converts an Allegro memory bitmap to a Windows DDB and returns a handle to it.
PROCEDURE al_draw_to_hdc (dc: HDC; bitmap: AL_BITMAPptr; x, y: AL_INT); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'draw_to_hdc';

Draws an entire Allegro bitmap to a Windows device context, using the same parameters as the al_draw_sprite procedure.

See also
al_blit_to_hdc
Blits an Allegro memory bitmap to a Windows device context, using the same parameters as the al_blit procedure.
al_stretch_blit_to_hdc
Blits an Allegro memory bitmap to a Windows device context, using the same parameters as the procedure.
al_draw_sprite
Draws a copy of the sprite bitmap onto the destination bitmap at the specified position.
PROCEDURE al_blit_to_hdc (bitmap: AL_BITMAPptr; dc: HDC; src_x, src_y, dest_x, dest_y, w, h: AL_INT); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'blit_to_hdc';

Blits an Allegro memory bitmap to a Windows device context, using the same parameters as the al_blit procedure.

See also
al_draw_to_hdc
Draws an entire Allegro bitmap to a Windows device context, using the same parameters as the al_draw_sprite procedure.
al_stretch_blit_to_hdc
Blits an Allegro memory bitmap to a Windows device context, using the same parameters as the procedure.
al_blit_from_hdc
Blits from a Windows device context to an Allegro memory bitmap, using the same parameters as the al_blit procedure.
al_blit
Copies a rectangular area of the source bitmap to the destination bitmap.
PROCEDURE al_stretch_blit_to_hdc (bitmap: AL_BITMAPptr; dc: HDC; src_x, src_y, src_w, src_h, dest_x, dest_y, dest_w, dest_h: AL_INT); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'stretchblit_to_hdc';

Blits an Allegro memory bitmap to a Windows device context, using the same parameters as the procedure.

See also
al_stretch_blit
Like al_blit, except it can scale images (so the source and destination rectangles don't need to be the same size) and requires the source and destination bitmaps to be of the same color depth.
al_draw_to_hdc
Draws an entire Allegro bitmap to a Windows device context, using the same parameters as the al_draw_sprite procedure.
al_blit_to_hdc
Blits an Allegro memory bitmap to a Windows device context, using the same parameters as the al_blit procedure.
al_stretch_blit_from_hdc
Blits from a Windows device context to an Allegro memory bitmap, using the same parameters as the al_stretch_blit procedure.
al_stretch_blit
Like al_blit, except it can scale images (so the source and destination rectangles don't need to be the same size) and requires the source and destination bitmaps to be of the same color depth.
PROCEDURE al_blit_from_hdc (dc: HDC; bitmap: AL_BITMAPptr; src_x, src_y, dest_x, dest_y, w, h: AL_INT); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'blit_from_hdc';

Blits from a Windows device context to an Allegro memory bitmap, using the same parameters as the al_blit procedure.

See also
al_stretch_blit_from_hdc
Blits from a Windows device context to an Allegro memory bitmap, using the same parameters as the al_stretch_blit procedure.
al_blit_to_hdc
Blits an Allegro memory bitmap to a Windows device context, using the same parameters as the al_blit procedure.
al_blit
Copies a rectangular area of the source bitmap to the destination bitmap.
PROCEDURE al_stretch_blit_from_hdc (dc: HDC; bitmap: AL_BITMAPptr; src_x, src_y, src_w, src_h, dest_x, dest_y, dest_w, dest_h: AL_INT); CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'stretchblit_from_hdc';

Blits from a Windows device context to an Allegro memory bitmap, using the same parameters as the al_stretch_blit procedure. It uses the current Allegro palette and does conversion to this palette, regardless of the current DC palette. So if you are blitting from 8-bit mode, you should first set the DC palette with the al_set_palette_to_hdc procedure.

See also
al_blit_from_hdc
Blits from a Windows device context to an Allegro memory bitmap, using the same parameters as the al_blit procedure.
al_stretch_blit_to_hdc
Blits an Allegro memory bitmap to a Windows device context, using the same parameters as the procedure.
al_stretch_blit
Like al_blit, except it can scale images (so the source and destination rectangles don't need to be the same size) and requires the source and destination bitmaps to be of the same color depth.

Types

__AL_WIN_CREATE_PROC__ = FUNCTION (p: WNDPROC): HWND; CDECL;

See al_win_set_wnd_create_proc.

__AL_WIN_MESSAGE_PROC__ = FUNCTION (w: HWND; m: UINT; wp: WPARAM; lp: LPARAM; p: AL_INTptr): AL_INT; CDECL;

See al_win_set_msg_pre_proc.

Constants

AL_SYSTEM_DIRECTX = $44582020;

DirectX system driver.

See also
al_install
Initialises the Allegro library.
AL_GFX_DIRECTX = $44584143;

Alias for AL_GFX_DIRECTX_ACCEL.

AL_GFX_DIRECTX_ACCEL = $44584143;

The regular fullscreen DirectX driver, running with hardware acceleration enabled.

See also
al_set_gfx_mode
Switches into graphics mode.
AL_GFX_DIRECTX_SAFE = $44585341;

Simplified fullscreen DirectX driver that doesn't support any hardware acceleration, video or system bitmaps, etc.

See also
al_set_gfx_mode
Switches into graphics mode.
AL_GFX_DIRECTX_SOFT = $4458534F;

DirectX fullscreen driver that only uses software drawing, rather than any hardware accelerated features.

See also
al_set_gfx_mode
Switches into graphics mode.
AL_GFX_DIRECTX_WIN = $4458574E;

The regular windowed DirectX driver, running in color conversion mode when the color depth doesn't match that of the Windows desktop. Color conversion is much slower than direct drawing and is not supported between 15-bit and 16-bit color depths. This limitation is needed to work around that of al_desktop_color_depth and allows to select the direct drawing mode in a reliable way on desktops reported as 16-bit.

Note that, mainly for performance reasons, this driver requires the width of the screen to be a multiple of 4. This driver is capable of displaying a hardware cursor, but there are size restrictions. Typically, the cursor image cannot be more than 32x32 pixels.

See also
al_set_gfx_mode
Switches into graphics mode.
AL_GFX_DIRECTX_OVL = $44584F56;

he DirectX overlay driver. It uses special hardware features to run your program in a windowed mode: it doesn't work on all hardware, but performance is excellent on cards that are capable of it. It requires the color depth to be the same as that of the Windows desktop. In light of the limitation of al_desktop_color_depth, the reliable way of setting the overlay driver on desktops reported as 16-bit is:

  IF al_desktop_color_depth = 16 THEN
  BEGIN
    al_set_color_depth (16);
    IF NOT al_set_gfx_mode (AL_GFX_DIRECTX_OVL, 640, 480, 0, 0) THEN
    BEGIN
      al_set_color_depth (15);
      IF NOT al_set_gfx_mode (AL_GFX_DIRECTX_OVL, 640, 480, 0, 0) THEN
      // DirectX overlay driver not supported, so raise an error.
	RAISE Exception.Create ('640x480 overlay driver not supported.');
    END;
  // Ok, the 640x480 overlay driver is running.
  END;

See also
al_set_gfx_mode
Switches into graphics mode.
AL_GFX_GDI = $47444942;

The windowed GDI driver. It is extremely slow, but is guaranteed to work on all hardware, so it can be useful for situations where you want to run in a window and don't care about performance. Note that this driver features a hardware mouse cursor emulation in order to speed up basic mouse operations (like GUI operations).

See also
al_set_gfx_mode
Switches into graphics mode.
AL_MIDI_WIN32MAPPER = $5733324D;

Use win32 MIDI mapper.

See also
al_detect_midi_driver
Detects whether the specified MIDI sound device is available.
al_install_sound
Initialises the sound module.
al_install_sound_input
AL_JOY_TYPE_DIRECTX = $44582020;

Use DirectInput to access the joystick.

See also
al_install_joystick
Installs Allegro's joystick handler, and calibrates the centre position values.
AL_JOY_TYPE_WIN32 = $57333220;

Use the regular Win32 interface rather than DirectInput to access the joystick.

See also
al_install_joystick
Installs Allegro's joystick handler, and calibrates the centre position values.

Generated by PasDoc 0.13.0 on 2016-07-20 12:01:36