Partager via


Using Resources

Other versions of this page are also available for the following:

Windows Mobile Not SupportedWindows Embedded CE Supported

8/28/2008

Resources are objects that are used within an application, but they are defined outside an application. They are added to the executable file when the application is linked. The Windows Embedded CE operating system (OS) resources include menus, keyboard accelerators, dialog boxes, carets, cursors, icons, bitmaps, string-table entries, message-table entries, timers, and user-defined data. The OS design determines available resources.

Resource files have an .rc extension. Text-based resources, such as menus, can be created by using a text editor. Resources such as icons are generated by using a resource editor. Resources created by using a resource editor must be referenced in the .rc file associated with your application. Resource files contain a special resource language, or script, that must be compiled by a resource compiler. The resource compiler converts the .rc file into a resource (.res) file, and then it links the file to the application.

Regardless of how a resource is compiled, you must load resources into memory before you can use them. The FindResource function finds a resource in a module and returns a handle to the binary resource data. The LoadResource function uses the resource handle returned by FindResource to load the resource into memory. After you load a resource by using LoadResource, Windows Embedded CE automatically unloads and reloads the resource as memory conditions and application execution require. Thus, you need not explicitly unload a resource that you no longer need.

The following code example shows how to find a resource and then load the resource.

//Find the resource
HRSRC hrInfo = FindResource(hInst, MAKEINTRESOURCE(IDR_WAVE1), 
                            TEXT("WAVE"));

//Load the resource
HANDLE hr = LoadResource(hInst, hrInfo);

To find and load any type of resource in one call, use the FindResource and LoadResource functions; use these functions only if you must access the binary resource data for subsequent function calls. The following table shows the resource-specific functions you can use.

Function Description

FormatMessage

Loads and formats a message-table entry

LoadAccelerators

Loads an accelerator table

LoadBitmap

Loads a bitmap resource

LoadCursor

Loads a cursor resource

LoadIcon

Loads an icon resource

LoadImage

Loads an icon, cursor, or bitmap

LoadMenu

Loads a menu resource

LoadString

Loads a string-table entry

Before terminating, an application should release the memory that is occupied by accelerator tables, bitmaps, cursors, icons, and menus. The following table shows the functions an application can use to do this.

Resource Release function

Accelerator table

DestroyAcceleratorTable

Bitmap

DeleteObject

Cursor

DestroyCursor

Icon

DestroyIcon

Menu

DestroyMenu

See Also

Concepts

Creating Keyboard Accelerators

Other Resources

GWES Application Development