https://wiki.uniformserver.com/index.php?title=PHP_WinBinder:_Basic_IO&feed=atom&action=historyPHP WinBinder: Basic IO - Revision history2024-03-29T09:17:04ZRevision history for this page on the wikiMediaWiki 1.41.0https://wiki.uniformserver.com/index.php?title=PHP_WinBinder:_Basic_IO&diff=4081&oldid=prevBobS: Proofreading and grammatical changes; some minor reformatting2010-01-29T13:58:40Z<p>Proofreading and grammatical changes; some minor reformatting</p>
<a href="https://wiki.uniformserver.com/index.php?title=PHP_WinBinder:_Basic_IO&diff=4081&oldid=4061">Show changes</a>BobShttps://wiki.uniformserver.com/index.php?title=PHP_WinBinder:_Basic_IO&diff=4061&oldid=prevRic: New page: {{Nav PHP WinBinder}} '''''Basic Input and Output''''' Most applications are designed to provide some form of interaction with a user. This can be a simple change of text indicating somet...2010-01-28T07:20:18Z<p>New page: {{Nav PHP WinBinder}} '''''Basic Input and Output''''' Most applications are designed to provide some form of interaction with a user. This can be a simple change of text indicating somet...</p>
<p><b>New page</b></p><div>{{Nav PHP WinBinder}}<br />
'''''Basic Input and Output'''''<br />
<br />
Most applications are designed to provide some form of interaction with a user. This can be a simple change of text indicating something happened when a button is click. May be the result requires a more significant attention grabber such as an alert box.<br />
<br />
This page shows how to create three changeable text areas, three buttons and an alert pop-up box<br />
<br />
== Cotrol Creation ==<br />
The manual provides this function to create controls:<br />
{|<br />
|-<br />
|<pre><br />
int wb_create_control (int parent, int ctlclass [, mixed caption [, int xpos [, int ypos [, int width<br />
[, int height [, int id [, int style [, int param [, int ntab]]]]]]]]])<br />
</pre><br />
|}<br />
On first encounter it looks intimidating hence I have reduced it to give this:<br />
{|<br />
|-<br />
|<pre><br />
handle = wb_create_control(parent,ctlclass,caption,xpos,ypos,width,height,id)<br />
</pre><br />
|}<br />
=== Parameters ===<br />
{|<br />
|-<br />
|'''parent'''|| is a handle to the WinBinder object that is the parent window.<br />
|-<br />
|'''ctlclass'''|| is the class of the control or object to be created.<br />
|-<br />
|'''caption&nbsp;'''|| is either a string with the caption of the control, an array of captions, or an array of arrays with information, depending on the control class.<br />
|-<br />
|'''xpos,'''|| '''ypos''', '''width''' and '''height''' describe the position and dimensions of the control when required.<br />
|-<br />
|'''id'''|| is an integer that identifies the control. It must be unique if the control is to be processed by a callback function.<br />
|}<br />
That’s all very well but how does it all fit together?<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Labels ==<br />
Labels are areas on a window containing text.<br />
<br />
They can be static (not changeable) however once given an ID and optionally grabbing their handle you can have dynamic text areas hence dynamic feedback to a user.<br />
<br />
Example 2 defines the following labels:<br />
{|<br />
|-<br />
|<br />
<pre><br />
<br />
$label1 = wb_create_control($mainwin, Label, "Apache Port = ", 5, 20, 112, 20, 101);<br />
$label2 = wb_create_control($mainwin, Label, "MySQL Port = ", 5, 40, 112, 20, 102);<br />
$text = "This is test 3 on two lines\nThis is test 3 on two lines";<br />
$label3 = wb_create_control($mainwin, Label, $text, 5, 60, 140, 40, 103);<br />
<br />
</pre><br />
|<br />
* Each label has a unique ID 101,102,103<br />
* handles are captured in variables $label1,$label2 and $label3 these are optional<br />
* You can find a components handle using it's ID for example '''wb_get_control($window, 102)'''<br />
|}<br />
<br />
'''''Parameters'''''<br />
{|<br />
|-<br />
|'''parent'''|| handle to the WinBinder object '''$mainwin'''<br />
|-<br />
|'''ctlclass'''|| is the class of the control or object to be created '''Label'''<br />
|-<br />
|'''caption&nbsp;'''|| A string (Test 1,Test 2) note for label3 uses variable '''$text'''<br />
|-<br />
|'''xpos,'''|| '''ypos''', '''width''' and '''height''' Tweak the values to position text. Note if text is to large to fit in a box it is clipped.<br />
|-<br />
|'''id'''|| A unique integer identifies a control. Start from 100 to avoid clashes. Say labels will be 100 push buttons start at 200 etc<br />
|}<br />
<br />
OK! So where does this code go? Place it it section two of the template. Once the main window is created the components need to be created before they can be used.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Push Bottoms ==<br />
Strange as this may seem push buttons are similar to labels in terms of creation. WinBinder has unified the creation process hence only a few logical chances.<br />
<br />
Example 2 defines the following push buttons:<br />
{|<br />
|-<br />
|<br />
<pre><br />
<br />
$button1 = wb_create_control($mainwin, PushButton, "Apache", 20, 120, 80, 22, 201);<br />
$button2 = wb_create_control($mainwin, PushButton, "MySQL", 110, 120, 80, 22, 202);<br />
$button3 = wb_create_control($mainwin, PushButton, "Alert", 200, 120, 80, 22, 203);<br />
<br />
</pre><br />
|<br />
* Each push button has a unique ID 201,202,203<br />
* No need to capture handles. Each button is traceable by its ID<br />
|}<br />
<br />
'''''Parameters'''''<br />
{|<br />
|-<br />
|'''parent'''|| handle to the WinBinder object '''$mainwin'''<br />
|-<br />
|'''ctlclass'''|| is the class of the control or object to be created '''PushButton'''<br />
|-<br />
|'''caption&nbsp;'''|| A string (Apache,MySQL and Alert)<br />
|-<br />
|'''xpos,'''|| '''ypos''', '''width''' and '''height''' Tweak the values to position a button. Note if a button is too small text is clipped. <br />
|-<br />
|'''id'''|| A unique integer identifies a control. Start from 100 to avoid clashes. Say labels will be 100 push buttons start at 200 etc<br />
|}<br />
<br />
OK! So where does this code go? Same place as the labels in section two of the template. <br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Interaction ==<br />
{|<br />
|-valign="top"<br />
|<br />
At this stage running the script will produce a window as shown on the right.<br />
<br />
Although the buttons are active they appear to do nothing when clicked.<br />
<br />
However behind the scenes they call function '''process_main()''' with parameters '''$window''' and '''$id''' ($id = ID of the button). The function contains no supporting code hence just returns. Lets specify what the buttons will do and then add code to the function. <br />
<br />
'''''Button Specification'''''<br />
* '''Apache''' When clicked changes label1 to display “Apache Port = 80” <br />
* '''MySQL''' When clicked changes label2 to display “MySQL Port = 3306”<br />
* '''Alert''' When clicked produces a pop-up alert box with message “Cannot run two servers on port 80” also changes both labels back to initial condition.<br />
|<br />
[[Image:WinBinder_2.gif]]<br />
|}<br />
'''''[[#top | Top]]'''''<br />
=== Handler function - code ===<br />
To resolve ID’s the handler function uses a switch statement.<br />
<br />
This is not a strict requirement you can use whatever method that suites your style of programming.<br />
<br />
However in response to ID=IDCLOSE you must run function wb_destroy_window($window) <br />
<br />
'''''[[#top | Top]]'''''<br />
==== Changing Label text ====<br />
Our specification requires changing label text WinBinder provides the following general function:<br />
{|<br />
|-<br />
|<br />
<pre><br />
bool wb_set_text (int wbobject, mixed text [, int item [, int subitem]])<br />
</pre><br />
|}<br />
{|<br />
|-<br />
|<br />
A simpler description as follows:<br />
|<br />
<pre><br />
wb_set_text(handle,"some text");<br />
</pre><br />
|}<br />
When the labels are created their handles are captured in variables these are global hence can be used in the Handler Function.<br />
<br />
If the handles were not assigned to variables they can be found using this function:<br />
{|<br />
|-<br />
|<br />
<pre><br />
int wb_get_control (int wbobject [, int id])<br />
<br />
Returns an integer handle that corresponds to the WinBinder object (control, toolbar item<br />
or menu item) wbobject that has the supplied id. This function is typically used to<br />
retrieve the handle of a child control in a dialog box or in a menu item.<br />
</pre><br />
|}<br />
See example below:<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
==== Apache button ====<br />
Handler code for Apache button:<br />
{|<br />
|-<br />
|<br />
<pre><br />
case 201: // Apache button<br />
wb_set_text(wb_get_control($window, 101),"Apache Port = 80");<br />
break;<br />
</pre><br />
|<br />
* When Apache Button is clicked case 201 (Button ID=201)is true.<br />
* The label text is updated with function wb_set_text(). The label handle is obtained using its ID (101)<br />
* break exits switch<br />
|}<br />
<br />
'''''[[#top | Top]]'''''<br />
==== MySQL Button ====<br />
Handler code for MySQL button:<br />
{|<br />
|-<br />
|<br />
<pre><br />
case 202: // MySQL button<br />
global $label2; <br />
wb_set_text($label2,"MySQL Port = 3306");<br />
break;<br />
</pre><br />
|<br />
* When MySQL Button is clicked case 202 (Button ID=202)is true.<br />
* global $label2; Gives access to label 2 handle <br />
* The label text is updated with function wb_set_text(). The label handle is directly used<br />
* break exits switch<br />
|}<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
==== Alert Button ====<br />
{|<br />
|-<br />
|<br />
<pre><br />
<br />
<br />
case 203: // Alert button<br />
global $label1;<br />
global $label2; <br />
wb_set_text($label1,"Apache Port =");<br />
wb_set_text($label2,"MySQL Port =");<br />
wb_message_box($window, "Cannot run two servers on port 80.","ALERT Test 2");<br />
break;<br />
<br />
<br />
</pre><br />
|<br />
* When Alert Button is clicked case 203 (Button ID=203)is true.<br />
* global $label1; Gives access to label 1 handle <br />
* global $label2; Gives access to label 2 handle <br />
* Label text is restored to default values. Label handles are directly used<br />
* Function wb_message_box() produces a pop-up box. Text "Cannot run two servers on port 80." is displayed. The box has a title "ALERT Test 2" <br />
* break exits switch<br />
|}<br />
'''''[[#top | Top]]'''''<br />
<br />
== Test 2 Script ==<br />
Final script as shown below:<br />
{|<br />
|-valign="top"<br />
|<br />
<pre><br />
<?php<br />
Include "../php/include/winbinder.php"; // Location Of Winbinder Library<br />
<br />
//=== 1) Create main window ---------------------------------------------------<br />
$mainwin = wb_create_window(NULL, AppWindow, "Test 2", 320, 240);<br />
<br />
//=== 2) Create controls for the main window ----------------------------------<br />
<br />
$label1 = wb_create_control($mainwin, Label, "Apache Port = ", 5, 20, 112, 20, 101);<br />
$label2 = wb_create_control($mainwin, Label, "MySQL Port = ", 5, 40, 112, 20, 102);<br />
$text = "This is test 3 on two lines\nThis is test 3 on two lines";<br />
$label3 = wb_create_control($mainwin, Label, $text, 5, 60, 140, 40, 103);<br />
<br />
$button1 = wb_create_control($mainwin, PushButton, "Apache", 20, 120, 80, 22, 201);<br />
$button2 = wb_create_control($mainwin, PushButton, "MySQL", 110, 120, 80, 22, 202);<br />
$button3 = wb_create_control($mainwin, PushButton, "Alert", 200, 120, 80, 22, 203);<br />
<br />
//=== 3) Assign handler function to the main window --------------------------<br />
wb_set_handler($mainwin, "process_main"); <br />
<br />
//=== 5) Enter application loop -----------------------------------------------<br />
wb_main_loop(); <br />
<br />
<br />
//=== 4) Handler Function -----------------------------------------------------<br />
function process_main($window, $id) <br />
{<br />
global $label1; <br />
<br />
switch($id) { <br />
<br />
case 201: // Apache button<br />
wb_set_text(wb_get_control($window, 101),"Apache Port = 80");<br />
break;<br />
<br />
case 202: // MySQL button<br />
global $label2; <br />
wb_set_text($label2,"MySQL Port = 3306");<br />
break;<br />
<br />
case 203: // Alert button<br />
global $label1;<br />
global $label2; <br />
wb_set_text($label1,"Apache Port =");<br />
wb_set_text($label2,"MySQL Port =");<br />
wb_message_box($window, "Cannot run two servers on port 80.","ALERT Test 2");<br />
break;<br />
<br />
case IDCLOSE: // Constant IDCLOSE (8) predefined <br />
wb_destroy_window($window); // Destroy the window<br />
break; <br />
}<br />
}<br />
?><br />
</pre><br />
|<br />
&nbsp;<br />
|<br />
<br /><br />
'''''Script'':'''<br />
<br />
'''test_2.phpw'''<br />
<br />
'''''Run'':'''<br />
<br />
Navigate to folder<br />
<br />
UniServer\plugins\winbinder\'''examples'''<br />
<br />
Double click on '''test_2.bat'''<br />
<br />
|}<br />
'''''[[#top | Top]]'''''<br />
<br />
== Summary ==<br />
This page introduced two basic controls, labels and push buttons. Even with this minimum set of controls it is possible to produce useful applications.<br />
<br />
What’s important you really do not require all the fancy bells and whistles as found on most windows applications.<br />
That said WinBinder provides a vast array of controls you can use these are fully described in the documentation.<br />
<br />
The [[PHP WinBinder: Text input | '''next page''']] covers text input. <br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
----<br />
<br />
[[Category: Tutorials]]<br />
[[Category: How To]]<br />
[[Category: Uniform Server 5.0-Nano]]</div>Ric