TabControl class

A TabControl is a special kind of container window that organizes several controls in multiple pages. When clicked, the page displays only the controls assigned to it and hides the rest.

Creating tab controls and pages

You have several options to create a tab control with pages:

// To create a tab control with pages, the caption variable must contain the page names separated by newlines.

$tab = wb_create_control($mainwin, TabControl, "Page0\nPage1\nPage2'", $x, $y, $w, $h, ID_TABCONTROL, WBC_VISIBLE);

// Create an empty tab control and add pages to it by passing an array to wb_create_items().

$tab = wb_create_control($mainwin, TabControl, "", $x, $y, $w, $h, ID_TABCONTROL, WBC_VISIBLE);
wb_create_items($tab, array("Page0", "Page1", "Page2"));

// Create an empty tab control and add the pages later with several calls to wb_create_items().

$tab = wb_create_control($mainwin, TabControl, "", $x, $y, $w, $h, ID_TABCONTROL, WBC_VISIBLE);
wb_create_items($tab, "Page0");
wb_create_items($tab, "Page1");
wb_create_items($tab, "Page2");

To create the child controls for each page, you must use the tab control as the parent window and set the ntab parameter in function wb_create_control() to the desired page number:

// Add controls to the first page

wb_create_control($tab, Label, "This will go to Page 0", $x1, $y1, $w1, $h1, 0, WBC_VISIBLE, 0, 0);
wb_create_control($tab, Edit, "This will go to Page 0", $x2, $y2, $w2, $h2, 0, WBC_VISIBLE, 0, 0);

// Add more controls to the second page

wb_create_control($tab, Label, "This will go to Page 1", $x3, $y3, $w3, $h3, 0, WBC_VISIBLE, 0, 1);
wb_create_control($tab, ComboBox, "This will go to Page 1", $x4, $y4, $w4, $h4, 0, WBC_VISIBLE, 0, 1);

// etc.

NOTES

Detecting a tab change

The tab control can send a notification to its parent when the selected tab has changed if you include the WBC_NOTIFY style and the WBC_HEADERSEL flag when creating the parent window. See the example below:

<?php

// This small program shows how to make a tab control send notifications of a tab change

include "../include/winbinder.php";
define("MAIN_TAB1", 101);

// Create main window with the WBC_NOTIFY style and the WBC_HEADERSEL flag

$mainwin = wb_create_window(NULL, PopupWindow, "Tab control", WBC_CENTER, WBC_CENTER, 320, 240, WBC_NOTIFY, WBC_HEADERSEL);
wb_set_handler($mainwin, "process_main");

// Create tab control and status bar

$maintab = wb_create_control($mainwin, TabControl, "Tab1\nTab2\nTab3\nTab4\nTab5", 5, 5, 305, 175, MAIN_TAB1, WBC_VISIBLE);
$statusbar = wb_create_control($mainwin, StatusBar);

wb_main_loop();

// Main window processing

function process_main($window, $id, $ctrl, $lparam1=0, $lparam2=0)
{
   global $statusbar;

   switch($id) {
      case MAIN_TAB1:
         if($lparam1 & WBC_HEADERSEL)
            wb_set_text($statusbar, "Tab $lparam2 selected.");
         break;
   }
}

?>

See also

wb_create_control
wb_create_items

Control classes