11.1.1 Finding and Loading Resources
To use a resource, your application must find the resource and load it into memory. The FindResource and FindResourceEx functions find a resource in a module and return a handle to the binary resource data. The FindResource function locates the resource by type and name; FindResourceEx locates the resource by type, name, and language.
The LoadResource function uses the resource handle returned by FindResource or FindResourceEx to load the resource into global memory. An application does not need to unload the resource when it is no longer needed. After an application loads a resource with the LoadResource function, Windows automatically unloads and reloads the resource as memory conditions and application execution demand.
You should not use FindResource, FindResourceEx, or LoadResource on cursor, icon, string, or message-string resources, unless you need access to the binary resource data. These resources have specialized functions that find and load the resource for use in an application:
LoadCursor |
Loads a cursor resource |
LoadIcon |
Loads an icon resource |
LoadString |
Loads a string-table entry |
FormatMessage |
Loads and formats a message-table entry |
You can use FindResource, FindResourceEx, and LoadResource on any type of resource, although the following functions find and load an accelerator table, bitmap, or menu in one call:
LoadAccelerators |
Loads an accelerator table |
LoadBitmap |
Loads a bitmap resource |
LoadMenu |
Loads a menu resource |
Before terminating, you should release the memory occupied by accelerator tables, bitmaps, cursors, icons, and menus. The following functions perform these tasks:
Resource |
Release Function |
accelerator table |
DestroyAcceleratorTable |
bitmap |
DeleteObject |
cursor |
DestroyCursor |
icon |
DestroyIcon |
menu |
DestroyMenu |