Jump to navigation Jump to search

PHP WinBinder 2: Resource

59 bytes added, 02:06, 30 January 2010
Proofreading and grammatical changes; some minor reformatting
'''''WinBinder Part 2 PHC-Win Resources'''''
On the previous page I mentioned image duplication. We included individual images with our distribution package , however PHC-Win adds these to the final exe file.
Without making code changes , these image resources are not directly accessible by WinBinder , hence the reason for adding them to our distribution package.
This page looks at describes code changes required to use images contained within the .exe file , thus eliminating the need for separately including them with the distribution package.
== Embeder overview ==
The embeder creates an executable file where additional files may be added.
These files are added to an array named PHP, array . Array keys are md5 encoded a . A resource file is accessible via it’s its key.
Running tis this executable creates a unique constant is created named '''''EMBEDED''''' .
It’s worth looking at the mechanics of this process.
'''''[[#top | Top]]'''''
== Problem ==
Our application uses the following code to assign images :
=== Solution ===
Solution The solution is as follows:
* Write the image resource to a file on disk
* Allow WinBinder to assign this image file (using it's its path)* Once assigned , it is no longer required hence , so delete the image file
'''''[[#top | Top]]'''''
=== Code ===
Code splits The code is split into three sections.
* First section tests if code is running from the .exe using EMBEDED as a reference. If running from .exe , it gets the image resource as a file and saves it to disk with the original file name.
* Second section contains original lines that remain unchanged.
* Last section tests if code is running from the .exe and deletes the file from disk if true.
This method allows code to be tested with original images. After compiling , the .exe produced is moved to folder C:\us_wb\my_dis\final for testing.
If code is running from .exe (EMBEDED true) get resource as a file and save it to disk with same file name..
If running from .exe , image no longer required hence , so deleteit.
With the exception of image name , each image requires identical code.
'''''[[#top | Top]]'''''
== Modifications ==
Edit file C:\us_wb\my_app\'''z_basic.phpw'''
* Designing a Windows application using WinBinder is extremely easy.
* Compiling a project with PHC-Win really is a snipsnap, and takes just a few mouse clicks.
* Being slightly A slight negative for a small Windows application is that the distributed code size is relatively large. This is not a significant issue, havening with the connivance convenience and ease of use of PHP far out ways outweighs this.
* That said core elements of WinBinder are being actively worked on. Both Andrew (Frantik) and Alec Gorge “alecgorge” are pushing to reduce core size further ; expect significant changes.
* The WinBinder project remains alive and vibrant. What I really like, is that you can produce very powerful Windows applications using these tools. Project The project is well supported and you will find numerous code examples.
* If you get stuck with a problem , visit WinBinder’s friendly forum.

Navigation menu