PHP WinBinder 2: Add code

Revision as of 07:33, 28 January 2010 by Ric (talk | contribs) (New page: {{Nav PHP WinBinder 2}} '''''WinBinder Part 2 Adding code and files''''' On the previous page we finished with a bare windows application containing two buttons and indicators. This page...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

 

UniServer 5-Nano
PHP WinBinder 2.

WinBinder Part 2 Adding code and files

On the previous page we finished with a bare windows application containing two buttons and indicators.

This page looks at adding functionality to these buttons. Code will be split across several include files, sole purpose is to demonstrate capabilities of PHC-Win covered on the next page.

Top

Individual files

Individual files are added to C:\us_wb\my_app\z_basic.phpw as shown below:

Include "../wb/php/include/winbinder.php";       // Location Of Winbinder Library

Include "button_1_toggle.inc.php";
Include "button_2_toggle.inc.php";
Include "red_1_on.inc.php";
Include "red_2_on.inc.php";
Include "green_1_on.inc.php";
Include "green_2_on.inc.php";

There are six in all each containing a single function as follows:

button_1_toggle.inc.php

<?php
function button_1_toggle(){
 global $mainwin;

   $text = wb_get_text(wb_get_control($mainwin, IDC_BUTTONRED1));   // get button txt
   if($text == 'Red 1'){ 
     red_1_on();
     wb_set_text(wb_get_control($mainwin, IDC_BUTTONRED1),'Green 1'); // Change button text
   }
   if($text == 'Green 1'){ 
     green_1_on();
     wb_set_text(wb_get_control($mainwin, IDC_BUTTONRED1),'Red 1'); // Change button text
   }
}
?>

Top

button_2_toggle.inc.php

<?php
function button_2_toggle(){
 global $mainwin;

   $text = wb_get_text(wb_get_control($mainwin, IDC_BUTTONRED2));   // get button txt
   if($text == 'Red 2'){ 
     red_2_on();
     wb_set_text(wb_get_control($mainwin, IDC_BUTTONRED2),'Green 2'); // Change button text
   }
   if($text == 'Green 2'){ 
     green_2_on();
     wb_set_text(wb_get_control($mainwin, IDC_BUTTONRED2),'Red 2'); // Change button text
   }
}
?>

Top

red_1_on.inc.php

<?php
function red_1_on(){
 global $mainwin;
 wb_set_visible(wb_get_control($mainwin, IDC_FRAMERED1),TRUE);;   // red 1 on
 wb_set_visible(wb_get_control($mainwin, IDC_FRAMEGREEN1),FALSE); // green 1 off
}
?>

Top

red_2_on.inc.php

<?php
function red_2_on(){
 global $mainwin;
 wb_set_visible(wb_get_control($mainwin, IDC_FRAMERED2),TRUE);;   // red 2 on
 wb_set_visible(wb_get_control($mainwin, IDC_FRAMEGREEN2),FALSE); // green 2 off
}
?>

Top

green_1_on.inc.php

<?php
function green_1_on(){
 global $mainwin;
 wb_set_visible(wb_get_control($mainwin, IDC_FRAMERED1),FALSE);;   // red 1 off
 wb_set_visible(wb_get_control($mainwin, IDC_FRAMEGREEN1),TRUE); // green 1 on
}
?>

Top

green_2_on.inc.php

<?php
function green_2_on(){
 global $mainwin;
 wb_set_visible(wb_get_control($mainwin, IDC_FRAMERED2),FALSE);;   // red 2 off
 wb_set_visible(wb_get_control($mainwin, IDC_FRAMEGREEN2),TRUE); // green 2 on
}
?>

Top

  • Run C:\us_wb\my_app\z_basic.bat
  • Each button toggles between Red and Green.
  • Each indicator toggles between Red and Green.

 

Top

Summary

That completes our masterpiece it is now ready for packaging and distribution.

Next page covers PHC-Win which makes the whole process very easy.

Top