PHP WinBinder 2: WinBinder portable: Difference between revisions

From The Uniform Server Wiki
Jump to navigation Jump to search
(Proofreading and grammatical changes; some minor reformatting)
No edit summary
Line 1: Line 1:
=[http://oqagacyti.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]=
{{Nav PHP WinBinder 2}}
{{Nav PHP WinBinder 2}}
'''''WinBinder Part 2'''''
'''''WinBinder Part 2'''''
Line 18: Line 19:
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
Line 30: Line 31:




* '''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.
* '''E)''' After adding controls, they are listed in this window. Click any item in the&lt;br /&gt; list to select a control; alternatively click on a control in the application design window.
* '''F)''' This window displays additional styles that 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 37: Line 38:
'''Explore'''
'''Explore'''


Explore the form-editor, add controls move them around.<br />Get a feel for laying out controls.
Explore the form-editor, add controls move them around.&lt;br /&gt;Get a feel for laying out controls.


'''Delete a control'''
'''Delete a control'''


You can delete a control by first selecting it and using menu '''Edit > Delete control'''
You can delete a control by first selecting it and using menu '''Edit &gt; Delete control'''
   
   
'''Preview application'''
'''Preview application'''


* Select '''View > Preview form'''
* Select '''View &gt; Preview form'''
* Displays what an application will look like   
* Displays what an application will look like   


Line 74: Line 75:
==== Basic Windows app ====
==== Basic Windows app ====
{|
{|
|-valign="top"
|-valign=&quot;top&quot;
|
|
'''''Basic Windows app'':'''
'''''Basic Windows app'':'''
Line 89: Line 90:


Running '''z_basic.bat''' (Double click on file) produces the following:
Running '''z_basic.bat''' (Double click on file) produces the following:
<pre>
&lt;pre&gt;
The system cannot find the path specified.
The system cannot find the path specified.
Press any key to continue . . .
Press any key to continue . . .
</pre>
&lt;/pre&gt;
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. 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.
These files contain relative paths &quot;'''..\php'''.&quot; 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 &quot;'''wb'''&quot; and must be included in the paths as shown in the next section.
|
|
&nbsp;
&amp;nbsp;
|
|
'''z_basic.bat'''
'''z_basic.bat'''
<pre>
&lt;pre&gt;
..\php\php.exe -c ..\php\php-wb.ini z_basic.phpw
..\php\php.exe -c ..\php\php-wb.ini z_basic.phpw
</pre>
&lt;/pre&gt;
'''z_basic.phpw'''
'''z_basic.phpw'''
<pre>
&lt;pre&gt;
<?php
&lt;?php
Include "../php/include/winbinder.php";      // Location Of Winbinder Library
Include &quot;../php/include/winbinder.php&quot;;      // Location Of Winbinder Library


//--- Constants ---------------------------------------------------------------
//--- Constants ---------------------------------------------------------------


//=== 1) Create main window ---------------------------------------------------
//=== 1) Create main window ---------------------------------------------------
$mainwin = wb_create_window(NULL, AppWindow, "z_basic", 320, 240);
$mainwin = wb_create_window(NULL, AppWindow, &quot;z_basic&quot;, 320, 240);


//=== 2) Create controls for the main window ----------------------------------
//=== 2) Create controls for the main window ----------------------------------


//=== 3) Assign handler function to the main window  --------------------------
//=== 3) Assign handler function to the main window  --------------------------
wb_set_handler($mainwin, "process_main");       
wb_set_handler($mainwin, &quot;process_main&quot;);       


//=== 5) Enter application loop -----------------------------------------------
//=== 5) Enter application loop -----------------------------------------------
Line 131: Line 132:
   }
   }
}
}
?>
?&gt;
</pre>
&lt;/pre&gt;
|}
|}


==== Basic Windows app with corrected paths ====
==== Basic Windows app with corrected paths ====
{|
{|
|-valign="top"
|-valign=&quot;top&quot;
|
|
'''''Basic Windows app with corrected paths'':'''
'''''Basic Windows app with corrected paths'':'''
Line 164: Line 165:


|
|
&nbsp;
&amp;nbsp;
|
|
'''z_basic.bat'''
'''z_basic.bat'''
<pre>
&lt;pre&gt;
..\wb\php\php.exe -c ..\wb\php\php-wb.ini z_basic.phpw
..\wb\php\php.exe -c ..\wb\php\php-wb.ini z_basic.phpw
</pre>
&lt;/pre&gt;
'''z_basic.phpw'''
'''z_basic.phpw'''
<pre>
&lt;pre&gt;
<?php
&lt;?php
Include "../wb/php/include/winbinder.php";      // Location Of Winbinder Library
Include &quot;../wb/php/include/winbinder.php&quot;;      // Location Of Winbinder Library


//--- Constants ---------------------------------------------------------------
//--- Constants ---------------------------------------------------------------


//=== 1) Create main window ---------------------------------------------------
//=== 1) Create main window ---------------------------------------------------
$mainwin = wb_create_window(NULL, AppWindow, "z_basic", 320, 240);
$mainwin = wb_create_window(NULL, AppWindow, &quot;z_basic&quot;, 320, 240);


//=== 2) Create controls for the main window ----------------------------------
//=== 2) Create controls for the main window ----------------------------------


//=== 3) Assign handler function to the main window  --------------------------
//=== 3) Assign handler function to the main window  --------------------------
wb_set_handler($mainwin, "process_main");       
wb_set_handler($mainwin, &quot;process_main&quot;);       


//=== 5) Enter application loop -----------------------------------------------
//=== 5) Enter application loop -----------------------------------------------
Line 198: Line 199:
   }
   }
}
}
?>
?&gt;
</pre>
&lt;/pre&gt;
|}
|}


Line 206: Line 207:


{|
{|
|-valign="top"
|-valign=&quot;top&quot;
|
|
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'''  
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'''  
Line 226: Line 227:


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 menu, select '''File > Save Project as'''
* Top menu, select '''File &gt; Save Project as'''
* Navigate to folder '''my_project'''
* Navigate to folder '''my_project'''
* Enter '''my.prj'''
* Enter '''my.prj'''
* Click save
* Click save
* Exit form editor, select '''File > Exit'''
* Exit form editor, select '''File &gt; Exit'''
|
|
[[Image:WinBinder_FE_2.gif]]
[[Image:WinBinder_FE_2.gif]]
Line 240: Line 241:


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>
&lt;pre&gt;
<?php
&lt;?php


/*******************************************************************************
/*******************************************************************************
Line 273: Line 274:
// End controls
// End controls


?>
?&gt;
</pre>
&lt;/pre&gt;


==== Copy and paste ====
==== Copy and paste ====
Line 288: Line 289:
==== Assign Images ====
==== Assign Images ====
Use the following code to assign images to the frames. Place code at end of section “2) Create controls for the main window”  
Use the following code to assign images to the frames. Place code at end of section “2) Create controls for the main window”  
<pre>
&lt;pre&gt;
// Assign images to frames
// Assign images to frames
wb_set_image(wb_get_control($mainwin, IDC_FRAMERED1),'red.bmp', NOCOLOR);     
wb_set_image(wb_get_control($mainwin, IDC_FRAMERED1),'red.bmp', NOCOLOR);     
Line 294: Line 295:
wb_set_image(wb_get_control($mainwin, IDC_FRAMERED2),  'red.bmp', NOCOLOR);   
wb_set_image(wb_get_control($mainwin, IDC_FRAMERED2),  'red.bmp', NOCOLOR);   
wb_set_image(wb_get_control($mainwin, IDC_FRAMEGREEN2),'green.bmp', NOCOLOR);  
wb_set_image(wb_get_control($mainwin, IDC_FRAMEGREEN2),'green.bmp', NOCOLOR);  
</pre>
&lt;/pre&gt;




Add a logo image to the application window.
Add a logo image to the application window.
<pre>
&lt;pre&gt;
//=== 3) Assign handler function to the main window  --------------------------
//=== 3) Assign handler function to the main window  --------------------------
wb_set_handler($mainwin, "process_main");
wb_set_handler($mainwin, &quot;process_main&quot;);
   wb_set_image($mainwin, "uslogo.ico");  // Add logo  
   wb_set_image($mainwin, &quot;uslogo.ico&quot;);  // Add logo  
</pre>
&lt;/pre&gt;


==== Test ====
==== Test ====
{|
{|
|-valign="top"
|-valign=&quot;top&quot;
|
|
* Run C:\us_wb\my_app\'''z_basic.bat'''
* Run C:\us_wb\my_app\'''z_basic.bat'''

