A Sample Application: Bitmap

This sample shows how to incorporate a variety of bitmap operations in an application. In particular, it shows how to do the following:

Load and display a monochrome bitmap

Create and display a color bitmap

Stretch and compress a bitmap using the mouse

Set the stretching mode

Create and use a pattern brush

Use a pattern brush for the window background

In this application, the user specifies (by using the mouse) where and how the bitmap will be displayed. If the user drags the mouse while holding down the left button, and then releases that button, the application uses the StretchBlt function to fill the selected rectangle with the current bitmap. If the user clicks the right button, the application uses the BitBlt function to display the bitmap.

To create the Bitmap application, copy and rename the source files for the Generic application, then make the following modifications:

1.Add constant definitions and a function declaration to the include file.

2.Add two monochrome bitmaps, created by using Image Editor, to the resource script file.

3.Add Bitmap, Pattern, and Mode menus to the resource script file.

4.Add global and local variables.

5.Add the WM_CREATE case to the window function to create bitmaps and add bitmaps to the menus.

6.Modify the WM_DESTROY case in the window function to delete bitmaps.

7.Add the WM_LBUTTONUP, WM_MOUSEMOVE, and WM_LBUTTONDOWN cases to the window function to create a selection rectangle and display bitmaps.

8.Add the WM_RBUTTONUP case to the window function to display bitmaps.

9.Add the WM_ERASEBKGND case to the window function to erase the client area.

10.Modify the WM_COMMAND case to support the menus.

11.Add the SELECT.LIB library file to the project.

12.Build and run the application.

NOTE:

Rather than typing the code presented in the following sections, you might find it more convenient to simply examine and build the sample source files provided on the sample disks.

The following sections explain each step in detail.