PHP WinBinder: Tab Control 3: 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://ipelasuq.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]=
{{Nav PHP WinBinder}}
{{Nav PHP WinBinder}}
'''''Tab Control 3'''''
'''''Tab Control 3'''''
Line 21: Line 22:


For example:
For example:
<pre>
&lt;pre&gt;
wb_create_control($tab, Frame, "Change",  185, 14,  92, 110, 0, 0, 0);  // create frame
wb_create_control($tab, Frame, &quot;Change&quot;,  185, 14,  92, 110, 0, 0, 0);  // create frame
wb_create_control($tab, Frame, "",          0,  0, 295, 173, 0, 0, 0);  // create frame
wb_create_control($tab, Frame, &quot;&quot;,          0,  0, 295, 173, 0, 0, 0);  // create frame
</pre>
&lt;/pre&gt;
The above code will add two frames to tab index 0 (first page)
The above code will add two frames to tab index 0 (first page)


Line 30: Line 31:
== Single application instance ==
== Single application instance ==
A single instance application can use this function:
A single instance application can use this function:
<pre>
&lt;pre&gt;
bool wb_get_instance (string caption [, bool bringtofront])
bool wb_get_instance (string caption [, bool bringtofront])
</pre>
&lt;/pre&gt;
Each main window of all WinBinder applications stores a 32-bit identifier that is calculated according to the initial window caption and is unique to that caption.  
Each main window of all WinBinder applications stores a 32-bit identifier that is calculated according to the initial window caption and is unique to that caption.  


Line 38: Line 39:


For example this code was added to test 6
For example this code was added to test 6
<pre>
&lt;pre&gt;
//=== 1) Create main window ---------------------------------------------------
//=== 1) Create main window ---------------------------------------------------
define("CAPTION", "Test 6");            // Set caption to match application
define(&quot;CAPTION&quot;, &quot;Test 6&quot;);            // Set caption to match application
if(wb_get_instance(CAPTION, TRUE))      // Is there an existing instance?
if(wb_get_instance(CAPTION, TRUE))      // Is there an existing instance?
     die;                                // Yes: bring it to the front and quit
     die;                                // Yes: bring it to the front and quit
</pre>
&lt;/pre&gt;
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Add a logo-icon ==
== Add a logo-icon ==
Line 50: Line 51:
For example, this code was added to test 6
For example, this code was added to test 6


<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;./&quot; . &quot;uslogo.ico&quot;);      // Add logo
</pre>
&lt;/pre&gt;
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Application minimizes to system tray ==
== Application minimizes to system tray ==
Line 60: Line 61:


For example, the original line was:
For example, the original line was:
<pre>
&lt;pre&gt;
$mainwin = wb_create_window(NULL, AppWindow, "Test 6", 320, 240);
$mainwin = wb_create_window(NULL, AppWindow, &quot;Test 6&quot;, 320, 240);
</pre>
&lt;/pre&gt;
Change to this:
Change to this:
<pre>
&lt;pre&gt;
$mainwin = wb_create_window(NULL, AppWindow, "Test 6", WBC_CENTER, WBC_CENTER, 320, 240, WBC_TASKBAR);
$mainwin = wb_create_window(NULL, AppWindow, &quot;Test 6&quot;, WBC_CENTER, WBC_CENTER, 320, 240, WBC_TASKBAR);
</pre>
&lt;/pre&gt;
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Tab change detection ==
== Tab change detection ==
Line 77: Line 78:


The following was changed:
The following was changed:
<pre>
&lt;pre&gt;
$mainwin = wb_create_window(NULL, AppWindow, "Test 6", WBC_CENTER, WBC_CENTER, 320, 240, WBC_TASKBAR);
$mainwin = wb_create_window(NULL, AppWindow, &quot;Test 6&quot;, WBC_CENTER, WBC_CENTER, 320, 240, WBC_TASKBAR);
</pre>
&lt;/pre&gt;
To this:
To this:
<pre>
&lt;pre&gt;
$mainwin = wb_create_window(NULL, AppWindow, "Test 6", WBC_CENTER, WBC_CENTER, 320, 240, WBC_NOTIFY| WBC_TASKBAR , WBC_HEADERSEL );
$mainwin = wb_create_window(NULL, AppWindow, &quot;Test 6&quot;, WBC_CENTER, WBC_CENTER, 320, 240, WBC_NOTIFY| WBC_TASKBAR , WBC_HEADERSEL );
</pre>
&lt;/pre&gt;
* When a tab is clicked, the main tab ID is sent back to the handler function
* When a tab is clicked, the main tab ID is sent back to the handler function
* In addition the tab index is set to $lparm2
* In addition the tab index is set to $lparm2
Line 91: Line 92:


