PHP WinBinder 2: WinBinder portable: Difference between revisions

Proofreading and grammatical changes; some minor reformatting
(New page: {{Nav PHP WinBinder 2}} '''''WinBinder Part 2''''' == Introduction == PHP is an excellent scripting language primarily designed for dynamic web sites however it also contains a command lin...)
 
(Proofreading and grammatical changes; some minor reformatting)
Line 2: Line 2:
'''''WinBinder Part 2'''''
'''''WinBinder Part 2'''''
== Introduction ==
== Introduction ==
PHP is an excellent scripting language primarily designed for dynamic web sites however it also contains a command line interface. You run this via a command window although powerful it lacks a friendly user interface. The WinBinder project addressed this with a neat extension allowing a user to create windows applications.
PHP is an excellent scripting language, primarily designed for dynamic web sites. It also contains a command line interface, which you run from a command window. Although powerful, it lacks a friendly user interface. The WinBinder project addresses this with a neat extension, allowing a user to create Windows applications.


This tutorial describes a slightly modified version that is portable and runs straight out of the box. The tutorial assumes you have extracted a copy as explained on [[PHP WinBinder 2: Introduction#WinBinder Portable  | '''this page''']].
This tutorial describes a slightly modified version that is portable and runs straight out of the box. The tutorial assumes you have extracted a copy as explained on [[PHP WinBinder 2: Introduction#WinBinder Portable  | '''this page''']].
Line 9: Line 9:


== Examples ==
== Examples ==
To really appreciate WinBinders capabilities run the examples in folder C:\us_wb\wb\'''examples'''. All WinBinder windows scripts have the extension '''phpw''' you will notice that each script has a corresponding batch file. Double click on a batch file to run its associated script. These batch files were added purely for portability and connivance. (See [[PHP WinBinder 2: PHC-Win | '''PHC-win''']] how to create executables)
To really appreciate WinBinder's capabilities, run the examples in the folder C:\us_wb\wb\'''examples'''. All WinBinder Windows scripts have the extension '''phpw'''. You will notice that each script has a corresponding batch file. Double click on a batch file to run its associated script. These batch files were added purely for portability and convenience. (See [[PHP WinBinder 2: PHC-Win | '''PHC-win''']] on how to create executables).


Run '''manytests_main.bat''' it provides an excellent example showing all controls available.
Run '''manytests_main.bat''' which provides an excellent example showing all controls available.


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''


== Form Editor ==
== Form Editor ==
Form editor is an excellent tool for positioning Windows controls this overview will quickly get you up and running:
Form editor is an excellent tool for positioning Windows controls. This overview will quickly get you up and running:
{|
{|
|-valign="top"
|-valign="top"
|
|
Navigate to folder C:\us_wb\wb\'''form_editor''' and
Navigate to folder C:\us_wb\wb\'''form_editor''' and
double click on the batch file '''Run_form_editor.bat'''. This runs the form editor.


double click on batch '''file Run_form_editor.bat''' this runs the form editor.
You will see three floating windows as shown on the right.
 
You will see three floating windows shown on the right.


* '''A)''' Main application window
* '''A)''' Main application window
* '''B)''' The application you are designing
* '''B)''' The application you are designing
* '''C)''' Control (component) selector you can close this and use the drop down menu '''D)'''
* '''C)''' Control (component) selector. You can close this and use the drop down menu '''D)'''




* E) After adding a control they are listed in this window. Click any item in the<br /> list to select a control, alternatively click on a control in the application design window.
* '''E)''' After adding controls, they are listed in this window. Click any item in the<br /> list to select a control; alternatively click on a control in the application design window.
* F) This window displays additional styles you can add to a control.
* '''F)''' This window displays additional styles that you can add to a control.
* G) These four controls allow you to finely tune the position of a selected control
* '''G)''' These four controls allow you to finely tune the position of a selected control.




Line 42: Line 41:
'''Delete a control'''
'''Delete a control'''


You can delete a control by first selecting it and use menu '''Edit > Delete control'''
You can delete a control by first selecting it and using menu '''Edit > Delete control'''
   
   
'''Preview application'''
'''Preview application'''
Line 50: Line 49:




The form editor '''does not''' add functionality to any controls it is purely a layout tool.<br />Saving a project automatically exports a PHP script (file) containing layout information<br />this you can use either directly or cut and paste parts you require.
The form editor '''does not''' add functionality to any controls. It is purely a layout tool. Saving a project automatically exports a PHP script (file) containing layout information which you can use either directly or cut and paste the parts you require.
|
|
[[Image:WinBinder_FE_1.gif]]
[[Image:WinBinder_FE_1.gif]]
Line 56: Line 55:


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Tutorial ==
== Tutorial ==
This tutorial is intended to show the mechanics of creating a windows application using WinBinder and PHC-Win.
This tutorial is intended to show the mechanics of creating a windows application using WinBinder and PHC-Win.


So as not to mask details of this process the example is intentionally basic.
So as not to mask details of this process, the example is intentionally basic.


'''''Specification'''''
'''''Specification'''''


The application has two buttons each toggling the state of it's corresponding image.
The application has two buttons, each toggling the state of its corresponding image.
 
Several small files are used to simulate a larger project and demonstrate PHC-Win capabilities.
Several small files are used these simulate a larger project and demonstrate PHC-Win capabilities.


'''''[[#top | Top]]'''''
=== Preliminary ===
=== Preliminary ===
To store files and resources every application requires a main folder.
Every application requires a main folder to store the files and resources.


Create a new folder named '''my_app''' (or any other name) in folder  C:\'''us_wb''' (can be a different location).
Create a new folder named '''my_app''' (or any other name) in folder  C:\'''us_wb''' (can be a different location).


Reason for choosing this location is one of portability, you can copy folder '''us_wb''' to a USB memory stick and take your entire projects with you.
The reason for choosing this location is one of portability. You can copy folder '''us_wb''' to a USB memory stick and take your entire project set with you.


==== Basic Window app ====
==== Basic Windows app ====
{|
{|
|-valign="top"
|-valign="top"
|
|
'''''Basic Window app'':'''
'''''Basic Windows app'':'''


Each windows application has a common format to save typing you will find a template in folder C:\us_wb\wb\us_tutorial copy the two files '''z_basic.bat''' and '''z_basic.phpw''' to folder C:\us_wb\'''my_app'''.
Each Windows application has a common format. To save typing, you will find a template in folder C:\us_wb\wb\us_tutorial. Copy the two files '''z_basic.bat''' and '''z_basic.phpw''' to folder C:\us_wb\'''my_app'''.


* '''z_basic.bat''' Required to run the application z_basic.phpw. It opens a command window that does not close while the application is running any PHP error messages are displayed in this window.
* '''z_basic.bat''' Required to run the application z_basic.phpw. It opens a command window that does not close while the application is running. Any PHP error messages are displayed in this window.
* '''z_basic.phpw''' This template is our starting point for a new application.
* '''z_basic.phpw''' This template is our starting point for a new application.


Line 97: Line 93:
Press any key to continue . . .
Press any key to continue . . .
</pre>
</pre>
The error message is clear both files contain incorrect paths.
The error message is clear: both files contain incorrect paths.


These files contain relative paths '''..\php'''” the two periods means move up one folder level and down into folder php however it can not find the folder php. This folder resides inside folder '''wb'''” hence must be included in the paths as shown in the next section.
These files contain relative paths "'''..\php'''." The two periods means move up one folder level and down into folder php. but it cannot find the folder php. This folder resides inside folder "'''wb'''" and must be included in the paths as shown in the next section.
|
|
&nbsp;
&nbsp;
Line 138: Line 134:
</pre>
</pre>
|}
|}
'''''[[#top | Top]]'''''


==== Basic Window app corrected paths ====
==== Basic Windows app with corrected paths ====
{|
{|
|-valign="top"
|-valign="top"
|
|
'''''Basic Window app corrected paths'':'''
'''''Basic Windows app with corrected paths'':'''
 
After correcting the path run '''z_basic.bat''' again.


This time the basic windows application will run.
After correcting the path, run '''z_basic.bat''' again.
This time the basic Windows application will run.




Our application looks a bit sparse however the structure is in place.
Our application looks a bit sparse, however the structure is in place.


We will use the form editor to layout all controls this will automatically provide code for '''constants''' and '''control creation''' sections.
We will use the form editor to layout all controls. This will automatically provide code for '''constants''' and '''control creation''' sections.


However before doing this it is worth making a list of ID names and caption values to be used in the application.
But before doing this, it is worth making a list of ID names and caption values to be used in the application.


We have two buttons these can have the following ID’s and captions:
We have two buttons that can have the following IDs and captions:
* IDC_BUTTONRED1 - Button ID
* IDC_BUTTONRED1 - Button ID
* Red 1    - Button caption - Code toggles between Red 1 and Green 1
* Red 1    - Button caption - Code toggles between Red 1 and Green 1
Line 207: Line 201:
</pre>
</pre>
|}
|}
'''''[[#top | Top]]'''''


=== Create Form ===
=== Create Form ===
I have not provided details for a control’s position it’s your choice. Frame sizes are important they must match our images these are 20x12 pixels.
I have not provided details for a control’s position. That’s your choice. Frame sizes are important because they must match our images; these are 20x12 pixels.


{|
{|
|-valign="top"
|-valign="top"
|
|
Before creating a form it is best to create a new folder that will contain the resulting form (refered to as a project). Create a new folder named '''my_project''' (or any other name) in folder C:\'''us_wb'''  
Before creating a form, it is best to create a new folder that will contain the resulting form (referred to as a project). Create a new folder named '''my_project''' (or any other name) in folder C:\'''us_wb'''  


Start form editor by running C:\us_wb\wb\form_editor\'''Run_form_editor.bat'''
Start form editor by running C:\us_wb\wb\form_editor\'''Run_form_editor.bat'''


* Add a PushButton change ID to '''IDC_BUTTONRED1''' change caption to '''Red 1'''
* Add a PushButton, change ID to '''IDC_BUTTONRED1''', change caption to '''Red 1'''
* Create a second button change ID to '''IDC_BUTTONRED2''' change caption to '''Red 2''' Move this button just below the first button
* Create a second button, change ID to '''IDC_BUTTONRED2''', change caption to '''Red 2'''. Move this button just below the first button




* Create a Frame change ID to '''IDC_FRAMERED1''' delete the caption. In the styles select (check) the '''image box'''. Change the width to '''20''' and height to '''12''' . Move the frame to the right of button 1.
* Create a Frame, change ID to '''IDC_FRAMERED1''', delete the caption. In the styles select (check) the '''image box'''. Change the width to '''20''' and height to '''12'''. Move the frame to the right of button 1.
* Create a Frame change ID to '''IDC_FRAMGREEN1''' delete the caption. In the styles select (check) the image box. Change the width to 20 and height to 12 . Move the frame to the right of button 1 ('''left and top''' values identical to the above frame).
* Create a Frame, change ID to '''IDC_FRAMGREEN1''', delete the caption. In the styles select (check) the image box. Change the width to 20 and height to 12. Move the frame to the right of button 1 ('''left and top''' values identical to the above frame).




*Create a Frame change ID to '''IDC_FRAMERED2''' delete the caption. In the styles select (check) the '''image box'''. Change the width to 20 and height to 12 . Move the frame to the right of button 2.
*Create a Frame, change ID to '''IDC_FRAMERED2''', delete the caption. In the styles, select (check) the '''image box'''. Change the width to 20 and height to 12. Move the frame to the right of button 2.
*Create a Frame change ID to '''IDC_FRAMGREEN2''' delete the caption. In the styles select (check) the '''image box'''. Change the width to 20 and height to 12 . Move the  
*Create a Frame, change ID to '''IDC_FRAMGREEN2''', delete the caption. In the styles, select (check) the '''image box'''. Change the width to 20 and height to 12. Move the frame to the right of button 2 (left and top values identical to the above frame).
frame to the right of button 2 (left and top values identical to the above frame).


* Resize the application window to so the buttons and frame are in the enter of the window.
* Resize the application window so the buttons and frame are in the center of the window.


Save the project with name '''my.prj''' to folder '''my_proj''' as follows
Save the project with name '''my.prj''' to folder '''my_proj''' as follows:
* Top meun, select '''File > Save Project as'''
* Top menu, select '''File > Save Project as'''
* Navigate to folder '''my_project'''
* Navigate to folder '''my_project'''
* Eenter '''my.prj'''
* Enter '''my.prj'''
* Click save
* Click save
* Exit form editor, select '''File > Exit'''
* Exit form editor, select '''File > Exit'''
Line 242: Line 234:
[[Image:WinBinder_FE_2.gif]]
[[Image:WinBinder_FE_2.gif]]
|}
|}
'''''[[#top | Top]]'''''


==== Exported file ====
==== Exported file ====
The form editor automatically exports a PHP file corresponding to the form component layout.
The form editor automatically exports a PHP file corresponding to the form component layout.
This file can be found in our project folder.
This file can be found in our project folder.


In this example it is named '''my.form.php''' and has the following content
In this example, it is named '''my.form.php''' and has the following content:
<pre>
<pre>
<?php
<?php
Line 285: Line 275:
?>
?>
</pre>
</pre>
'''''[[#top | Top]]'''''


==== Copy and paste ====
==== Copy and paste ====
Line 314: Line 303:
   wb_set_image($mainwin, "uslogo.ico");  // Add logo  
   wb_set_image($mainwin, "uslogo.ico");  // Add logo  
</pre>
</pre>
'''''[[#top | Top]]'''''
 
==== Test ====
==== Test ====
{|
{|
Line 329: Line 318:


== Summary ==
== Summary ==
That completes form editor introduction you will appreciate how useful it is when you work with a larger application.
That completes the form editor introduction. You will appreciate how useful it is when you work with a larger application.


If you need to add additional controls or move the existing controls around open your project file in form editor make the changes and transfer these to your application. That really does save time.
If you need to add additional controls or move the existing controls around, open your project file in form editor, make the changes and transfer these to your application. That really does save time.


Before looking at PHC-Win [[PHP WinBinder 2: Add code | '''next page''']] covers adding functionality to the buttons. This functionality is spread across several files providing PHC-Win with more than a single file to process.
Before looking at PHC-Win, the [[PHP WinBinder 2: Add code | '''next page''']] covers adding functionality to the buttons. This functionality is spread across several files, providing PHC-Win with more than a single file to process.


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''