Re: Embedded Compiled Resource file to Compiled Exe
Posted: Fri Nov 12, 2010 10:15 am
An example which loads an icon from a resource and displays it in a window:
1. Copy an icon (for example C:\Programs\PureBasic\Examples\Data\CDPlayer.Ico) to a temporary directory (for example C:\Temp)
2. Open Notepad and create a new file, for example C:\Temp\Resources.RC
3. Resources.RC should contain the following line (terminated with Return):4. Save this file
5. Copy the following code into your IDE:6. Open "Compiler" / "Compiler Options..." in the title menu of the IDE
7. Select the tab "Resources"
8. Click onto the button "..." at the bottom above the Cancel button
9. Select the file Resources.RC in the folder C:\Temp
10. Click onto the Add button (the file "C:\Temp\Resources.RC" should be displayed in the list now)
11. Click onto OK
12. Run the program and the CDPlayer icon should be loaded from your resource and be displayed in a window.
1. Copy an icon (for example C:\Programs\PureBasic\Examples\Data\CDPlayer.Ico) to a temporary directory (for example C:\Temp)
2. Open Notepad and create a new file, for example C:\Temp\Resources.RC
3. Resources.RC should contain the following line (terminated with Return):
Code: Select all
1 ICON C:\Temp\CDPlayer.Ico
5. Copy the following code into your IDE:
Code: Select all
#WindowHeight = 72
#WindowWidth = 220
If FindResource_(GetModuleHandle_(0), 1, #RT_ICON) <> 0
If 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
EndIf
EndIf
7. Select the tab "Resources"
8. Click onto the button "..." at the bottom above the Cancel button
9. Select the file Resources.RC in the folder C:\Temp
10. Click onto the Add button (the file "C:\Temp\Resources.RC" should be displayed in the list now)
11. Click onto OK
12. Run the program and the CDPlayer icon should be loaded from your resource and be displayed in a window.