Programmer's Reference

Loading icons from DLLs

On Windows and OS/2 platforms, CgIcons can be loaded from an icon resource linked into the virtual machine (VM) executable or another file. A platform-specific resource specifier object is used to identify the icon resource.

On OS/2, only integers are used as resource specifiers. On Windows, resource specifiers can be either strings (as in the previous example) or integers.

The following code illustrates how to load an icon resource from the VM executable on the Windows platform. Do this using the fromResource: class method:

| icon |
icon := CgIcon fromResource: 'APP_ICON'.
CgWindow default
    drawIcon: CgGC default x: 0 y: 0 icon: icon.
icon freeIcon

The equivalent code for OS/2 is as follows:

| icon |
icon := CgIcon fromResource: 1.
CgWindow default
    drawIcon: CgGC default x: 0 y: 0 icon: icon.
icon freeIcon

To load an icon resource from a file other than the VM executable, use the fromResource:fileName: class method of CgIcon. The following examples load an icon from the VM executable, as above, but the file name is explicitly specified:

"Windows"
| icon |
icon := CgIcon
    fromResource: 'APP_ICON' fileName: 'abt.exe'.
CgWindow default
    drawIcon: CgGC default x: 0 y: 0 icon: icon.
icon freeIcon
 
"OS/2"
| icon |
icon := CgIcon
    fromResource: 1 fileName: 'abt.exe'.
CgWindow default
    drawIcon: CgGC default x: 0 y: 0 icon: icon.
icon freeIcon


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]