Bitmaps and Brushes

A bitmap may be included in a resource file in a similar fashion to icons and resources. The icon, cursor and bitmap that are included in the application of this section are shown below.

An icon
A cursor
A bitmap

An Example of a Resource bitmap, icon and cursor

The program of this section is similar to the program of the previous section except that it paints the background using a brush created out of the bitmap shown above. The output of this program is shown below.

The full source code of the resource specification is shown below.

// win+ -- Resource2.rc -- icon and cursor Demonstration Program no. 2

#include "Resource2.h"

FrameIdentity ICON   "Resource2.ico"
FrameIdentity CURSOR "Resource2.cur"

BitmapLoad BITMAP "Resource2.bmp"

 FrameIdentity, "icon and cursor Demonstration"

In this program, a brush is created from a bitmap and set as the background brush for the class. The main routine is shown below.

// win+ -- Resource2.cpp -- icon and cursor Demonstration Program number 2

import iplusplus;
using namespace core;

#include "Resource2.h"

result __stdcall client(handle,unsigned,parameter,parameter);

const character name[] = "Resource2";

int __stdcall WinMain(handle module_handle,
                     handle Reserved,
                     character* command_line,
                     int show_command)
 window_class<character> wclass;     = class_style::horizointal_redraw | class_style::vertical_redraw;
 wclass.procedure = client;
 wclass.Extra     = 0;
 wclass.window    = 0;
 wclass.module    = module_handle;
 wclass.icon      = load_icon(module_handle,(const character*)FrameIdentity);
 wclass.cursor    = load_cursor(module_handle,(const character*)FrameIdentity);
 handle bitmap   = load_bitmap(module_handle,(const character*)BitmapLoad);
 wclass.brush     = create_pattern_brush(bitmap);
 delete_object(bitmap);      = name;

 atom atom_name = register_class(&wclass);

 handle window_handle = create_window((const character*)atom_name,


 queue_message queue_message;

 return queue_message.parameter1;

The client window procedure then paints the client as follows.

result __stdcall client(handle window_handle,
    unsigned identity,
    parameter parameter1,
    parameter parameter2)

    switch (identity)
    case message::create:
        window_data* data = new window_data();
        set_window_pointer(window_handle, 0, (void*)data);
        data->width_of_icon = get_system_metrics(system_metric::icon_width);
        data->height_of_icon = get_system_metrics(system_metric::icon_height);

    case message::destroy:
        window_data* data = (window_data*)get_window_pointer(window_handle, 0);
        delete_object(set_class_pointer(window_handle, class_offset::background_brush,(handle)null));
        delete data;

    case message::size:
        window_data* data = (window_data*)get_window_pointer(window_handle, 0);
        data->width_of_client = low_part(parameter2);
        data->height_of_client = high_part(parameter2);

    case message::paint:
        window_data* data = (window_data*)get_window_pointer(window_handle, 0);

        paint paint_structure;
        handle device_context = begin_paint(window_handle, &paint_structure);

        handle icon_handle = get_class_pointer(window_handle, class_offset::icon);

        for (int y = data->height_of_icon; y < data->height_of_client; y += 2 * data->height_of_icon)
            for (int x = data->width_of_icon; x < data->width_of_client; x += 2 * data->width_of_icon)
                draw_icon(device_context, x, y, icon_handle);

        end_paint(window_handle, &paint_structure);

    case message::close:

        return default_window_procedure(window_handle, identity, parameter1, parameter2);
    return 0;

During creation, the width and height of an icon is queried. During painting, the width and height of the icon is combined with the width and height of the client to draw a grid of icons against the background of the bitmap brush previously set.