Revision as of 10:23, 24 November 2010

Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page

 

UniServer 5-Nano
PHP WinBinder 2.

WinBinder Part 2

Introduction

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 this page.

Top

Examples

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 PHC-win on how to create executables).

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

Top

Form Editor

Form editor is an excellent tool for positioning Windows controls. This overview will quickly get you up and running:

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.

You will see three floating windows as shown on the right.

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


  • 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 that you can add to a control.
  • G) These four controls allow you to finely tune the position of a selected control.


Explore

Explore the form-editor, add controls move them around.<br />Get a feel for laying out controls.

Delete a control

You can delete a control by first selecting it and using menu Edit > Delete control

Preview application

  • Select View > Preview form
  • Displays what an application will look like


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.

Top

Tutorial

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.

Specification

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.

Preliminary

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).

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 Windows 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.

  • 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.


Errors:

Well! Even from this starting point we have introduced errors!

Running z_basic.bat (Double click on file) produces the following: <pre> The system cannot find the path specified. Press any key to continue . . . </pre> 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. 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;

z_basic.bat <pre> ..\php\php.exe -c ..\php\php-wb.ini z_basic.phpw </pre> z_basic.phpw <pre> <?php Include "../php/include/winbinder.php"; // Location Of Winbinder Library

//--- Constants ---------------------------------------------------------------

//=== 1) Create main window --------------------------------------------------- $mainwin = wb_create_window(NULL, AppWindow, "z_basic", 320, 240);

//=== 2) Create controls for the main window ----------------------------------

//=== 3) Assign handler function to the main window -------------------------- wb_set_handler($mainwin, "process_main");

//=== 5) Enter application loop ----------------------------------------------- wb_main_loop();

//=== 4) Handler Function ----------------------------------------------------- function process_main($window, $id) {

 switch($id) { 
  case IDCLOSE:                          // Constant IDCLOSE (8) predefined 
   wb_destroy_window($window);           // Destroy the window
   break; 
 }

} ?> </pre>

Basic Windows app with 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.


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.

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 that can have the following IDs and captions:

  • IDC_BUTTONRED1 - Button ID
  • Red 1 - Button caption - Code toggles between Red 1 and Green 1
  • IDC_BUTTONRED2 - Button ID
  • Red 2 - Button caption - Code toggles between Red 2 and Green 2
  • IDC_FRAMERED1 - An image frame to contain image red.bmp
  • IDC_FRAMEGREEN1 - An image frame to contain image green.bmp
  • IDC_FRAMERED2 - An image frame to contain image red.bmp
  • IDC_FRAMEGREEN2 - An image frame to contain image green.bmp

&nbsp;

z_basic.bat <pre> ..\wb\php\php.exe -c ..\wb\php\php-wb.ini z_basic.phpw </pre> z_basic.phpw <pre> <?php Include "../wb/php/include/winbinder.php"; // Location Of Winbinder Library

//--- Constants ---------------------------------------------------------------

//=== 1) Create main window --------------------------------------------------- $mainwin = wb_create_window(NULL, AppWindow, "z_basic", 320, 240);

//=== 2) Create controls for the main window ----------------------------------

//=== 3) Assign handler function to the main window -------------------------- wb_set_handler($mainwin, "process_main");

//=== 5) Enter application loop ----------------------------------------------- wb_main_loop();

//=== 4) Handler Function ----------------------------------------------------- function process_main($window, $id) {

 switch($id) { 
  case IDCLOSE:                          // Constant IDCLOSE (8) predefined 
   wb_destroy_window($window);           // Destroy the window
   break; 
 }

} ?> </pre>

Create Form

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.

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

  • 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 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_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 frame to the right of button 2 (left and top values identical to the above frame).
  • 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:

  • Top menu, select File > Save Project as
  • Navigate to folder my_project
  • Enter my.prj
  • Click save
  • Exit form editor, select File > Exit

Exported file

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

In this example, it is named my.form.php and has the following content: <pre> <?php

/*******************************************************************************

WINBINDER - form editor PHP file (generated automatically)

                                                                                                                                                              • /

// Control identifiers

if(!defined('IDC_BUTTONRED1')) define('IDC_BUTTONRED1', 1); if(!defined('IDC_BUTTONRED2')) define('IDC_BUTTONRED2', 2); if(!defined('IDC_FRAMERED1')) define('IDC_FRAMERED1', 3); if(!defined('IDC_FRAMEGREEN1')) define('IDC_FRAMEGREEN1', 4); if(!defined('IDC_FRAMERED2')) define('IDC_FRAMERED2', 5); if(!defined('IDC_FRAMEGREEN2')) define('IDC_FRAMEGREEN2', 6);

// Create window

$mainwin = wb_create_window(null, AppWindow, '(Empty Form)', WBC_CENTER, WBC_CENTER, 195, 141, 0x00000000, 0);

// Insert controls

wb_create_control($mainwin, PushButton, 'Red 1', 20, 20, 90, 25, IDC_BUTTONRED1, 0x00000000, 0, 0); wb_create_control($mainwin, PushButton, 'Red 2', 20, 60, 90, 25, IDC_BUTTONRED2, 0x00000000, 0, 0); wb_create_control($mainwin, Frame, , 141, 23, 20, 12, IDC_FRAMERED1, 0x00000004, 0, 0); wb_create_control($mainwin, Frame, , 141, 23, 20, 12, IDC_FRAMEGREEN1, 0x00000004, 0, 0); wb_create_control($mainwin, Frame, , 141, 63, 20, 12, IDC_FRAMERED2, 0x00000004, 0, 0); wb_create_control($mainwin, Frame, , 141, 63, 20, 12, IDC_FRAMEGREEN2, 0x00000004, 0, 0);

// End controls

?> </pre>

Copy and paste

At this stage we can start building our application.

Copy images files (uslogo.ico, red.bmp and green.bmp) from folder C:\us_wb\wb\us_tutorial to folder C:\us_wb\my_app.

  • Open files C:\us_wb\my_app\z_basic.phpw and C:\us_wb\my_project\my.form.php in a text editor.
  • From my.form.php copy “Control identifiers” section and past in to z_basic.phpw under the Constants section.
  • From my.form.php copy “Insert controls” section and past in to z_basic.phpw under the “2) Create controls for the main window” section.
  • In z_basic.phpw change wb_create_window to have the same width and height as that in my.form.php.

Assign Images

Use the following code to assign images to the frames. Place code at end of section “2) Create controls for the main window” <pre> // Assign images to frames wb_set_image(wb_get_control($mainwin, IDC_FRAMERED1),'red.bmp', NOCOLOR); wb_set_image(wb_get_control($mainwin, IDC_FRAMEGREEN1),'green.bmp', NOCOLOR); wb_set_image(wb_get_control($mainwin, IDC_FRAMERED2), 'red.bmp', NOCOLOR); wb_set_image(wb_get_control($mainwin, IDC_FRAMEGREEN2),'green.bmp', NOCOLOR); </pre>


Add a logo image to the application window. <pre> //=== 3) Assign handler function to the main window -------------------------- wb_set_handler($mainwin, "process_main");

 wb_set_image($mainwin, "uslogo.ico");  // Add logo 

</pre>

Test

  • Run C:\us_wb\my_app\z_basic.bat
  • Application shown on right.
  • Currently buttons do nothing code to be added later.

Top

Summary

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.

Before looking at PHC-Win, the 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