https://wiki.uniformserver.com/index.php?title=PHP_WinBinder_3:_Dialog_pop-ups&feed=atom&action=historyPHP WinBinder 3: Dialog pop-ups - Revision history2024-03-29T12:02:36ZRevision history for this page on the wikiMediaWiki 1.41.0https://wiki.uniformserver.com/index.php?title=PHP_WinBinder_3:_Dialog_pop-ups&diff=4194&oldid=prevRic: New page: {{Nav 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 ...2010-04-06T20:00:49Z<p>New page: {{Nav 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 ...</p>
<p><b>New page</b></p><div>{{Nav PHP WinBinder 3}}<br />
'''''Dialog and message boxes '''''<br />
<br />
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.<br />
<br />
Following examples demonstrate how to use them.<br />
<br />
== Message box ==<br />
A message box has the following code format:<br />
* int wb_message_box (int parent, string message [, string title [, int style]])<br />
A few examples of supported styles are listed below:<br />
{|<br />
|-valign="top"<br />
|<br />
{| cellpadding="4" cellspacing="1" style="background:#000000;"<br />
|- style="background:#e8e8e8;"<br />
|'''Style Value''' || '''Display'''<br />
|- style="background:#f5f5f5;"<br />
|WBC_OK (the default)|| Standard OK button.<br />
|- style="background:#f5f5f5;"<br />
|WBC_INFO ||Information icon and a OK button.<br />
|- style="background:#f5f5f5;"<br />
|WBC_OKCANCEL ||Question mark icon, OK and Cancel buttons.<br />
|- style="background:#f5f5f5;"<br />
|WBC_YESNO ||Question mark icon, Yes and No buttons.<br />
|}<br />
|<br />
* The default dialogue is neat very compact and is extremely useful for debugging code.<br />
* What may be confusing is you must state a parent! However if you put code in the INIT<br> section you may think there is not parent window. Not strictly true every application<br> has a default parent, to pick this up just use '''NULL'''.<br />
<br />
* '''''Note'':''' You can even use '''NULL''' in the Handler Function<br />
|}<br />
'''''[[#top | Top]]'''''<br />
=== Example 1 (WBC_OK) ===<br />
The following three lines are example code <br />
{|<br />
|-<br />
|style="background:#f5f5f5;"|<br />
* wb_message_box (NULL, "Create Window", "TEST");<br />
* wb_message_box ($window, $name, "TEST"); <br />
* wb_message_box (NULL, $pass, "TEST");<br />
|<br />
&nbsp;<br />
|<br />
First line is placed in the INIT section. Clicking either OK or close has the same<br> effect because we are not using the returned value.<br />
<br />
Next two lines are added to the Handler Function again the return value is not used.<br> However they do use text entered in the pop-up text box. <br />
|}<br />
<br />
----<br />
<br />
{|<br />
|--valign="top"<br />
|<br />
==== Edit file ====<br />
|<br />
&nbsp;&nbsp;<br />
|<br />
==== Results ====<br />
|-valign="top"<br />
|<br />
Edit file '''Pro_demo_wb.php''' add the above lines as shown below:<br />
<pre><br />
//=== INIT =========================================<br />
<br />
wb_message_box (NULL, "Create Window", "TEST"); <br />
<br />
//==================================== END INIT ====<br />
</pre><br />
<pre><br />
$pass = trim($pass);<br />
<br />
wb_message_box ($window, $name, "TEST"); <br />
wb_message_box (NULL, $pass, "TEST");<br />
<br />
break; <br />
</pre><br />
<br />
* Run the script (double click on file Pro_demo_wb.bat)<br />
* Result shown on the right<br />
* The first pop-up relates to the PHP CLI script no Window is generated until you click the OK button<br />
* Once clicked the window is created.<br />
* Processing is now confined to the Windows application.<br />
* Enter a name and password<br />
* Click Enter to start processing<br />
* Each text box is read<br />
* Followed by our two dialogue boxes<br />
<br />
Function wb_message_box is a regular PHP function. You can use strings as in the first line for example<br> "Create Window" alternatively, use variables such as $name and $pass.<br />
<br />
'''''Important'':''' If there is no obvious parent window use '''NULL''' <br />
|<br />
&nbsp;&nbsp;<br />
|<br />
[[Image:Demo_2.gif]]<br />
|}<br />
'''''[[#top | Top]]'''''<br />
<br />
=== Example 2 (WBC_YESNO) ===<br />
Message boxes are ideal for obtaining a user response to yes no questions.<br />
<br />
The following line of code creates a message box with two buttons Yes and No. This is achieved using the style attribute WBC_YESNO<br />
<br />
The following two lines are example code <br />
{|<br />
|-<br />
|style="background:#f5f5f5;"|<br />
* $answer = wb_message_box (NULL, "Are you sure you want to create a window?", "TEST2",'''WBC_YESNO''');<br />
* if($answer == FALSE) Exit;<br />
|<br />
&nbsp;<br />
|<br />
Text displayed requires a yes or no response from a user.<br />
<br />
If answer is No exit the script.<br />
|}<br />
Clicking button '''Yes''' returns '''true''' while clicking button '''No''' returns '''false'''.<br />
<br />
==== Edit file ====<br />
Edit file '''Pro_demo_wb.php''' add the above lines as shown below:<br />
<pre><br />
//=== INIT =========================================<br />
<br />
wb_message_box (NULL, "Create Window", "TEST"); <br />
<br />
$answer = wb_message_box (NULL, "Are you sure you want to create a window?", "TEST2",WBC_YESNO);<br />
if($answer == FALSE) Exit;<br />
<br />
//==================================== END INIT ====<br />
</pre><br />
{|<br />
|--valign="top"<br />
|<br />
* Run the script (double click on file Pro_demo_wb.bat)<br />
* Click OK<br />
* Click No<br />
* Result shown on the right<br />
<br />
'''''What’s important'':''' When buttons are clicked in the<br> above sequence the Windows creation code is never executed. <br />
<br />
It clearly shows you can use message boxes within pure PHP CLI code.<br />
<br />
If you click Yes the Windows creation code is executed.<br />
|<br />
&nbsp;&nbsp;<br />
|<br />
[[Image:Demo_3.gif]]<br />
|}<br />
'''''[[#top | Top]]'''''<br />
==== Coding style ====<br />
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.<br />
<br />
The following two examples give the same result <br />
<br />
Replace<br />
<pre><br />
$answer = wb_message_box (NULL, "Are you sure you want to create a window?", "TEST2",WBC_YESNO);<br />
if($answer == FALSE) Exit;<br />
</pre><br />
With<br />
<pre><br />
if(!wb_message_box (NULL, "Are you sure you want to create a window?", "TEST2",WBC_YESNO)) Exit;<br />
</pre><br />
or<br />
<pre><br />
if(!wb_message_box (NULL, "Are you sure you want to create a window?", "TEST2",WBC_YESNO)){<br />
Exit;<br />
}<br />
</pre><br />
My personal preference is the last style its easier to add additional code if required. <br />
<br />
'''''[[#top | Top]]'''''<br />
== Select Path dialog box ==<br />
A select path dialog box has the following code format:<br />
* string wb_sys_dlg_path (int parent [, string title [, string path]])<br />
<br />
'''''Parameters'':'''<br />
<br />
* '''parent''' We are using PHP CLI hence use '''NULL''' for this parameter<br />
* '''title''' A string to be displayed in the dialog box.<br />
* '''path''' Full path to a folder to start from (optional)<br />
<br />
Returns full path of selected folder, or a blank string if the dialog box was canceled. Returns NULL if not successful.<br />
<br />
The following lines are example code <br />
{|<br />
|-<br />
|style="background:#f5f5f5;"|<br />
* $currentpath = dirname(__FILE__).'\www'; <br />
* $path = wb_sys_dlg_path(NULL, 'Select a folder', $currentpath);<br />
* if($path){<br />
* &nbsp;wb_message_box (NULL, $path, "TEST3"); <br />
* }<br />
|<br />
&nbsp;<br />
|<br />
First line sets the current path of the script. It is optional worth including if you know where to startfrom.<br />
<br />
Second line creates the pop-up. Returned value is save in variable $path<br />
<br />
If a path is returned it is displayed in a message box.<br />
|}<br />
<br />
----<br />
==== Edit file ====<br />
{|<br />
|--valign="top"<br />
|<br />
Edit file '''Pro_demo_wb.php''' add the above lines as shown below:<br />
|<br />
&nbsp;&nbsp;<br />
|<br />
==== Results ====<br />
|-valign="top"<br />
|<br />
<pre><br />
//=== INIT =========================================<br />
<br />
$currentpath = dirname(__FILE__).'\www'; <br />
$path = wb_sys_dlg_path(NULL, 'Select a folder', $currentpath);<br />
if($path){<br />
wb_message_box (NULL, $path, "TEST3"); <br />
}<br />
<br />
//==================================== END INIT ====<br />
</pre><br />
<br />
* Run the script (double click on file Pro_demo_wb.bat)<br />
* Brows for Folder is displayed<br />
* Note folder www is pre-selected (we set this using $currentpath)<br />
* Select any folder (images shows folder images selected)<br />
* Click OK<br />
* Message box Test4 displays full path to selected folder.<br />
* Result shown on the right<br />
<br />
In a real application you use the variable $path as required.<br />
<br />
You would delete this code its only there for testing:<br />
<pre><br />
if($path){<br />
wb_message_box (NULL, $path, "TEST3"); <br />
}<br />
</pre><br />
|<br />
&nbsp;&nbsp;<br />
|<br />
[[Image:Demo_4.gif]]<br />
|}<br />
<br />
<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Links ==<br />
The following are usful links to the WinBinber reference manual:<br />
* [http://winbinder.org/files/repository/docs/manual/reference/functions_category.html#dialog Functions Category]<br />
<br />
<br />
'''''[[#top | Top]]'''''<br />
== Summary ==<br />
That concludes support material for the new Application plugin scripts.<br />
<br />
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.<br />
<br />
These will not work since our basic script does not support them this will be resolved later in the tutorial.<br />
<br />
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.<br />
<br />
Next page shows how to convert the windows creation code into a function that can be used similar to a message box.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
----<br />
<br />
[[Category: Tutorials]]<br />
[[Category: How To]]<br />
[[Category: Uniform Server 5.0-Nano]]</div>Ric