PHP WinBinder 3: Dialog pop-ups
PHP WinBinder 3 : Introduction | Dialog pop-ups | Name Password pop-up | Open and Save As dialog boxes
|
|
UniServer 5-Nano PHP WinBinder 3. |
Dialog and message boxes
WinBinder provides a number of standard dialog boxes and message boxes. These can be run directly from a PHP CLI script or run within a Windows application.
Following examples demonstrate how to use them.
Message box
A message box has the following code format:
- int wb_message_box (int parent, string message [, string title [, int style]])
A few examples of supported styles are listed below:
|
|
Example 1 (WBC_OK)
The following three lines are example code
|
|
First line is placed in the INIT section. Clicking either OK or close has the same Next two lines are added to the Handler Function again the return value is not used. |
Edit file |
|
Results |
Edit file Pro_demo_wb.php add the above lines as shown below: //=== INIT ========================================= wb_message_box (NULL, "Create Window", "TEST"); //==================================== END INIT ==== $pass = trim($pass); wb_message_box ($window, $name, "TEST"); wb_message_box (NULL, $pass, "TEST"); break;
Function wb_message_box is a regular PHP function. You can use strings as in the first line for example Important: If there is no obvious parent window use NULL |
|
Example 2 (WBC_YESNO)
Message boxes are ideal for obtaining a user response to yes no questions.
The following line of code creates a message box with two buttons Yes and No. This is achieved using the style attribute WBC_YESNO
The following two lines are example code
|
|
Text displayed requires a yes or no response from a user. If answer is No exit the script. |
Clicking button Yes returns true while clicking button No returns false.
Edit file
Edit file Pro_demo_wb.php add the above lines as shown below:
//=== INIT ========================================= wb_message_box (NULL, "Create Window", "TEST"); $answer = wb_message_box (NULL, "Are you sure you want to create a window?", "TEST2",WBC_YESNO); if($answer == FALSE) Exit; //==================================== END INIT ====
What’s important: When buttons are clicked in the It clearly shows you can use message boxes within pure PHP CLI code. If you click Yes the Windows creation code is executed. |
|
Coding style
Coding style is a personal choice. You will have noticed I assigned the returned value to a variable $answer and then used it in an if statement.
The following two examples give the same result
Replace
$answer = wb_message_box (NULL, "Are you sure you want to create a window?", "TEST2",WBC_YESNO); if($answer == FALSE) Exit;
With
if(!wb_message_box (NULL, "Are you sure you want to create a window?", "TEST2",WBC_YESNO)) Exit;
or
if(!wb_message_box (NULL, "Are you sure you want to create a window?", "TEST2",WBC_YESNO)){ Exit; }
My personal preference is the last style its easier to add additional code if required.
Select Path dialog box
A select path dialog box has the following code format:
- string wb_sys_dlg_path (int parent [, string title [, string path]])
Parameters:
- parent We are using PHP CLI hence use NULL for this parameter
- title A string to be displayed in the dialog box.
- path Full path to a folder to start from (optional)
Returns full path of selected folder, or a blank string if the dialog box was canceled. Returns NULL if not successful.
The following lines are example code
|
|
First line sets the current path of the script. It is optional worth including if you know where to startfrom. Second line creates the pop-up. Returned value is save in variable $path If a path is returned it is displayed in a message box. |
Edit file
Edit file Pro_demo_wb.php add the above lines as shown below: |
|
Results |
//=== INIT ========================================= $currentpath = dirname(__FILE__).'\www'; $path = wb_sys_dlg_path(NULL, 'Select a folder', $currentpath); if($path){ wb_message_box (NULL, $path, "TEST3"); } //==================================== END INIT ====
In a real application you use the variable $path as required. You would delete this code its only there for testing: if($path){ wb_message_box (NULL, $path, "TEST3"); } |
|
Links
The following are usful links to the WinBinber reference manual:
Summary
That concludes support material for the new Application plugin scripts.
If you followed the above link you will have noticed there are other dialogue functions such as Open dialog box and Save As dialog box you can use.
These will not work since our basic script does not support them this will be resolved later in the tutorial.
Our current implementation of the name-password pop-up is not independent of our script it an integral part. By this I mean it’s not a function like the above message boxes.
Next page shows how to convert the windows creation code into a function that can be used similar to a message box.