HMG4: image icon resource file

Moderator: Rathinagiri

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

HMG4: image icon resource file

Post by l3whmg »

Hello everyone,

I'm :D because I found a possible solution to the problem of the icons and images.
Before exposure to you, I say that is strongly linked to the current versions of the Harbour compiler and the Qt library.
In fact, reading the documentation, I found the words "at present" especially on the Qt library and therefore binding.

Abstract:
pay close attention to the presence of qt.conf file in the directory of the executable program. Example:
[Paths]
plugins=../qt/plugins
plugins directory structure:
...plugins\imageformats\qgif4.dll
...plugins\imageformats\qico4.dll
...plugins\imageformats\qjpeg4.dll
...plugins\imageformats\qmng4.dll
...plugins\imageformats\qsvg4.dll
...plugins\imageformats\qtiff4.dll
Materials needed:
- Of course the library HMG4 :mrgreen:
- The full distribution of the Harbour compiler latest version, because (my solution) includes the use of compiler rcc.exe

Optional Material:
- The full distribution of the MinGW compiler
Note: If you have any problem at compile time, you may need the full distribution

As indicated in the documentation of QT website, to assign the icon to the program (Windows Explorer level) is still necessary to use the compiler windres.

A) How to assign the icon to the program (windows explorer level - probably, you already use a similar method):
A.1) Create a file <iconfilename>.rc:

Code: Select all

DEFAULT     ICON   <pathname/><icon-name>.ico
Note:
<iconfilename> is the name of the file .rc
<pathname/> is the directory where the icon file exist (optional, depending on your organization)
<icon-name> s the physical name of the image file

A.2) Compile the program with Harbour (the other options you already know):
HBMK2 %1 <iconfilename>.rc .....
B) How to create the resources file
Attention: if the source window.prg of the library HMG4, does NOT include the statement ":oQTObject:setWindowIcon()" you can not see the icon in the title bar of the window.

B.1) Create a file <resourcesfilename>.qrc (warning: .qrc):
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file alias="MYLOGO"><pathname\>l3w_logo.ico</file>
<file alias="L3W_IEXIT"><pathname\>exit.png</file>
<file alias="L3W_ISAVE"><pathname\>save.png</file>
</qresource>
</RCC>
Note:
<resourcesfilename> is the name of the file .qrc
<pathname/> is the directory where the images/icons files exists (optional, depending on your organization)

Warning: using the syntax alias="name", allows us to refer to the image with alias instead of the file name. Exactly like in the .rc file.
Just make sure that, using this syntax, we will have to use ":MYLOGO" instead of "MYLOGO"(see section C below)
Remember: alias IS case sensitive.

B.2) Compiling and creating a resource file <resourcesfilename>.rcc
...\harbour\bin\rcc -binary -o <resourcesfilename>.rcc <resourcesfilename>.qrc
Warning: the file. rcc must reside in the same directory of the executable program.

B.3) Code to be added at the beginning of your main program .prg

Code: Select all

 #include "hmg.ch"

 STATIC s_re1       <-------------

 *.................................................................................
 * main function
 *.................................................................................
 FUNCTION Main()

  HBQT_ERRORSYS()

  s_re1 := QResource()     <-------------
  s_re1:registerResource( "<resourcesfilename>.rcc" )     <-------------

Warning: <resourcesfilename>.rcc must be the same as B.2

B.4) Code to add when closing your main program (perhaps, in the event OnRelease of the main window)

Code: Select all

 *.................................................................................
 * main window OnRelease event
 *.................................................................................
 STATIC FUNCTION Win_OnRelease()

   s_re1:unregisterResource( "<resourcesfilename>.rcc" )

 RETURN NIL
Warning: <resourcesfilename>.rcc must be the same as B.2

B.5) Compile the program with Harbour (the other options you already know):
HBMK2 %1 <iconfilename>.rc .....
C) Use of images and icons in the programs .prg (examples)
Warning: displaying the images is dependent on the library HMG4 handle the image correctly.

C.1) DEFINE WINDOW

Code: Select all

DEFINE WINDOW p000Win
  ROW	0
	COL	0
	ICON ":MYLOGO"
  .....
C.2) MENU ITEM

Code: Select all

MENUITEM "e&Xit" ACTION p000_Exit() IMAGE ":L3W_IEXIT"
C.3) BUTTON

Code: Select all

With Object oButton2 := Button():New()
  ...
  :Picture	:= ':L3W_ISAVE'
  ...

Concluding remarks.
I'm not a Guru :|
I hope I was clear enough in the process of implementation :roll:
Unfortunately, the documentation for the world Xbase / Harbour is not very clear instead for the C programming :cry:
I don't know if this can be considered the only one solution: this is what I found after 4 weeks of errors :twisted:
If you have any questions, I am at your disposal, but know that I consider myself a newbe. I'll do what I can ;)

