Page 1 of 1

icon from a .RC file

Posted: Thu Nov 14, 2024 8:26 pm
by Natter
Is it possible to save an icon from a .RC file to a file ?

Re: icon from a .RC file

Posted: Thu Nov 14, 2024 9:25 pm
by Antonio Linares
You can save it from a RES file but you can't save it from a RC file as you only have the icon name there.

The RES file does include the icon contents.

Re: icon from a .RC file

Posted: Fri Nov 15, 2024 8:34 am
by Natter
Sorry, Antonio, I wrote it wrong. Of course I meant the RES file :(

Re: icon from a .RC file

Posted: Fri Nov 15, 2024 1:15 pm
by Antonio Linares
Simply open the RES file with a resources editor and save the icon file

Re: icon from a .RC file

Posted: Fri Nov 15, 2024 4:20 pm
by Natter
I guess I didn't ask the question well. :( I compiled .prg and .rc into a single .exe In some situation I need to save one of the resources (icon) to a bitmap file from the program.

Re: icon from a .RC file

Posted: Fri Nov 15, 2024 10:24 pm
by Antonio Linares
Open the EXE with the resources editor and save the icon

Re: icon from a .RC file

Posted: Sat Nov 16, 2024 2:20 am
by nageswaragunupudi
If you want to save an Icon resource to an icon file "filename.ico"

Code: Select all | Expand

hIcon := LoadIcon( GetResources(), cResIcoName )
FW_SaveHIconToIco( hIcon, "name.ico" )
If you want to save any image resource to a file of the same type or different type:
Ex. Save bmp resource as bmp file.

Code: Select all | Expand

FW_SaveImage( BmpResourceName, "name.bmp" )
Ex. Save bmp resource as PNG file.

Code: Select all | Expand

FW_SaveImage( BmpResourceName, "name.png" )
This reads bitmap image from the resource, converts to png image and saves as png image.

Re: icon from a .RC file

Posted: Sat Nov 16, 2024 3:28 am
by nageswaragunupudi
Sample:

Using this rc file:
"saveres.rc"

Code: Select all | Expand

BOOKSICO ICON "..\icons\books.ico"
CHARTICO ICON "..\icons\chart.ico"
USERSICO ICON "..\icons\users.ico"
SEA   BITMAP "..\bitmaps\sea.bmp"
OLGA  10  "..\bitmaps\olga1.jpg"
build and run this sample program in the fwh\samples folder:

"saveres.prg"

Code: Select all | Expand

#include "fivewin.ch"

function Main()

   local oWnd, oIco, oBar, oBtn

   DEFINE ICON oIco RESOURCE "BOOKSICO"
   DEFINE WINDOW oWnd ICON oIco SIZE 600,400 PIXEL
   DEFINE BUTTONBAR oBar SIZE 140,30 2007

   DEFINE BUTTON OF oBar PROMPT "OLGA.JPG->PNG" CENTER ACTION ( ;
      FW_SaveImage( "OLGA", "olga.png" ), XImage( "olga.png" ) )

   DEFINE BUTTON OF oBar PROMPT "SEA.BMP->JPG" CENTER ACTION ( ;
      FW_SaveImage( "SEA", "sea.jpg", 100 ), XImage( "sea.jpg" ) )

   DEFINE BUTTON OF oBar PROMPT "SAVE-ICO" CENTER ACTION ( ;
      FW_SaveHIconToIco( LoadIcon( GetResources(), "BOOKSICO" ), "books2.ico" ), ;
      XImage( "books2.ico" ) )

   ACTIVATE WINDOW oWnd CENTERED

return nil

Re: icon from a .RC file

Posted: Sat Nov 16, 2024 6:13 pm
by Natter
Thank you ! That's just what I need.