Embedded Compiled Resource file to Compiled Exe

Windows specific forum
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Embedded Compiled Resource file to Compiled Exe

Post by Shardik »

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):

Code: Select all

1 ICON C:\Temp\CDPlayer.Ico
4. Save this file
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
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.
Last edited by Shardik on Fri Nov 12, 2010 10:58 am, edited 1 time in total.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Embedded Compiled Resource file to Compiled Exe

Post by ts-soft »

Why OpenLibrary? Simple use: GetModuleHandle_(0)
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Embedded Compiled Resource file to Compiled Exe

Post by Shardik »

ts-soft wrote:Why OpenLibrary? Simple use: GetModuleHandle_(0)
You are right, Thomas. GetModuleHandle_(0) is shorter because OpenLibrary()
isn't necessary anymore. I have updated my above code example. I had used
one of my older examples. My newer ones are aready using GetModuleHandle_(0) :oops:

Thank you for your hint. :wink:
Peyman
Enthusiast
Enthusiast
Posts: 203
Joined: Mon Dec 24, 2007 4:15 pm
Location: Iran

Re: Embedded Compiled Resource file to Compiled Exe

Post by Peyman »

thanks ts-soft and Shardik, but i want embedded a compiled resource file to a Compiled exe, first i want create my exe then embedded my compiled resource to it.
Sorry for my bad english.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Embedded Compiled Resource file to Compiled Exe

Post by ts-soft »

You can use Resource Hacker
Peyman
Enthusiast
Enthusiast
Posts: 203
Joined: Mon Dec 24, 2007 4:15 pm
Location: Iran

Re: Embedded Compiled Resource file to Compiled Exe

Post by Peyman »

thanks it works, i can use it like this :

Code: Select all

ResHacker.exe -addskip myExe.exe, myExe.exe, Myresource.res ,,,
its work but anybody know a command line program that just do this job ?
Sorry for my bad english.
Post Reply