Warning:
I have read, about the contents of the file .rcc, which could be inserted into the executable at C compiler time as a file. cpp. I do not know how I can do. If anyone has any idea could tell me?

Cheers
Luigi from Italy
www.L3W.it
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: HMG4: image icon resource file

Post by Rathinagiri »

Perfect Luigi.

Based on your code, now I am working on

a) the removal of ":" and adding the same in HMG4 library level.
b) Management of QResource() also in HMG4 library level.

In this way, we can convert all our HMG3 applications, only by changing the .rc file into .qrc file. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: HMG4: image icon resource file

Post by Rathinagiri »

I had checked your suggestion and it works as we expect. :)

Can you please join the developers' team and contribute the code yourselves?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: HMG4: image icon resource file

Post by l3whmg »

Hi Rathinagiri,
I sent you a PM about developer's team.
About "b) Management of QResource() also in HMG4 library level", I want do some tests, because I have this doubt.

If we insert in HMG4 lib this piece of code
s_re1:registerResource( "<resourcesfilename>.rcc" )
1) The <resourcesfilename> must be prefixed :?: In this case, how could a user to add his HMG4 images? He is expected to generate a file which also includes those of HMG :roll:

or

2) We should give the opportunity to register this file with a function (eg "HMG_RegResource (name)" and "HMG_UnRegResource(name)" ) that will be added to already provided (Is it possible?) by HMG :roll:

or

:?:

In fact, I look at hbide but it's a "closed project" thinking about images, actions and so on. The developer will determine first what is useful: images, commands, etc.. Instead, HMG4 will know later (I hope to have been clear this section).

Cheers
Luigi from Italy
www.L3W.it
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: HMG4: image icon resource file

Post by concentra »

Invading the topic... :)

Does anyone knows if is it possible to use dialogs defined in RC files in HMG4 ?
How do I reference the dialog IDs in the code ?
If not, is it possible to auto convert the RCs to another supported format ?

I am asking for this because I want to port FiveWin code to HMG4 and the code have a lot of RCs . :(

[[]] Maurício Faria
[[]] Mauricio Ventura Faria
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: HMG4: image icon resource file

Post by Rathinagiri »

l3whmg wrote:Hi Rathinagiri,
I sent you a PM about developer's team.
About "b) Management of QResource() also in HMG4 library level", I want do some tests, because I have this doubt.

If we insert in HMG4 lib this piece of code
s_re1:registerResource( "<resourcesfilename>.rcc" )
1) The <resourcesfilename> must be prefixed :?: In this case, how could a user to add his HMG4 images? He is expected to generate a file which also includes those of HMG :roll:

or

2) We should give the opportunity to register this file with a function (eg "HMG_RegResource (name)" and "HMG_UnRegResource(name)" ) that will be added to already provided (Is it possible?) by HMG :roll:

or

:?:

In fact, I look at hbide but it's a "closed project" thinking about images, actions and so on. The developer will determine first what is useful: images, commands, etc.. Instead, HMG4 will know later (I hope to have been clear this section).

Cheers
Hi Luigi,

Nothing is impossible, except bringing a death person to live. :)

We can prefix the .rcc filename like _hmg4_temp.rcc even though we have a different .qrc filename via batch file. Isn't it? We can then verify the availability of this file inside HMG4 library code.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: HMG4: image icon resource file

Post by Rathinagiri »

After some study, I found that, making a .rcc file is a dynamic one meaning, the resources are not embedded to exe file.

I am successful in embedding the .qrc file inside .exe by using a .hbp file mentioning the .qrc file at the end. This I can find by seeing the different sizes of exe files with and without .qrc.

However, I am not successful in calling the resource inside the executable file. Can anybody help?

Hbide is an open source project. I had seen the above method of resource handling from HBIDE only. Thanks to Pritpal for that.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: HMG4: image icon resource file

Post by l3whmg »

Hi everybody,

:D :D for me it's a great day: I find how can compile a program with QT library with embedding images and icons, without an external .rcc file
I must do other test and then I can show my experience....

For Concentra
at this moment (as you can read) I only +- understand how it's possible to compile a program with QT library and use icon/image.

Cheers
Luigi from Italy
www.L3W.it
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: HMG4: image icon resource file

Post by Rathinagiri »

Is it!?

Fantastic Luigi.

I could embed the resource, but couldn't refer it.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: HMG4: image icon resource file

Post by l3whmg »

