ID: Q83034
Gdirsrcs.exe is a file in the Microsoft Software Library that demonstrates the following three techniques:
1. Reading a device independent bitmap (DIB) resource from a file and
using that data to create one of the following:
- A device dependent bitmap (DDB)
- A cursor
- An icon
2. Reading a cursor resource from a file and using that data to create
one of the following:
- A device dependent bitmap
- A device independent bitmap
- An icon
- Another cursor
3. Reading an icon resource from a file and using that data to create
one of the following:
- A device dependent bitmap
- A device independent bitmap
- A cursor
- Another icon
The following file is available for download from the Microsoft Software Library:
~ Gdirsrcs.exe (size: 51017 bytes)
For more information about downloading files from the Microsoft Software
Library, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q119591
TITLE : How to Obtain Microsoft Support Files from Online Services
Reading icon and cursor resources from a file is straightforward.
However, reading a device independent bitmap resource from a file is
not so straightforward for the following two reasons:
The process to create a DDB using the information in a DIB is straightforward. Call the CreateBitmap() function to create a bitmap, then read the image data from the DIB into the DDB.
Creating a DDB from a cursor or from an icon is also straightforward. Note that a cursor and an icon each contain two bitmaps (the AND and XOR bit masks) in a DIB. Extract the XOR bit mask and use it to create a DDB.
In the GDIRSRCS sample, the functions that create bitmaps are in the BMP.C file.
In the GDIRSRCS sample, the functions that create cursors are in the CUR.C file.
The procedure to create a cursor based on a DIB obtained from a cursor or icon resource file has eight steps. While the following discussion describes the process of creating a cursor based on a DIB from an icon file, the procedure to create a cursor based on a DIB from another cursor is the same.
1. Obtain a pointer to the bits of the device independent bitmap from
the icon.
2. Divide the height of the DIB by two because the DIB contains both
the AND and XOR masks.
3. Calculate the offset to the AND mask bits.
4. Calculate the offset to the XOR mask bits.
5. Create a device dependent monochrome bitmap with the bits of the
XOR mask.
6. Obtain the contents of the device dependent XOR bit mask and store
it in memory. The AND bit mask is a monochrome bitmap. Because
device independent and device dependent monochrome bitmaps share
the same format, there is no need to convert the AND bit mask.
7. Because the image of a DIB is stored from bottom to top, flip the
scanlines of the AND bit mask.
8. Create a cursor by calling the CreateCursor() function, specifying the
AND and XOR bit masks.
To create a cursor from a bitmap DIB, use the following eight steps:
1. Obtain a handle to the DIB in the bitmap.
2. Call the GetSystemMetrics() function with the SM_CXCURSOR and
SM_CYCURSOR indexes to determine the width and height of cursors
supported by the installed video driver.
3. Change the size of the bitmap to match the size of the system's
cursors.
4. If the bitmap is a color bitmap, convert it to monochrome. (All
cursors are monochrome.)
5. Save the XOR mask bits in memory.
6. Create a monochrome bitmap for the AND bit mask. Fill it with any
desired pattern.
7. Save the AND mask bits in memory.
8. Create a cursor by calling the CreateCursor() function, specifying the
AND and XOR bit masks.
In the GDIRSRCS sample, the functions that create icons are in the ICON.C file.
The process to create an icon from a cursor or from another icon resource file has eight steps. While the following discussion describes the process of creating an icon based on a cursor, the process to create an icon based on another icon is the same.
1. Obtain a pointer to the bits of the DIB in the cursor.
2. Divide the height of the DIB by two because the DIB contains both
the AND and XOR bitmaps.
3. Calculate the offset to the AND mask bits.
4. Calculate the offset to the XOR mask bits.
5. Create a device dependent monochrome bitmap with the bits of the
XOR mask.
6. Obtain the contents of the device dependent XOR bit mask and store
it in memory. The AND bit mask is a monochrome bitmap. Because
device independent and device dependent monochrome bitmaps share
the same format, there is no need to convert the AND bit mask.
7. Because the image of a DIB is stored from bottom to top, flip the
scanlines of the AND bit mask.
8. Create a cursor by calling the CreateCursor() function, and specifying
the AND and XOR bit masks.
To create an icon from a bitmap DIB, use the following seven steps:
1. Obtain a handle to the DIB in the bitmap.
2. Call the GetSystemMetrics() function with the SM_CXICON and SM_CYICON
indexes to determine the width and height of icons supported by the
installed video driver.
3. Change the size of the bitmap to match the size of the system's
icons.
4. Save the XOR mask bits in memory.
5. Create a monochrome bitmap for the AND bit mask. Fill it with any
desired pattern.
6. Save the AND mask bits in memory.
7. Create an icon by calling the CreateIcon() function, and specifying
the AND and XOR bit masks.
Additional query words: softlib GDIRSRCS.EXE
Keywords : kbsample kb16bitonly kbWinOS310 kbWinOS300 GdiCurico
Version : 3.00 3.10
Platform : WINDOWS
Last Reviewed: December 12, 1998