Page 1 of 1

Re: Embedded Compiled Resource file to Compiled Exe

Posted: Fri Nov 12, 2010 10:15 am
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.

Re: Embedded Compiled Resource file to Compiled Exe

Posted: Fri Nov 12, 2010 10:46 am
by ts-soft
Why OpenLibrary? Simple use: GetModuleHandle_(0)

Re: Embedded Compiled Resource file to Compiled Exe

Posted: Fri Nov 12, 2010 10:57 am
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:

Re: Embedded Compiled Resource file to Compiled Exe

Posted: Fri Nov 12, 2010 1:34 pm
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.

Re: Embedded Compiled Resource file to Compiled Exe

Posted: Fri Nov 12, 2010 2:37 pm
by ts-soft
You can use Resource Hacker

Re: Embedded Compiled Resource file to Compiled Exe

Posted: Fri Nov 12, 2010 5:01 pm
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 ?