Hello everyone.
first and briefly, some information derived from Qt's documentation, which you can find here (http://doc.qt.nokia.com/latest/qresource.html#details).
"That QResource is an object Represents a set of data (and possibly children) Relating to a single resource entity. QResource Gives direct access to the raw bytes in Their format. In this way direct access Allows reading data buffer without copying or indirection."

This class has two members: "registerResource()" and "unregisterResource()". Attention! The first parameter can be a rccFileName or a rccData.

Now I describe how I came to the solution.

Open one of these files with an editor (preferably idemain.prg):
- harbour\contrib\hbide\idemain.prg
- harbour\contrib\hbqt\tests\testres.prg
- harbour\contrib\hbnetio\utils\hbnetioq\netiosrq.prg

A) QResource class used by the harbour
A.1) search for the string "registerResource_1". As the first parameter you will find a function which begins with "hbqtres_xxxxxx ()"
A.2) in the previous solution (the one with the external file) I had used "registerResource"

first important thing! it seems that the Qt bindings use two different classes according to the first parameter of QT:
"QResource (): registerResource (rccFileName)" if you use an external file .RCC
"QResource():registerResource_1(rccData)" if you use binary data inside

B) the compiler Harbour: as it compiles and includes the binary file.
Open this file "harbour\contrib\hbqt\hbmk2_qt.hbs" and search for the string "/* Create little .prg stub which includes the binary */"

B.1) during compilation, if a .QRC file is included, the compiler creates a .PRG which contains a function called "hbqtres_<filename>()".
and incidentally, <filename> is the name of the physical file and corresponds to the sequence "xxxxxx" to A.1) point for each .QRC file included in the compilation

B.2) during compilation, if a QRC file is included, the compiler creates a file .QRB (instead of a .RCC file) which contains the binary code corresponding to the content of .QRC

first case of application

1) compilation. the command is this "HBMK2 pgmp000.hbp <iconfilename>.rc ...." (the other options you already know)
note: now it's not required rcc.exe compiler

2) HBP file content. at the bottom of this file, place all .QRC files. Example.

Code: Select all

#
# Harbour flags
#
-inc
-prgflag=-w0 -es2 -gtgui
-workdir=./temp
D:/HMG4/hmg/svn/hmg.hbc
pgmp000.hbc
pgmp000.prg
l3w_xsys.prg
l3w_xprj.prg

cusimage.qrc
other1.qrc
other2.qrc
...
3) QRC file content. I invite you to read the previous post regarding the contents of this file

Code: Select all

<!DOCTYPE RCC><RCC version="1.0">
<qresource>
 <file alias="MYLOGO">Icons\l3w_logo.ico</file>
 <file alias="L3W_ICLEAR">Icons\clear.png</file>
 <file alias="L3W_ICOPY">Icons\copy.png</file>
 <file alias="L3W_IEXIT">Icons\exit.png</file>
</qresource>
</RCC>
4) PRG main content.

Code: Select all

FUNCTION Main()

 HBQT_ERRORSYS()

 QResource():registerResource_1( HBQTRES_CUSIMAGE(), ":/resource" )
 QResource():registerResource_1( HBQTRES_OTHER1(), ":/resource" )
 QResource():registerResource_1( HBQTRES_OTHER2(), ":/resource" )
 ...

 your next code here

RETURN NIL
5) HMG4 commands.
5.1) DEFINE WINDOW
DEFINE WINDOW p000Win
ROW 0
COL 0
ICON ":MYLOGO"
.....

5.2) MENU ITEM
MENUITEM "e&Xit" ACTION p000_Exit() IMAGE ":L3W_IEXIT"

5.3) BUTTON
With Object oButton2 := Button():New()
...
Picture := ':L3W_ISAVE'
...

I hope I was clear in the explanation. excuse me if I did not use correct terms

I believe that:
A) HMG4 publishes a .QRC file, which contains icons and images of HMG (eg hmg4res.qrc)
B) source window.prg: after this line "::s_qApp := QApplication()" insert "QResource():registerResource_1( HBQTRES_HMG4RES(), ":/resource" )"
C) will be the programmer, who uses the library HMG4, inserted at the beginning of the main function many "QResource ...." how many .QRC files he wants to use. Because HMG4 can't known and can't register unknown resources file (I think)

Perhaps, it is appropriate to create two HMG4 functions to link the QT functions. For example:
- HMG_RegisterFile(rccFileName) binding to QResource():registerResource(rccFileName)
- HMG_RegisterData binding to QResource():registerResource:(rccData)

Most important: I don't known future directions about QT library and Harbour code...

I am available to the developer team for further questions, opinions, suggestions, etc.

Cheers
Luigi from Italy
www.L3W.it
Post Reply