This line:
This line:
<pre>
&lt;pre&gt;
function process_main($window, $id)
function process_main($window, $id)
</pre>
&lt;/pre&gt;
Changes to this:
Changes to this:
<pre>
&lt;pre&gt;
function process_main($window, $id, $ctrl=0, $lparam1=0, $lparam2=0)
function process_main($window, $id, $ctrl=0, $lparam1=0, $lparam2=0)
</pre>
&lt;/pre&gt;


=== Test Code ===
=== Test Code ===
{|
{|
|-valign="top"
|-valign=&quot;top&quot;
|
|
<pre>
&lt;pre&gt;
   // TAB Change - Test
   // TAB Change - Test
   case 9000; //                                                ID of main TAB
   case 9000; //                                                ID of main TAB
   $text="ID = $id \n CTRL = $ctrl \n PARAM1 = $lparam1 \n PARAM2 =  $lparam2 ";
   $text=&quot;ID = $id \n CTRL = $ctrl \n PARAM1 = $lparam1 \n PARAM2 =  $lparam2 &quot;;
   wb_message_box($window, $text,"TAB Pressed.", WBC_INFO);
   wb_message_box($window, $text,&quot;TAB Pressed.&quot;, WBC_INFO);


     switch($lparam2) {
     switch($lparam2) {


       case 0: // Tab index 0 or page 1
       case 0: // Tab index 0 or page 1
       wb_message_box($window, "Case 0","TAB 0 Page 1", WBC_OK); // Call init 1     
       wb_message_box($window, &quot;Case 0&quot;,&quot;TAB 0 Page 1&quot;, WBC_OK); // Call init 1     
       break;
       break;


       case 1: // Tab index 1 or page 2
       case 1: // Tab index 1 or page 2
       wb_message_box($window, "Case 1","TAB 1 Page 2", WBC_OKCANCEL); // Call init 2       
       wb_message_box($window, &quot;Case 1&quot;,&quot;TAB 1 Page 2&quot;, WBC_OKCANCEL); // Call init 2       
       break;
       break;


       case 2: // Tab index 2 or page 3
       case 2: // Tab index 2 or page 3
       wb_message_box($window, "Case 2","TAB 2 Page 3", WBC_WARNING); // Call init 3       
       wb_message_box($window, &quot;Case 2&quot;,&quot;TAB 2 Page 3&quot;, WBC_WARNING); // Call init 3       
       break;
       break;
     }   
     }   
Line 126: Line 127:
   break;
   break;
   // END TAB Change - Test
   // END TAB Change - Test
</pre>
&lt;/pre&gt;
|
|
<br />
&lt;br /&gt;
'''''Test code'''''
'''''Test code'''''


Line 145: Line 146:
== Test 6 Script ==
== Test 6 Script ==
{|
{|
|-valign="top"
|-valign=&quot;top&quot;
|
|
<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 ----------------------------------------------------------------


//ID's Page 1
//ID's Page 1
define("ID_L1101", 1101); //Label
define(&quot;ID_L1101&quot;, 1101); //Label
define("ID_L1102", 1102);
define(&quot;ID_L1102&quot;, 1102);
define("ID_E1301", 1301); // Edit box
define(&quot;ID_E1301&quot;, 1301); // Edit box
define("ID_PB1201", 1201); // Push button
define(&quot;ID_PB1201&quot;, 1201); // Push button
define("ID_PB1202", 1202); // Push button
define(&quot;ID_PB1202&quot;, 1202); // Push button
define("ID_PB1203", 1203); // Push button
define(&quot;ID_PB1203&quot;, 1203); // Push button


//ID's Page 2
//ID's Page 2
define("ID_L2101", 2101); //Label
define(&quot;ID_L2101&quot;, 2101); //Label
define("ID_L2102", 2102);
define(&quot;ID_L2102&quot;, 2102);
define("ID_E2301", 2301); // Edit box
define(&quot;ID_E2301&quot;, 2301); // Edit box
define("ID_PB2201", 2201); // Push button
define(&quot;ID_PB2201&quot;, 2201); // Push button
define("ID_PB2202", 2202); // Push button
define(&quot;ID_PB2202&quot;, 2202); // Push button
define("ID_PB2203", 2203); // Push button
define(&quot;ID_PB2203&quot;, 2203); // Push button


//ID's Page 3
//ID's Page 3
define("ID_L3101", 3101); //Label
define(&quot;ID_L3101&quot;, 3101); //Label
define("ID_L3102", 3102);
define(&quot;ID_L3102&quot;, 3102);
define("ID_E3301", 3301); // Edit box
define(&quot;ID_E3301&quot;, 3301); // Edit box
define("ID_PB3201", 3201); // Push button
define(&quot;ID_PB3201&quot;, 3201); // Push button
define("ID_PB3202", 3202); // Push button
define(&quot;ID_PB3202&quot;, 3202); // Push button
define("ID_PB3203", 3203); // Push button
define(&quot;ID_PB3203&quot;, 3203); // Push button


//=== 1) Create main window ---------------------------------------------------
//=== 1) Create main window ---------------------------------------------------
define("CAPTION", "Test 6");            // Set caption to match application
define(&quot;CAPTION&quot;, &quot;Test 6&quot;);            // Set caption to match application
if(wb_get_instance(CAPTION, TRUE))      // Is there an existing instance?
if(wb_get_instance(CAPTION, TRUE))      // Is there an existing instance?
     die;                                // Yes: bring it to the front and quit
     die;                                // Yes: bring it to the front and quit


$mainwin = wb_create_window(NULL, AppWindow, "Test 6", WBC_CENTER, WBC_CENTER, 320, 240, WBC_NOTIFY| WBC_TASKBAR , WBC_HEADERSEL );
$mainwin = wb_create_window(NULL, AppWindow, &quot;Test 6&quot;, WBC_CENTER, WBC_CENTER, 320, 240, WBC_NOTIFY| WBC_TASKBAR , WBC_HEADERSEL );


//=== 2) Create controls for the main window ----------------------------------
//=== 2) Create controls for the main window ----------------------------------
Line 190: Line 191:


//Create Tab 0 - Page 1
//Create Tab 0 - Page 1
wb_create_items($tab, "Page1");
wb_create_items($tab, &quot;Page1&quot;);
  wb_create_control($tab, Label,    "Test label A", 10, 14, 112, 20,  ID_L1101, 0, 0, 0);
  wb_create_control($tab, Label,    &quot;Test label A&quot;, 10, 14, 112, 20,  ID_L1101, 0, 0, 0);
  wb_create_control($tab, Label,    "Test label B", 10, 34, 112, 20,  ID_L1102, 0, 0, 0);
  wb_create_control($tab, Label,    &quot;Test label B&quot;, 10, 34, 112, 20,  ID_L1102, 0, 0, 0);
  wb_create_control($tab, EditBox,    "",            10, 54, 112, 20,  ID_E1301, 0, 0, 0);
  wb_create_control($tab, EditBox,    &quot;&quot;,            10, 54, 112, 20,  ID_E1301, 0, 0, 0);
  wb_create_control($tab, PushButton, "Button A",    10, 90,  80, 22,  ID_PB1201, 0, 0, 0);
  wb_create_control($tab, PushButton, &quot;Button A&quot;,    10, 90,  80, 22,  ID_PB1201, 0, 0, 0);
  wb_create_control($tab, PushButton, "Button B",  100, 90,  80, 22,  ID_PB1202, 0, 0, 0);
  wb_create_control($tab, PushButton, &quot;Button B&quot;,  100, 90,  80, 22,  ID_PB1202, 0, 0, 0);
  wb_create_control($tab, PushButton, "Button C",  190, 90,  80, 22,  ID_PB1203, 0, 0, 0);
  wb_create_control($tab, PushButton, &quot;Button C&quot;,  190, 90,  80, 22,  ID_PB1203, 0, 0, 0);


wb_create_control($tab, Frame, "Change", 185, 14,  92, 110, 0, 0, 0);  // create frame
wb_create_control($tab, Frame, &quot;Change&quot;, 185, 14,  92, 110, 0, 0, 0);  // create frame
wb_create_control($tab, Frame, "",          0,  0, 295, 173,  0, 0, 0); // create frame
wb_create_control($tab, Frame, &quot;&quot;,          0,  0, 295, 173,  0, 0, 0); // create frame


//Create Tab 1 - Page 2
//Create Tab 1 - Page 2
wb_create_items($tab, "Page2");
wb_create_items($tab, &quot;Page2&quot;);
  wb_create_control($tab, Label,    "Test label C", 10, 14, 112, 20,  ID_L2101, 0, 0, 1);
  wb_create_control($tab, Label,    &quot;Test label C&quot;, 10, 14, 112, 20,  ID_L2101, 0, 0, 1);
  wb_create_control($tab, Label,    "Test label D", 10, 34, 112, 20,  ID_L2102, 0, 0, 1);
  wb_create_control($tab, Label,    &quot;Test label D&quot;, 10, 34, 112, 20,  ID_L2102, 0, 0, 1);
  wb_create_control($tab, EditBox,    "",            10, 54, 112, 20,  ID_E2301, 0, 0, 1);
  wb_create_control($tab, EditBox,    &quot;&quot;,            10, 54, 112, 20,  ID_E2301, 0, 0, 1);
  wb_create_control($tab, PushButton, "Button D",    10, 90,  80, 22,  ID_PB2201, 0, 0, 1);
  wb_create_control($tab, PushButton, &quot;Button D&quot;,    10, 90,  80, 22,  ID_PB2201, 0, 0, 1);
  wb_create_control($tab, PushButton, "Button E",  100, 90,  80, 22,  ID_PB2202, 0, 0, 1);
  wb_create_control($tab, PushButton, &quot;Button E&quot;,  100, 90,  80, 22,  ID_PB2202, 0, 0, 1);
  wb_create_control($tab, PushButton, "Button F",  190, 90,  80, 22,  ID_PB2203, 0, 0, 1);
  wb_create_control($tab, PushButton, &quot;Button F&quot;,  190, 90,  80, 22,  ID_PB2203, 0, 0, 1);




//Create Tab 2 - Page 3
//Create Tab 2 - Page 3
wb_create_items($tab, "Page3");
wb_create_items($tab, &quot;Page3&quot;);
  wb_create_control($tab, Label,    "Test label E", 10, 14, 112, 20,  ID_L3101, 0, 0, 2);
  wb_create_control($tab, Label,    &quot;Test label E&quot;, 10, 14, 112, 20,  ID_L3101, 0, 0, 2);
  wb_create_control($tab, Label,    "Test label F", 10, 34, 112, 20,  ID_L3102, 0, 0, 2);
  wb_create_control($tab, Label,    &quot;Test label F&quot;, 10, 34, 112, 20,  ID_L3102, 0, 0, 2);
  wb_create_control($tab, EditBox,    "",            10, 54, 112, 20,  ID_E3301, 0, 0, 2);
  wb_create_control($tab, EditBox,    &quot;&quot;,            10, 54, 112, 20,  ID_E3301, 0, 0, 2);
  wb_create_control($tab, PushButton, "Button G",    10, 90,  80, 22,  ID_PB3201, 0, 0, 2);
  wb_create_control($tab, PushButton, &quot;Button G&quot;,    10, 90,  80, 22,  ID_PB3201, 0, 0, 2);
  wb_create_control($tab, PushButton, "Button H",  100, 90,  80, 22,  ID_PB3202, 0, 0, 2);
  wb_create_control($tab, PushButton, &quot;Button H&quot;,  100, 90,  80, 22,  ID_PB3202, 0, 0, 2);
  wb_create_control($tab, PushButton, "Button I",  190, 90,  80, 22,  ID_PB3203, 0, 0, 2);
  wb_create_control($tab, PushButton, &quot;Button I&quot;,  190, 90,  80, 22,  ID_PB3203, 0, 0, 2);




//=== 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;./&quot; . &quot;uslogo.ico&quot;);      // Add logo         


//=== 5) Enter application loop -----------------------------------------------
//=== 5) Enter application loop -----------------------------------------------
Line 235: Line 236:
   // TAB Change - Test
   // TAB Change - Test
   case 9000; //                                                ID of main TAB
   case 9000; //                                                ID of main TAB
   $text="ID = $id \n CTRL = $ctrl \n PARAM1 = $lparam1 \n PARAM2 =  $lparam2 ";
   $text=&quot;ID = $id \n CTRL = $ctrl \n PARAM1 = $lparam1 \n PARAM2 =  $lparam2 &quot;;
   wb_message_box($window, $text,"TAB Pressed.", WBC_INFO);
   wb_message_box($window, $text,&quot;TAB Pressed.&quot;, WBC_INFO);


     switch($lparam2) {
     switch($lparam2) {


       case 0: // Tab index 0 or page 1
       case 0: // Tab index 0 or page 1
       wb_message_box($window, "Case 0","TAB 0 Page 1", WBC_OK); // Call init 1     
       wb_message_box($window, &quot;Case 0&quot;,&quot;TAB 0 Page 1&quot;, WBC_OK); // Call init 1     
       break;
       break;


       case 1: // Tab index 1 or page 2
       case 1: // Tab index 1 or page 2
       wb_message_box($window, "Case 1","TAB 1 Page 2", WBC_OKCANCEL); // Call init 2       
       wb_message_box($window, &quot;Case 1&quot;,&quot;TAB 1 Page 2&quot;, WBC_OKCANCEL); // Call init 2       
       break;
       break;


       case 2: // Tab index 2 or page 3
       case 2: // Tab index 2 or page 3
       wb_message_box($window, "Case 2","TAB 2 Page 3", WBC_WARNING); // Call init 3       
       wb_message_box($window, &quot;Case 2&quot;,&quot;TAB 2 Page 3&quot;, WBC_WARNING); // Call init 3       
       break;
       break;
     }   
     }   
Line 258: Line 259:
   //== Page 1
   //== Page 1
   case ID_PB1201:        // Button A
   case ID_PB1201:        // Button A
   wb_set_text(wb_get_control($window, ID_L1101),"12345");
   wb_set_text(wb_get_control($window, ID_L1101),&quot;12345&quot;);
   wb_set_text(wb_get_control($window, ID_L1102),"67890");
   wb_set_text(wb_get_control($window, ID_L1102),&quot;67890&quot;);
   break;
   break;


   case ID_PB1202:        // Button B
   case ID_PB1202:        // Button B
   wb_set_text(wb_get_control($window, ID_L1101),"67890");
   wb_set_text(wb_get_control($window, ID_L1101),&quot;67890&quot;);
   wb_set_text(wb_get_control($window, ID_L1102),"12345");
   wb_set_text(wb_get_control($window, ID_L1102),&quot;12345&quot;);


   break;
   break;
Line 270: Line 271:
   case ID_PB1203:        // Button C
   case ID_PB1203:        // Button C
   $text1 = wb_get_text(wb_get_control($window, ID_E1301));
   $text1 = wb_get_text(wb_get_control($window, ID_E1301));
   wb_set_text(wb_get_control($window, ID_L1101),"Page 1 ".$text1);
   wb_set_text(wb_get_control($window, ID_L1101),&quot;Page 1 &quot;.$text1);
   wb_set_text(wb_get_control($window, ID_L1102),"Page 1 ".$text1);
   wb_set_text(wb_get_control($window, ID_L1102),&quot;Page 1 &quot;.$text1);
   break;
   break;


Line 289: Line 290:
   //== Page 3
   //== Page 3
   case ID_PB3201:        // Button G
   case ID_PB3201:        // Button G
     wb_message_box($window, "Page 3.","BUTTON G", WBC_INFO);
     wb_message_box($window, &quot;Page 3.&quot;,&quot;BUTTON G&quot;, WBC_INFO);
   break;
   break;


   case ID_PB3202:        // Button H
   case ID_PB3202:        // Button H
     wb_message_box($window, "Page 3.","BUTTON H", WBC_QUESTION);
     wb_message_box($window, &quot;Page 3.&quot;,&quot;BUTTON H&quot;, WBC_QUESTION);
   break;
   break;


   case ID_PB3203:        // Button I
   case ID_PB3203:        // Button I
     wb_message_box($window, "Page 3.","BUTTON I", WBC_YESNO);
     wb_message_box($window, &quot;Page 3.&quot;,&quot;BUTTON I&quot;, WBC_YESNO);
   break;
   break;


Line 308: Line 309:


function button_D($window){
function button_D($window){
   wb_set_text(wb_get_control($window, ID_L2101),"xxxx");
   wb_set_text(wb_get_control($window, ID_L2101),&quot;xxxx&quot;);
   wb_set_text(wb_get_control($window, ID_L2102),"yyyy");
   wb_set_text(wb_get_control($window, ID_L2102),&quot;yyyy&quot;);
}
}
function button_E($window){
function button_E($window){
   wb_set_text(wb_get_control($window, ID_L2101),"yyyy");
   wb_set_text(wb_get_control($window, ID_L2101),&quot;yyyy&quot;);
   wb_set_text(wb_get_control($window, ID_L2102),"xxxx");
   wb_set_text(wb_get_control($window, ID_L2102),&quot;xxxx&quot;);
}
}
function button_F($window){
function button_F($window){
   $text1 = wb_get_text(wb_get_control($window, ID_E2301));
   $text1 = wb_get_text(wb_get_control($window, ID_E2301));
   wb_set_text(wb_get_control($window, ID_L2101),"Page 2 ".$text1);
   wb_set_text(wb_get_control($window, ID_L2101),&quot;Page 2 &quot;.$text1);
   wb_set_text(wb_get_control($window, ID_L2102),"Page 2 ".$text1);
   wb_set_text(wb_get_control($window, ID_L2102),&quot;Page 2 &quot;.$text1);
}
}
?>
?&gt;


</pre>
&lt;/pre&gt;
|}
|}



Revision as of 01:14, 24 November 2010

Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly

 

UniServer 5-Nano
PHP WinBinder.

Tab Control 3

On the previous page we finished with a template script. This page covers converting that script into a Windows project script. This means the script is specifically targeting a real application.

Specification

The following modifications and functionality are required to script test_5.phpw

  • Static wire boxes for cosmetics
  • Only a single instance of the application allowed
  • Add a logo-icon to the application window and system tray icon.
  • Application minimizes to notification area (system tray) and not the Task Bar
  • Tab change detection required.

Top

Frame - Static wire boxes

A single control Frame produces a transparent framed box.

Adding a caption produces text top-left on upper edge.

If a caption is not provided the frame is completely closed.

For example: <pre> wb_create_control($tab, Frame, "Change", 185, 14, 92, 110, 0, 0, 0); // create frame wb_create_control($tab, Frame, "", 0, 0, 295, 173, 0, 0, 0); // create frame </pre> The above code will add two frames to tab index 0 (first page)

Top

Single application instance

A single instance application can use this function: <pre> bool wb_get_instance (string caption [, bool bringtofront]) </pre> Each main window of all WinBinder applications stores a 32-bit identifier that is calculated according to the initial window caption and is unique to that caption.

wb_get_instance() will try to find, among all current top-level windows, a WinBinder window that was created with the same caption. The function returns TRUE if it finds the existing window or FALSE if it is does not.

For example this code was added to test 6 <pre> //=== 1) Create main window --------------------------------------------------- define("CAPTION", "Test 6"); // Set caption to match application if(wb_get_instance(CAPTION, TRUE)) // Is there an existing instance?

   die;                                // Yes: bring it to the front and quit

</pre> Top

Add a logo-icon

You can added an image top left of the application using the function wb_set_image(parent,path to image)

For example, this code was added to test 6

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

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

</pre> Top

Application minimizes to system tray

To create a window that minimizes itself as an icon in the TaskBar status area, include the WBC_TASKBAR style flag in the style parameter of the wb_create_window function. All operations will be handled automatically.

For example, the original line was: <pre> $mainwin = wb_create_window(NULL, AppWindow, "Test 6", 320, 240); </pre> Change to this: <pre> $mainwin = wb_create_window(NULL, AppWindow, "Test 6", WBC_CENTER, WBC_CENTER, 320, 240, WBC_TASKBAR); </pre> Top

Tab change detection

The reason for detecting a tab change is to call a function and update any data on that page that may be out of date.

Tab detection requires additional messages to be passed back to the handler function. These are not enabled by default, and changes are required to both the window and handler functions.

Create Window Changes

A Windows application is instructed to pass additional messages using WBC_NOTIFY type of message defined by WBC_HEADERSEL

The following was changed: <pre> $mainwin = wb_create_window(NULL, AppWindow, "Test 6", WBC_CENTER, WBC_CENTER, 320, 240, WBC_TASKBAR); </pre> To this: <pre> $mainwin = wb_create_window(NULL, AppWindow, "Test 6", WBC_CENTER, WBC_CENTER, 320, 240, WBC_NOTIFY| WBC_TASKBAR , WBC_HEADERSEL ); </pre>

  • When a tab is clicked, the main tab ID is sent back to the handler function
  • In addition the tab index is set to $lparm2

Change Handler function parameters

The handler function requires changing to pass additional parameters.

This line: <pre> function process_main($window, $id) </pre> Changes to this: <pre> function process_main($window, $id, $ctrl=0, $lparam1=0, $lparam2=0) </pre>

Test Code

<pre>

 // TAB Change - Test
 case 9000; //                                                ID of main TAB
  $text="ID = $id \n CTRL = $ctrl \n PARAM1 = $lparam1 \n PARAM2 =  $lparam2 ";
  wb_message_box($window, $text,"TAB Pressed.", WBC_INFO);
   switch($lparam2) {
     case 0: // Tab index 0 or page 1
     wb_message_box($window, "Case 0","TAB 0 Page 1", WBC_OK); // Call init 1     
     break;
     case 1: // Tab index 1 or page 2
     wb_message_box($window, "Case 1","TAB 1 Page 2", WBC_OKCANCEL); // Call init 2      
     break;
     case 2: // Tab index 2 or page 3
     wb_message_box($window, "Case 2","TAB 2 Page 3", WBC_WARNING); // Call init 3      
     break;
   }   

 break;
 // END TAB Change - Test

</pre>

<br /> Test code

With the above modifications, main tab now generates its ID (in this case 9000) on any tab change. For reference, a wb_message_box displays all parameters passed to the handler function.

We are interested in which tab caused the change. Its index can be found in $lparam2 hence this is used in a switch. Each tab is resolved using a case statement (resolves tab indexes 0 to 2)

In a real application the message box would be replaced with a call to an initialisation function if required for that tab.

Top

Test 6 Script

<pre> <?php Include "../php/include/winbinder.php"; // Location Of Winbinder Library

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

//ID's Page 1 define("ID_L1101", 1101); //Label define("ID_L1102", 1102); define("ID_E1301", 1301); // Edit box define("ID_PB1201", 1201); // Push button define("ID_PB1202", 1202); // Push button define("ID_PB1203", 1203); // Push button

//ID's Page 2 define("ID_L2101", 2101); //Label define("ID_L2102", 2102); define("ID_E2301", 2301); // Edit box define("ID_PB2201", 2201); // Push button define("ID_PB2202", 2202); // Push button define("ID_PB2203", 2203); // Push button

//ID's Page 3 define("ID_L3101", 3101); //Label define("ID_L3102", 3102); define("ID_E3301", 3301); // Edit box define("ID_PB3201", 3201); // Push button define("ID_PB3202", 3202); // Push button define("ID_PB3203", 3203); // Push button

//=== 1) Create main window --------------------------------------------------- define("CAPTION", "Test 6"); // Set caption to match application if(wb_get_instance(CAPTION, TRUE)) // Is there an existing instance?

   die;                                // Yes: bring it to the front and quit

$mainwin = wb_create_window(NULL, AppWindow, "Test 6", WBC_CENTER, WBC_CENTER, 320, 240, WBC_NOTIFY| WBC_TASKBAR , WBC_HEADERSEL );

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

//Create main tab area $tab = wb_create_control($mainwin, TabControl, 0, 5, 5, 305, 200, 9000);

//Create Tab 0 - Page 1 wb_create_items($tab, "Page1");

wb_create_control($tab, Label,     "Test label A", 10, 14, 112, 20,   ID_L1101, 0, 0, 0);
wb_create_control($tab, Label,     "Test label B", 10, 34, 112, 20,   ID_L1102, 0, 0, 0);
wb_create_control($tab, EditBox,    "",            10, 54, 112, 20,   ID_E1301, 0, 0, 0);
wb_create_control($tab, PushButton, "Button A",    10, 90,  80, 22,   ID_PB1201, 0, 0, 0);
wb_create_control($tab, PushButton, "Button B",   100, 90,  80, 22,   ID_PB1202, 0, 0, 0);
wb_create_control($tab, PushButton, "Button C",   190, 90,  80, 22,   ID_PB1203, 0, 0, 0);

wb_create_control($tab, Frame, "Change", 185, 14, 92, 110, 0, 0, 0); // create frame wb_create_control($tab, Frame, "", 0, 0, 295, 173, 0, 0, 0); // create frame

//Create Tab 1 - Page 2 wb_create_items($tab, "Page2");

wb_create_control($tab, Label,     "Test label C", 10, 14, 112, 20,   ID_L2101, 0, 0, 1);
wb_create_control($tab, Label,     "Test label D", 10, 34, 112, 20,   ID_L2102, 0, 0, 1);
wb_create_control($tab, EditBox,    "",            10, 54, 112, 20,   ID_E2301, 0, 0, 1);
wb_create_control($tab, PushButton, "Button D",    10, 90,  80, 22,   ID_PB2201, 0, 0, 1);
wb_create_control($tab, PushButton, "Button E",   100, 90,  80, 22,   ID_PB2202, 0, 0, 1);
wb_create_control($tab, PushButton, "Button F",   190, 90,  80, 22,   ID_PB2203, 0, 0, 1);


//Create Tab 2 - Page 3 wb_create_items($tab, "Page3");

wb_create_control($tab, Label,     "Test label E", 10, 14, 112, 20,   ID_L3101, 0, 0, 2);
wb_create_control($tab, Label,     "Test label F", 10, 34, 112, 20,   ID_L3102, 0, 0, 2);
wb_create_control($tab, EditBox,    "",            10, 54, 112, 20,   ID_E3301, 0, 0, 2);
wb_create_control($tab, PushButton, "Button G",    10, 90,  80, 22,   ID_PB3201, 0, 0, 2);
wb_create_control($tab, PushButton, "Button H",   100, 90,  80, 22,   ID_PB3202, 0, 0, 2);
wb_create_control($tab, PushButton, "Button I",   190, 90,  80, 22,   ID_PB3203, 0, 0, 2);


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

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

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

//=== 4) Handler Function ----------------------------------------------------- function process_main($window, $id, $ctrl=0, $lparam1=0, $lparam2=0) {

 switch($id) { 
 // TAB Change - Test
 case 9000; //                                                ID of main TAB
  $text="ID = $id \n CTRL = $ctrl \n PARAM1 = $lparam1 \n PARAM2 =  $lparam2 ";
  wb_message_box($window, $text,"TAB Pressed.", WBC_INFO);
   switch($lparam2) {
     case 0: // Tab index 0 or page 1
     wb_message_box($window, "Case 0","TAB 0 Page 1", WBC_OK); // Call init 1     
     break;
     case 1: // Tab index 1 or page 2
     wb_message_box($window, "Case 1","TAB 1 Page 2", WBC_OKCANCEL); // Call init 2      
     break;
     case 2: // Tab index 2 or page 3
     wb_message_box($window, "Case 2","TAB 2 Page 3", WBC_WARNING); // Call init 3      
     break;
   }   

 break;
 // END TAB Change - Test
 //== Page 1
 case ID_PB1201:         // Button A
  wb_set_text(wb_get_control($window, ID_L1101),"12345");
  wb_set_text(wb_get_control($window, ID_L1102),"67890");
  break;
 case ID_PB1202:         // Button B
  wb_set_text(wb_get_control($window, ID_L1101),"67890");
  wb_set_text(wb_get_control($window, ID_L1102),"12345");
  break;
 case ID_PB1203:         // Button C
  $text1 = wb_get_text(wb_get_control($window, ID_E1301));
  wb_set_text(wb_get_control($window, ID_L1101),"Page 1 ".$text1);
  wb_set_text(wb_get_control($window, ID_L1102),"Page 1 ".$text1);
  break;
 //== Page 2
 case ID_PB2201:         // Button D
  button_D($window); 
  break;
 case ID_PB2202:         // Button E
  button_E($window); 
  break;
 case ID_PB2203:         // Button F
  button_F($window); 
  break;
 //== Page 3
 case ID_PB3201:         // Button G
    wb_message_box($window, "Page 3.","BUTTON G", WBC_INFO);
  break;
 case ID_PB3202:         // Button H
    wb_message_box($window, "Page 3.","BUTTON H", WBC_QUESTION);
  break;
 case ID_PB3203:         // Button I
    wb_message_box($window, "Page 3.","BUTTON I", WBC_YESNO);
  break;


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

}

function button_D($window){

  wb_set_text(wb_get_control($window, ID_L2101),"xxxx");
  wb_set_text(wb_get_control($window, ID_L2102),"yyyy");

} function button_E($window){

  wb_set_text(wb_get_control($window, ID_L2101),"yyyy");
  wb_set_text(wb_get_control($window, ID_L2102),"xxxx");

} function button_F($window){

  $text1 = wb_get_text(wb_get_control($window, ID_E2301));
  wb_set_text(wb_get_control($window, ID_L2101),"Page 2 ".$text1);
  wb_set_text(wb_get_control($window, ID_L2102),"Page 2 ".$text1);

} ?>

</pre>

Script:

test_6.phpw

Run:

Navigate to folder

UniServer\plugins\winbinder\examples

Double click on test_6.bat


Top

Summary

The above script (test_6.phpw) makes a good starting point for a Windows application. Use it as a template, make changes as required or alternatively use it as a guide and cut and paste the bits you need.

That completes a basic introduction to windows controls. It covers enough material to get started including some cosmetics that are not essential but will make a completed application more pleasing.

The next two pages cover a stand-alone project. It’s written from a scripting point of view and avoids compiling.

Top