In Windows you may include resources in your exe file. These resources are only loaded when needed. There will be only one copy of each resource in RAM.
Here is a simple example for including an icon resource in your exe file:
- Copy the icon #PB_Compiler_Home + "\Examples\Sources\Data\CdPlayer.ico" for example to C:\Temp
- Open Notepad and write "1 Icon C:\Temp\CdPlayer.ico" into the first line
- Type <Enter> at the end of the first line
- Save the file as C:\Temp\Icon.rc and close Notepad
- Open the PureBasic IDE and copy the source code from below into a newly created tab.
- In the menu of the IDE click onto Compiler > Compiler Options...
- Select the tab "Resources"
- At the bottom select the path C:\Temp\Icon.rc
- Click onto "Add" and then onto "OK"
- Now start the example code
After compiling your source code to an exe file you may delete C:\Temp\CdPlayer.ico because this icon is included as a resource in your exe file. Of course normally you shouldn't save the rc file in C:\Temp but in the same folder or a subfolder of your source code file.
In the file path of your rc file you have to take care that
- Hyphens are not allowed
- Each line has to be terminated with a CRLF
You may include many different resources in your rc file like AVIs, Bitmaps, cursors, menu entries, fonts and dialog fields.
Code: Select all
#WindowHeight = 76
#WindowWidth = 230
OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, "Icon contained in resource",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 6, #WindowWidth - 12, #WindowHeight - 12, "", 60)
SetGadgetAttribute(0, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
IconHandle = LoadIcon_(GetModuleHandle_(0), @"#1")
If IconHandle
AddGadgetItem(0, -1, "#1", IconHandle)
EndIf
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend