PHP WinBinder: Introduction: Difference between revisions

From The Uniform Server Wiki
Jump to navigation Jump to search
(New page: {{Nav PHP WinBinder}} '''''WinBinder Plugin Introduction''''' PHP’s command line interface “CLI” is extremely powerful, however using a command window for user interfacing is restri...)
 
(Proofreading and grammatical changes; some minor reformatting)
Line 4: Line 4:
PHP’s command line interface “CLI” is extremely powerful, however using a command window for user interfacing is restrictive. An ideal solution would be to use a Windows interface.  
PHP’s command line interface “CLI” is extremely powerful, however using a command window for user interfacing is restrictive. An ideal solution would be to use a Windows interface.  


WinBinder provides a neat solution to the above. It remains actively supported by the open source community. Of importance the WinBinder extension '''php_winbinder.dll''' is being compiled for new versions of PHP (currently 5.3.1) hence WinBinder is alive and kicking.
WinBinder provides a neat solution. It remains actively supported by the open source community. Of importance, the WinBinder extension '''php_winbinder.dll''' is being compiled for new versions of PHP (currently 5.3.1), hence WinBinder is alive and kicking.


This plugin uses WinBinder to provide a PHP CLI Windows interface. It intentionally does not include a compiler, if you wish to produce standalone code check out this page [[PHP WinBinder 2: PHC-Win | '''PHC-Win''']].  
This plugin uses WinBinder to provide a PHP CLI Windows interface. It intentionally does not include a compiler. If you wish to produce standalone code, check out [[PHP WinBinder 2: PHC-Win | '''PHC-Win''']].  


Windows applications are generally coded in “c” before they can be executed require compiling. In contrast this self-contained plugin uses WinBinder allowing an application to be coded in PHP. This has the advantage of providing a common language for web-design, control architecture and user interface. It eliminates the need to learn a new language.
Windows applications are generally coded in “C”, so before they can be executed, they must be compiled. In contrast this self-contained plugin uses WinBinder, allowing an application to be coded in PHP. This has the advantage of providing a common language for web-design, control architecture and user interface. It eliminates the need to learn a new language.


This plugin is self-contained allowing it to be run independently of Uniform Server. However it is designed to fit neatly into Uniform Server’s control architecture thus providing an [[PHP WinBinder: Alternative control 1 | alternative control interface]]. If space is at a premium the plugin can be overplayed onto Uniform Server allowing it to use the existing PHP core (VC6).
The WinBinder plugin is self-contained allowing it to be run independently of Uniform Server. However it is designed to fit neatly into Uniform Server’s control architecture thus providing an [[PHP WinBinder: Alternative control 1 | alternative control interface]]. If space is at a premium the plugin can be overlayed onto Uniform Server allowing it to use the existing PHP core (VC6).


During development windows scripts are run using a batch file. This batch file can be converted to an exe using a small utility program included with this plugin.  
During development, windows scripts are run using a batch file. This batch file can be converted to an .exe using a small utility program included with the plugin.  


== Tutorial ==
== Tutorial ==
This tutorial explains how to use the plugin and introduces basics of windows programming using WinBinder.
This tutorial explains how to use the plugin and introduces some basics of windows programming using WinBinder.


An emphasis is on scripting hence I have avoided the complexity of compiling a windows application. Even with this restriction you can deploy a single file windows application all necessary files are compacted using the included utility.
An emphasis is on scripting, so I have avoided the complexity of compiling a windows application. Even with this restriction you can deploy a single file windows application; all necessary files are compressed using the included utility.


Tutorial format is based around working examples; first basic principals are explained followed by a working script you can run.
The tutorial format is based around working examples; first basic principles are explained, followed by a working script you can run.


'''''[[#top | Top]]'''''
=== Topics covered ===
=== Topics covered ===
{|
{|
Line 29: Line 28:
[[PHP WinBinder: Basic IO | '''Basic IO''']] introduces two windows components '''Labels''' and '''Push button'''.
[[PHP WinBinder: Basic IO | '''Basic IO''']] introduces two windows components '''Labels''' and '''Push button'''.


Label text can be dynamically changed hence provide user feedback.
Label text can be dynamically changed, providing user feedback.


The example shows how to change text using a push button and
The example shows how to change text using a push button and
introduces the Handler Function (callback function).


introduces the Handler Function (callback function).


'''''[[#top | Top]]'''''
|
|
[[Image:WinBinder_2.gif]]
[[Image:WinBinder_2.gif]]
Line 43: Line 41:
[[PHP WinBinder: Text input | '''Text input''']] allows a user to enter either a text string or numeric data.
[[PHP WinBinder: Text input | '''Text input''']] allows a user to enter either a text string or numeric data.


Included is the draw rectangle function this can be used for user feedback.
Included is the "draw rectangle" function. This can be used for user feedback.


Introduces a control's style parameter.
Introduces a control's style parameter.


'''''[[#top | Top]]'''''
|
|
[[Image:WinBinder_3.gif]]
[[Image:WinBinder_3.gif]]
Line 54: Line 51:
==== Tab Control 1 ====
==== Tab Control 1 ====
[[PHP WinBinder: Tab Control | '''Tab Control''']] allows a designer to split a single page application that has
[[PHP WinBinder: Tab Control | '''Tab Control''']] allows a designer to split a single page application that has
become too visually crowded into smaller logical pages.
become too visually crowded into smaller logical pages.
==== Tab Control 2 ====
==== Tab Control 2 ====
[[PHP WinBinder: Tab Control 2 | '''Tab Control 2''']] Looks at coding style Handles and ID’s concludes
[[PHP WinBinder: Tab Control 2 | '''Tab Control 2''']] Looks at coding style Handles and ID’s concludes
with a working template.
with a working template.


==== Tab Control 3 ====
==== Tab Control 3 ====
[[PHP WinBinder: Tab Control 3 | '''Tab Control 3''']] Covers adding cosmetics (static controls) a logo (icon)
[[PHP WinBinder: Tab Control 3 | '''Tab Control 3''']] Covers adding cosmetics (static controls) a logo (icon)
and some additional functionality to produce a specific application template.
and some additional functionality to produce a specific application template.
|
|
Line 71: Line 65:
==== Project 1 ====
==== Project 1 ====
[[PHP WinBinder: Project | '''Project 1''']] This page looks at creating a separate Windows application
[[PHP WinBinder: Project | '''Project 1''']] This page looks at creating a separate Windows application
independent of Uniform Server. Applications produced using this method,
independent of Uniform Server. Applications produced using this method,
 
are not compiled hence are not standalone executables. They require
are not compiled hence are not standalone executables they require
 
several support files.
several support files.


That said they are easy to program using PHP and Winbinder
That said, they are easy to program using PHP and Winbinder


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


==== Project 2 ====
==== Project 2 ====
[[PHP WinBinder: Alternative control 2 | '''Project 2''']] This page looks at Bat_To_Exe Converter from
[[PHP WinBinder: Alternative control 2 | '''Project 2''']] This page looks at Bat_To_Exe Converter from
Fatih Kodak combined with WinBinder produces a windows application coded in PHP without the need for compiling.


Fatih Kodak combined with WinBinder produces a windows
An entire windows project can be distributed and run as a single (exe) file.
 
application coded in PHP without the need for compiling.
 
An entire windows project can be distributed and run as
 
a single (exe) file.
|-valign="top"
|-valign="top"
|
|
Line 100: Line 84:


Uniform server 4-Mona series introduced UniController a simple Windows
Uniform server 4-Mona series introduced UniController a simple Windows
program written in C to control both Apache and MySQL servers.
program written in C to control both Apache and MySQL servers.


This page looks at converting this application into a WinBinder script.
This page looks at converting this application into a WinBinder script.


'''''[[#top | Top]]'''''
|
|
[[Image:UnicontrollerV2.gif]]
[[Image:UnicontrollerV2.gif]]
Line 114: Line 96:


It covers starting and stopping Apache and MySQL servers from a windows
It covers starting and stopping Apache and MySQL servers from a windows
application. It introduces the timer control and concludes with a fully
application. It introduces the timer control and concludes with a fully
functional server.
functional server.


'''''[[#top | Top]]'''''
|
|
[[Image:WinBinder_Unicon_1.gif]]
[[Image:WinBinder_Unicon_1.gif]]
Line 126: Line 105:
=== Alternative control 3 ===
=== Alternative control 3 ===
[[PHP WinBinder: Alternative control 3 | '''Alternative control 3''']] Adding functionality to buttons Logs, Edit and Test
[[PHP WinBinder: Alternative control 3 | '''Alternative control 3''']] Adding functionality to buttons Logs, Edit and Test
requires access to several files that in turn require additional buttons. At a
requires access to several files that in turn require additional buttons. At a
later date you may require that extra button! Solution is to replace the three
later date you may require that extra button! Solution is to replace the three
buttons with a drop down menuthis requires minimal changes and offers
buttons with a drop down menuthis requires minimal changes and offers
expandability.
expandability.


'''''[[#top | Top]]'''''
|
|
[[Image:WinBinder_final.gif]]
[[Image:WinBinder_final.gif]]
|}
|}
'''''[[#top | Top]]'''''
=== Alternative control 4 ===
=== Alternative control 4 ===
[[PHP WinBinder: Alternative control 4 | '''Alternative control 4''']] WinBinder has a few limitations most of which can be worked around. One limitation, there is no direct way to detect that an application has been restored from the tray menu this page provides a solution.
[[PHP WinBinder: Alternative control 4 | '''Alternative control 4''']] WinBinder has a few limitations most of which can be worked around. One limitation, there is no direct way to detect that an application has been restored from the tray menu this page provides a solution.
Line 176: Line 149:
| ||'''bat2exe'''|| ||Bat to exe converter folder|| 
| ||'''bat2exe'''|| ||Bat to exe converter folder|| 
|-style="background:#f5f5f5;"
|-style="background:#f5f5f5;"
| ||  Bat_To_Exe_Converter.exe|| ||Utility program converts bat to exe||From Fatih Kodak
| ||  Bat_To_Exe_Converter.exe|| ||Utility program that converts bat to exe||From Fatih Kodak
|-style="background:#f5f5f5;"
|-style="background:#f5f5f5;"
| ||  Help [English].chm|| ||Utility documentation||From Fatih Kodak
| ||  Help [English].chm|| ||Utility documentation||From Fatih Kodak
Line 204: Line 177:
| || ||'''extensions'''||PHP extensions folder|| 
| || ||'''extensions'''||PHP extensions folder|| 
|-style="background:#f5f5f5;"
|-style="background:#f5f5f5;"
| || ||  php_winbinder.dll||WinBinder extention||From WinBinder.org see above.
| || ||  php_winbinder.dll||WinBinder extention||From WinBinder.org; see above.
|-style="background:#f5f5f5;"
|-style="background:#f5f5f5;"
| || ||  php_curl.dll|| ||From PHP 5.3.1
| || ||  php_curl.dll|| ||From PHP 5.3.1
Line 220: Line 193:
| || ||'''resources'''||WinBinder image resources folder|| From WinBinder-0.46.0.zip  
| || ||'''resources'''||WinBinder image resources folder|| From WinBinder-0.46.0.zip  
|}
|}
'''''[[#top | Top]]'''''
 
=== Adding PHP extensions ===
=== Adding PHP extensions ===
* Copy additional PHP extensions to folder UniServer\plugins\winbinder\php\'''extensions'''
* Copy additional PHP extensions to folder UniServer\plugins\winbinder\php\'''extensions'''
Line 239: Line 212:
Add lines similar to the first line (enables an extension)
Add lines similar to the first line (enables an extension)


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


=== Modification to winbinder.php ===
=== Modification to winbinder.php ===
When WinBinder was written PHP 5.3.1 did not exist hence file UniServer\plugins\winbinder\php\include\'''winbinder.php'''
When WinBinder was written, PHP 5.3.1 did not exist hence the file UniServer\plugins\winbinder\php\include\'''winbinder.php'''
 
has been modified to remove PHP version checking. The following section was removed:
has been modified to remove PHP version checking. The following section was removed:
{|
{|
Line 262: Line 233:


== Plugin Components ==
== Plugin Components ==
This section is included for completeness, it provides details where to obtain the plugin components.
This section is included for completeness. It provides details on where to obtain the plugin components.


'''''[[#top | Top]]'''''
=== Bat To Exe Converter ===
=== Bat To Exe Converter ===
A utility to convert a batch file to an executable.  
A utility to convert a batch file to an executable.  
Although not open source, it is an excellent freeware utility.


Although not open source is an excellent freeware utility.
Download [http://www.f2ko.de/English/index.php  Bat To Exe Converter] version 1.5.0.0, dated 18.02.2009
 
Download [http://www.f2ko.de/English/index.php  Bat To Exe Converter] version 1.5.0.0 date 18.02.2009


'''''[[#top | Top]]'''''
=== WinBinder ===
=== WinBinder ===
WinBinder is an extension to PHP for building native Windows graphical user interfaces.
WinBinder is an extension to PHP for building native Windows graphical user interfaces.
Although currently at alpha design stage, it is fully functional. A minor change is required to disable the PHP version check.


Although currently at alpha design stage is fully functional. A minor change is required to disable PHP version check.
Uniform Server's WinBinder plugin is a minimal solution. See the download for a complete version of WinBinder.
 
Uniform Server's WinBinder plugin is a minimal solution see download for a complete version of WinBinder.


Download [http://sourceforge.net/projects/winbinder/files/WinBinder/Version%200.46.0/WinBinder-0.46.0.zip/download WinBinder-0.46.0.zip]
Download [http://sourceforge.net/projects/winbinder/files/WinBinder/Version%200.46.0/WinBinder-0.46.0.zip/download WinBinder-0.46.0.zip]
'''''[[#top | Top]]'''''


=== DLL ===
=== DLL ===
A core component of WinBinder is the PHP extension '''php_winbinder.dll'''
A core component of WinBinder is the PHP extension '''php_winbinder.dll'''
Be sure you use a compiled extension that matches the version of PHP.


Depending on the PHP version you use ensure you use a matching compiled extension.
Your first port of call is [http://winbinder.org/forum/ WinBinder.org].
 
Your first port of call is [http://winbinder.org/forum/ WinBinder.org]  
 
Check out [http://winbinder.org/forum/viewtopic.php?f=10&t=1058 this page] for a compatible version.
Check out [http://winbinder.org/forum/viewtopic.php?f=10&t=1058 this page] for a compatible version.


'''''Note'':'''
'''''Note'':'''
* Binary used in this plugin was compiled by Alec Gorge "WinBinder forum name alecgorge" (Sun Dec 13, 2009 4:05 am) found on the above page
* The binary used in this plugin was compiled by Alec Gorge (WinBinder forum name "alecgorge") (Sun Dec 13, 2009 4:05 am) found on the above page
* Download page http://www.mediafire.com/?3g2dwayg4zm
* Download page http://www.mediafire.com/?3g2dwayg4zm
* Compiled for PHP 5.3.1 V6 TS
* Compiled for PHP 5.3.1 V6 TS
Alec's web site [http://ramblingwood.com Ramblingwood]
Alec's web site is [http://ramblingwood.com Ramblingwood]
 
'''''[[#top | Top]]'''''


=== PHP ===
=== PHP ===
Line 308: Line 269:
Depending on your Windows application requirements you may require additional extensions hence its worth downloading a full version of PHP.
Depending on your Windows application requirements you may require additional extensions hence its worth downloading a full version of PHP.


'''''[[#top | Top]]'''''
== Summary ==
== Summary ==
The above introduced WinBinder and shows how easy the plugin is to install.  
The above introduction to WinBinder shows how easy the plugin is to install.  


Each Windows application starts with a basic script (template) covered on the [[PHP WinBinder: Template | '''next page''']].
Each Windows application starts with a basic script (template) covered on the [[PHP WinBinder: Template | '''next page''']].

Revision as of 13:00, 29 January 2010

 

UniServer 5-Nano
PHP WinBinder.

WinBinder Plugin Introduction

PHP’s command line interface “CLI” is extremely powerful, however using a command window for user interfacing is restrictive. An ideal solution would be to use a Windows interface.

WinBinder provides a neat solution. It remains actively supported by the open source community. Of importance, the WinBinder extension php_winbinder.dll is being compiled for new versions of PHP (currently 5.3.1), hence WinBinder is alive and kicking.

This plugin uses WinBinder to provide a PHP CLI Windows interface. It intentionally does not include a compiler. If you wish to produce standalone code, check out PHC-Win.

Windows applications are generally coded in “C”, so before they can be executed, they must be compiled. In contrast this self-contained plugin uses WinBinder, allowing an application to be coded in PHP. This has the advantage of providing a common language for web-design, control architecture and user interface. It eliminates the need to learn a new language.

The WinBinder plugin is self-contained allowing it to be run independently of Uniform Server. However it is designed to fit neatly into Uniform Server’s control architecture thus providing an alternative control interface. If space is at a premium the plugin can be overlayed onto Uniform Server allowing it to use the existing PHP core (VC6).

During development, windows scripts are run using a batch file. This batch file can be converted to an .exe using a small utility program included with the plugin.

Tutorial

This tutorial explains how to use the plugin and introduces some basics of windows programming using WinBinder.

An emphasis is on scripting, so I have avoided the complexity of compiling a windows application. Even with this restriction you can deploy a single file windows application; all necessary files are compressed using the included utility.

The tutorial format is based around working examples; first basic principles are explained, followed by a working script you can run.

Topics covered

Basic IO

Basic IO introduces two windows components Labels and Push button.

Label text can be dynamically changed, providing user feedback.

The example shows how to change text using a push button and introduces the Handler Function (callback function).


Text input

Text input allows a user to enter either a text string or numeric data.

Included is the "draw rectangle" function. This can be used for user feedback.

Introduces a control's style parameter.

Tab Control 1

Tab Control allows a designer to split a single page application that has become too visually crowded into smaller logical pages.

Tab Control 2

Tab Control 2 Looks at coding style Handles and ID’s concludes with a working template.

Tab Control 3

Tab Control 3 Covers adding cosmetics (static controls) a logo (icon) and some additional functionality to produce a specific application template.

Project 1

Project 1 This page looks at creating a separate Windows application independent of Uniform Server. Applications produced using this method, are not compiled hence are not standalone executables. They require several support files.

That said, they are easy to program using PHP and Winbinder


Project 2

Project 2 This page looks at Bat_To_Exe Converter from Fatih Kodak combined with WinBinder produces a windows application coded in PHP without the need for compiling.

An entire windows project can be distributed and run as a single (exe) file.

Alternative control 1

Alternative control 1

Uniform server 4-Mona series introduced UniController a simple Windows program written in C to control both Apache and MySQL servers.

This page looks at converting this application into a WinBinder script.

Alternative control 2

Alternative control 2 This page is a continuation of the alternative control.

It covers starting and stopping Apache and MySQL servers from a windows application. It introduces the timer control and concludes with a fully functional server.

Alternative control 3

Alternative control 3 Adding functionality to buttons Logs, Edit and Test requires access to several files that in turn require additional buttons. At a later date you may require that extra button! Solution is to replace the three buttons with a drop down menuthis requires minimal changes and offers expandability.

Alternative control 4

Alternative control 4 WinBinder has a few limitations most of which can be worked around. One limitation, there is no direct way to detect that an application has been restored from the tray menu this page provides a solution.

More functionality is added to menu items using the versatile function wb_exec(). This function runs external programs with the option to pass parameters.

This page concludes the tutorial with a fully working alternative controller.

Top

Download and Install

The plugin is independent of Uniform Server and may be extracted to any location.

However if you wish to run the alternative control interface example it must be extracted to Uniform Server’s plugin folder as explained below.

Options 1

  1. Download file V55_WINBINDER_531VC6TS_1.0.exe from SourceForge
  2. Save the file to folder UniServer\plugins
  3. To extract files, double click on file V55_WINBINDER_531VC6TS_1.0.exe, no need to change the path.
  4. If you wish to save space delete V55_WINBINDER_531VC6TS_1.0.exe

Options 2

  1. Download file V55_WINBINDER_531VC6TS_1.0.zip from SourceForge
  2. Save to any folder (e.g. temp1)
  3. Extract files, navigate to folder winbinder
  4. Copy winbinder to Uniform Server's folder UniServer\plugins.
  5. If you wish to save space delete temp1

Top

Plugin Structure

The plugin has the following file-folder structure:

winbinder     Main Plugin folder NOTES
  bat2exe   Bat to exe converter folder  
    Bat_To_Exe_Converter.exe   Utility program that converts bat to exe From Fatih Kodak
    Help [English].chm   Utility documentation From Fatih Kodak
    uslogo.ico   icon for exe - optional (use your own)  
  examples   Tutorial examples  
    test_1.bat   Batch file to run test_1.phpwb See Wiki
    test_1.phpwb   First Tutorial example See Wiki
  php   PHP folder  
    php.exe   CLI command line interface From PHP 5.3.1
    php-win.exe   CLI command line interface (hidden) From PHP 5.3.1
    php5ts.dll   PHP Script Interpreter From PHP 5.3.1
    php-wb.ini   PHP configuration file for WinBinder Edit this to add extensions
    ssleay32.dll   cURL support From PHP 5.3.1
    libeay32.dll   cURL support From PHP 5.3.1
    extensions PHP extensions folder  
      php_winbinder.dll WinBinder extention From WinBinder.org; see above.
      php_curl.dll   From PHP 5.3.1
    include WinBinder includes folder;  
      wb_generic.inc.php General-purpose supporting functions From WinBinder-0.46.0.zip
      wb_resources.inc.php RC file parser: convert Windows resource file to WinBinder commands From WinBinder-0.46.0.zip
      wb_windows.inc.php Windows functions From WinBinder-0.46.0.zip
      winbinder.php Main inclusion file for WinBinder From WinBinder-0.46.0.zip
    resources WinBinder image resources folder From WinBinder-0.46.0.zip

Adding PHP extensions

  • Copy additional PHP extensions to folder UniServer\plugins\winbinder\php\extensions
  • Edit file UniServer\plugins\winbinder\php\php-wb.ini

The file contains the following:

[PHP]
extension=php_winbinder.dll
extension=php_curl.dll
extension_dir = "./extensions"
error_reporting = E_ALL | E_STRICT
date.timezone = "Europe/London"

Add lines similar to the first line (enables an extension)


Modification to winbinder.php

When WinBinder was written, PHP 5.3.1 did not exist hence the file UniServer\plugins\winbinder\php\include\winbinder.php has been modified to remove PHP version checking. The following section was removed:

$supported_php_version = preg_match(
    '"^(' . '4\.(3\.(10|11)|4\..)' . '|' . '5\.(1\.[3-5]|1\..)' . ')$"', PHP_VERSION
);

if (!$supported_php_version)
	die("WinBinder does only support the following PHP versions:\n"
		. "- 4.3.10 up to excluding 5.0.0\n- 5.0.3  up to excluding 6.0.0\n");

Top

Plugin Components

This section is included for completeness. It provides details on where to obtain the plugin components.

Bat To Exe Converter

A utility to convert a batch file to an executable. Although not open source, it is an excellent freeware utility.

Download Bat To Exe Converter version 1.5.0.0, dated 18.02.2009

WinBinder

WinBinder is an extension to PHP for building native Windows graphical user interfaces. Although currently at alpha design stage, it is fully functional. A minor change is required to disable the PHP version check.

Uniform Server's WinBinder plugin is a minimal solution. See the download for a complete version of WinBinder.

Download WinBinder-0.46.0.zip

DLL

A core component of WinBinder is the PHP extension php_winbinder.dll Be sure you use a compiled extension that matches the version of PHP.

Your first port of call is WinBinder.org. Check out this page for a compatible version.

Note:

  • The binary used in this plugin was compiled by Alec Gorge (WinBinder forum name "alecgorge") (Sun Dec 13, 2009 4:05 am) found on the above page
  • Download page http://www.mediafire.com/?3g2dwayg4zm
  • Compiled for PHP 5.3.1 V6 TS

Alec's web site is Ramblingwood

PHP

The following components are required obtain these from the full PHP 5.3.1 package or from Uniform Server 5.5-Nano:

  • php.exe
  • php-win.exe
  • php5ts.dll

Depending on your Windows application requirements you may require additional extensions hence its worth downloading a full version of PHP.

Summary

The above introduction to WinBinder shows how easy the plugin is to install.

Each Windows application starts with a basic script (template) covered on the next page.

Top