Hard coding picture on a button

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
esgici
Posts: 4425
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 306 times
Been thanked: 99 times
Contact:

Re: Hard coding picture on a button

Post by esgici » Fri Dec 08, 2017 10:45 pm

edk wrote:
Fri Dec 08, 2017 1:52 pm
Works fine with bitmap, png, gif, jpg, tif
IMHO .ico files not convenient for button images and there is tons of utility (included freeware) to convert images from one type to another (my favorite is IrfanView).

Still may be possible to add .ico type to images types supported by BUTTON control of HMG ( if one of our developers start to do ).

Viva HMG :D
Viva INTERNATIONAL HMG :D

edk
Posts: 285
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 76 times
Been thanked: 225 times

Post by edk » Fri Dec 08, 2017 11:19 pm

esgici wrote:
Fri Dec 08, 2017 10:45 pm

IMHO .ico files not convenient for button images and there is tons of utility (included freeware) to convert images from one type to another (my favorite is IrfanView).

Still may be possible to add .ico type to images types supported by BUTTON control of HMG ( if one of our developers start to do ).

Viva HMG :D
I fully agree with you.
I wrote the post in the context of the problem reported by RPC.
Regards, Edward.

User avatar
esgici
Posts: 4425
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 306 times
Been thanked: 99 times
Contact:

Post by esgici » Sat Dec 09, 2017 12:26 am

But we have a little difference : problem is not BUTTON implementation of HMG, but icon file declared into .rc file; direct definition icon file in BUTTON definition successfully work fine.

Viva HMG :D
Viva INTERNATIONAL HMG :D

User avatar
srvet_claudio
Posts: 2006
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 34 times
Been thanked: 138 times
Contact:

Post by srvet_claudio » Sat Dec 09, 2017 1:21 am

A long time ago, the buttons do not support icons as an image, that happened when all the graphic part of hmg was handled with BT. That was a small price to pay for the advantages (eg bmp, jpg, png, gif, tiff) of unifying the graphics manangement of all controls with BT.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

RPC
Posts: 127
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF
Has thanked: 29 times
Been thanked: 7 times

Post by RPC » Sat Dec 09, 2017 11:40 am

Rathinagiri wrote:
Fri Dec 08, 2017 9:30 am
Can you give a sample project?

The files shall have .ico file for Icons.
Thanks Rathinagiri
My problem is quite simple I want to embed icon/bitmap image in my exe file.
Edwards demo.exe when run on my computer displays both button.bmp and img.png icons (though not img.ico)
I want the same to happen when I run my exe which contains open.bmp file. How can I embed open.bmp file in my exe file ?
I am using form file for my controls.

RPC
Posts: 127
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF
Has thanked: 29 times
Been thanked: 7 times

Post by RPC » Sat Dec 09, 2017 11:59 am

Hi Edward
Thanks for the demo file. You understood my problem. However I still am not able to embed the icon/bitmap image.
I have my controls defined in .fmg file(and not in body of program).
In my fmg file I have ...PICTURE "res\gear.bmp"... and I created a sub-directory 1 level down from where my prg, fmg, hbp etc files are residing, called "res" and put the gear.bmp file there.
When I try to compile the program and run it it shows the gear bitmap image on button , but when I copy the exe to some other place it doesn't show the gear image. In your demo.exe the bitmap and png images are displayed.
Pls advice

edk
Posts: 285
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 76 times
Been thanked: 225 times

Post by edk » Sat Dec 09, 2017 1:52 pm

Hi Rajeev.
It's simple, just look into demo.rc file.
There are defined files, whitch should be embedded in your exe file.
example:

Code: Select all

B1 BITMAP res\BUTTON.BMP
B2 PNG    res\img.PNG
B3 ICON   res\img.ICO
Where:
B1, B2 and B3 are alises of embedded files;
BITMAP, PNG, ICON are types of embedded files;
res\BUTTON.BMP, res\img.PNG, res\img.ICO are files that the compiler will attach to your .exe file.

In the source code file, you can use the aliases of the attached files, ex:
PICTURE "B1" - "B1" alias indicates the embedded file BUTTON.BMP
PICTURE "B2" - "B2" alias indicates the embedded file img.PNG
PICTURE "B3" - "B3" alias indicates the embedded file img.ICO

Make sure that the types are in uppercase, there is case sensitive.

You can check if the files are attached by extracting them from the created exe file, eg using 7-zip.
There should be a ".rsrc" folder with yours files.
Last edited by edk on Sat Dec 09, 2017 1:59 pm, edited 1 time in total.

User avatar
esgici
Posts: 4425
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 306 times
Been thanked: 99 times
Contact:

Post by esgici » Sat Dec 09, 2017 1:58 pm

edk wrote:
Sat Dec 09, 2017 1:52 pm
Hi Rajeev.
It's simple, just look into demo.rc file.
There are defined files, whitch should be embended in your exe file.
example:

Code: Select all

B1 BITMAP res\BUTTON.BMP
B2 PNG    res\img.PNG
B3 ICON   res\img.ICO
Where:
B1, B2 and B3 are alises of embended files;
BITMAP, PNG, ICON are types of embended files;
res\BUTTON.BMP, res\img.PNG, res\img.ICO are files that the compiler will attach to your .exe file.

In the source code file, you can use the aliases of the attached files, ex:
PICTURE "B1" - "B1" alias indicates the emdended file BUTTON.BMP
PICTURE "B2" - "B2" alias indicates the emdended file img.PNG
PICTURE "B3" - "B3" alias indicates the emdended file img.ICO

Make sure that the types are in uppercase, there is case sensitive.

You can check if the files are attached by extracting them from the created exe file, eg using 7-zip.
There should be a ".rsrc" folder with your files.
Thanks Edward

@Rajeev:

A last and small note to add Edward:

name of .rc file should be same as .prg ( in the sample: demo.rc for demo.prg )

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D

edk
Posts: 285
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 76 times
Been thanked: 225 times

Post by edk » Sat Dec 09, 2017 2:01 pm

esgici wrote:
Sat Dec 09, 2017 1:58 pm

@Rajeev:

A last and small note to add Edward:

name of .rc file should be same as .prg ( in the sample: demo.rc for demo.prg )

Happy HMG'ing :D
This is obvious, just like .hpc,. hbp ;)

User avatar
esgici
Posts: 4425
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 306 times
Been thanked: 99 times
Contact:

Post by esgici » Sat Dec 09, 2017 3:51 pm

esgici wrote:name of .rc file should be same as .prg ( in the sample: demo.rc for demo.prg )
Sorry, this is incorrect; correct is:
name of .rc file should be same as .hbp ( in the sample: demo.rc for demo.hbp )
More, this isn't a compulsory; is a easiness gave by HMG.
edk wrote:This is obvious, just like .hpc,. hbp ;)
Also isn't mandatory using .hbp ( Harbour project) and .hbc ( Harbour configuration) file names same as .prg file name; it's also easiness gave by HMG and habits came from HMG samples.

IMHO this and "give name to everything as demo" habit aren't good programming conventions :(

Viva HMG :D
Last edited by esgici on Sat Dec 09, 2017 10:43 pm, edited 2 times in total.
Viva INTERNATIONAL HMG :D

Post Reply