PHP WinBinder: Text input: Difference between revisions
(New page: {{Nav PHP WinBinder}} '''''Text and numeric input''''' Previous page covered very basic I/O this page looks at obtaining data (numeric and text) from a user. In addition I have thrown in ...) |
(No difference)
|
Revision as of 07:21, 28 January 2010
|
UniServer 5-Nano PHP WinBinder. |
Text and numeric input
Previous page covered very basic I/O this page looks at obtaining data (numeric and text) from a user. In addition I have thrown in a little extra user output feedback.
Example 3 uses Example 2 as a template in reality there are only small changes.
Cotrol Creation
Again we use this this function to create controls:
int wb_create_control (int parent, int ctlclass [, mixed caption [, int xpos [, int ypos [, int width [, int height [, int id [, int style [, int param [, int ntab]]]]]]]]]) |
I have have reduced it however there is an extra parameter style that we will be using :
handle = wb_create_control(parent,ctlclass,caption,xpos,ypos,width,height,id,style) |
Style changes either the look of a control for example WBC_BORDER will produce a sunken looks on a label.
Changes label3 as follows:
$text = " This is test 3 on two lines\n Sunken Label"; $label3 = wb_create_control($mainwin, Label, $text, 5, 60, 140, 40, 103, WBC_BORDER);
or it can change a controls functionality see edit box below..
EditBox
EditBox is a small window where a user can enter text or numeric data.
Example 3 defines the following edit boxes:
$editbox1= wb_create_control($mainwin, EditBox, "80", 150, 20, 112, 20, 301, WBC_NUMBER); $editbox2= wb_create_control($mainwin, EditBox, "Me", 150, 40, 112, 20, 302); |
|
Parameters
parent | handle to the WinBinder object $mainwin |
ctlclass | is the class of the control or object to be created EditBox |
caption | A string (80,Me) sets the initial value. Use "" to display no value |
xpos, | ypos, width and height Tweak the values to position and size EditBox. |
id | A unique integer identifies a control. Start from 100 to avoid clashes. Say labels will be 100 push buttons 200 and edit boxes start at 300 etc |
style | Optional if not provided the window will accept all characters. Setting style to WBC_NUMBER only characters 0 to 9 are excepted. |
Place the above in section two of the template. Once the main window is created the two controls are created
Read whats entered
Data entered into an edit box is obtained using one of these two functions:
wb_get_value(handle) wb_get_text(handle) |
The value returned may be assigned to a variable for example:
$text1 = wb_get_value($editbox1); $text2 = wb_get_text($editbox2); |
Interaction
At this stage running the script will produce a window as shown on the right. The pushbuttons will perform what was specified for Example 2. Lets specify new functionality for the buttons. Button Specification
|
Draw Rectangle
The following was taken from the manual:
bool wb_draw_rect (int target, int xpos, int ypos, int width, int height, int color [, bool filled [, int linewidth]])
Draws a filled or hollow rectangle. xpos and ypos are the coordinates of the upper-left corner, in pixels. width and height are the dimensions of the rectangle. color is a RGB color value. Set filled to FALSE to draw a border. In this case, linewidth sets the width of the border, in pixels. A linewidth of zero sets the width to 1 pixel. The first parameter, target, may be a WinBinder object, a window handle, a drawing surface or a bitmap.
Example 3 uses the following code:
wb_draw_rect($window,270,20,20,20,0x00FF00,TRUE); |
color is defined as RGB 0x00FF00 is green |
wb_draw_rect($window,270,20,20,20,RED,TRUE); |
color is defined using a pre-defined constant RED |
Handler function - code
The handler function changes are as follows:
Apache button
Handler code for Apache button:
case 201: // Apache button wb_set_text(wb_get_control($window, 101),"Apache Port = 80"); wb_draw_rect($window,270,20,20,20,0x00FF00,TRUE); break; |
|
MySQL Button
Handler code for MySQL button:
case 202: // MySQL button global $label2; wb_set_text($label2,"MySQL Port = 3306"); break; |
|
Alert Button
Handler code for Alert button:
case 203: // Alert button global $label1; global $label2; global $editbox1; global $editbox2; $text1 = wb_get_value($editbox1); $text2 = wb_get_text($editbox2); wb_set_text($label1,"Apache Port = $text1"); wb_set_text($label2,"MySQL Port = $text2"); wb_draw_rect($window,270,20,20,20,RED,TRUE); break; |
|
Test 3 Script
<?php Include "../php/include/winbinder.php"; // Location Of Winbinder Library //=== 1) Create main window --------------------------------------------------- $mainwin = wb_create_window(NULL, AppWindow, "Test 3", 320, 240); //=== 2) Create controls for the main window ---------------------------------- $editbox1= wb_create_control($mainwin, EditBox, "80", 150, 20, 112, 20, 301, WBC_NUMBER); $editbox2= wb_create_control($mainwin, EditBox, "Me", 150, 40, 112, 20, 302); $label1 = wb_create_control($mainwin, Label, "Apache Port = ", 5, 20, 112, 20, 101); $label2 = wb_create_control($mainwin, Label, "MySQL Port = ", 5, 40, 112, 20, 102); $text = " This is test 3 on two lines\n Sunken Label"; $label3 = wb_create_control($mainwin, Label, $text, 5, 60, 140, 40, 103, WBC_BORDER); $button1 = wb_create_control($mainwin, PushButton, "Apache", 20, 120, 80, 22, 201); $button2 = wb_create_control($mainwin, PushButton, "MySQL", 110, 120, 80, 22, 202); $button3 = wb_create_control($mainwin, PushButton, "Alert", 200, 120, 80, 22, 203); //=== 3) Assign handler function to the main window -------------------------- wb_set_handler($mainwin, "process_main"); //=== 5) Enter application loop ----------------------------------------------- wb_main_loop(); //=== 4) Handler Function ----------------------------------------------------- function process_main($window, $id) { global $label1; switch($id) { case 201: // Apache button wb_set_text(wb_get_control($window, 101),"Apache Port = 80"); wb_draw_rect($window,270,20,20,20,0x00FF00,TRUE); break; case 202: // MySQL button global $label2; wb_set_text($label2,"MySQL Port = 3306"); break; case 203: // Alert button global $label1; global $label2; global $editbox1; global $editbox2; $text1 = wb_get_value($editbox1); $text2 = wb_get_text($editbox2); wb_set_text($label1,"Apache Port = $text1"); wb_set_text($label2,"MySQL Port = $text2"); wb_draw_rect($window,270,20,20,20,RED,TRUE); break; case IDCLOSE: // Constant IDCLOSE (8) predefined wb_destroy_window($window); // Destroy the window break; } } ?> |
|
test_3.phpw Run: Navigate to folder UniServer\plugins\winbinder\examples Double click on test_3.bat |
Summary
This page and the previous one have covered basic controls for user input and output. I use the term basic loosely because with these controls alone you can produce powerful applications.
Depending on the complexity of your application you probably will want to divide it into logical sections.
The tab control is an excellent choice covered on the next page.