Using Resources (Windows CE 5.0)

Windows CE 5.0
Send Feedback

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 Microsoft® Windows® 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 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), 

//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.

FormatMessageLoads and formats a message-table entry
LoadAcceleratorsLoads an accelerator table
LoadBitmapLoads a bitmap resource
LoadCursorLoads a cursor resource
LoadIconLoads an icon resource
LoadImageLoads an icon, cursor, or bitmap
LoadMenuLoads a menu resource
LoadStringLoads 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.

ResourceRelease function
Accelerator tableDestroyAcceleratorTable

See Also

GWES Application Development

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.