Creating Icons, Bitmaps, Images, and Strings (Windows Embedded CE 6.0)
1/6/2010
An icon is an image that used to identify an application, file, or other object. It consists of a bit image combined with a mask. An application icon always appears on the taskbar while the application is running, and it can be used to recover the application main window when another window has the foreground. The icon can also be used to identify the application in the Windows Embedded CE Explorer. Every application should register both 16 by 16 pixel and 32 by 32 pixel icons for its main executable file and the types of files it stores in the file system.
A bitmap is a graphics image that you can include in an application. Unlike icons, which have a fixed size, you determine the bitmap size. Both icons and bitmaps must be defined in a resource file.
To create an icon
Draw the icon by using a graphics application.
Include the icon as a resource in the application resource-definition file.
Call the WM_SETICON message to associate an icon with a window class.
Icons are associated with window classes rather than with individual windows.
Call the WM_GETICON message to retrieve the handle of the icon that is associated with a window class.
Note
Windows Embedded CE does not support any of the standard predefined icons (IDI_*) that Windows-based desktop platforms support.
To create a bitmap
Draw the bitmap by using a graphics application.
Include the bitmap as a resource in the application resource-definition file.
Call the LoadBitmap function to initialize the bitmap.
The bitmap you create with this function will be read-only because Windows Embedded CE does not copy the bitmap into RAM as Windows-based desktop operating systems do.
Call the SelectObject function to select the bitmap into a device context. This enables you to display the bitmap.
When you select the bitmap into a device context, you cannot modify the device context — or example, by drawing text into it — because that would require the ability to write to the bitmap.
The following code example shows how to load a bitmap and display it.
HBITMAP hbm = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP1));
// Clear the window.
InvalidateRect(hWnd, NULL, TRUE);
UpdateWindow(hWnd);
HDC hdc = GetDC(hWnd);
HDC hdcTemp = CreateCompatibleDC(hdc);
SelectObject(hdcTemp, hbm);
// Get the size of the bitmap.
BITMAP bm;
GetObject(hbm, sizeof(BITMAP), &bm );
BitBlt(hdc, 50, 50, bm.bmWidth + 50, bm.bmHeight + 50, hdcTemp, 0, 0, SRCCOPY);
ReleaseDC(hWnd,hdc);
Images and strings are created similarly to icons and bitmaps. Both are resources that must be defined in a resource file. The following code example shows how to define a resource for an icon, bitmap, cursor, and string.
#include "windows.h"
#define IDB_BITMAP 101
#define IDC_CURSOR 102
#define IDI_CEPADICON 103
IDB_CEPADBITMAP BITMAP DISCARDABLE "CePad.bmp"
IDC_CEPADCURSOR CURSOR DISCARDABLE "CePad.cur"
IDI_CEPADICON ICON DISCARDABLE "CePad.ico"
STRINGTABLE DISCARDABLE
BEGIN
1 "CePad"
2 "CePad Application"
END
When adding an image or string to an application, call the LoadImage function to load an image and call the LoadString function to load a string. Windows Embedded CE does not support stretching and shrinking of images or any loading options other than LR_DEFAULTCOLOR. Windows Embedded CE supports only Unicode strings.