https://wiki.uniformserver.com/index.php?title=MongoDB_Tutorial_2:_Buttons_1&feed=atom&action=historyMongoDB Tutorial 2: Buttons 1 - Revision history2024-03-29T09:00:07ZRevision history for this page on the wikiMediaWiki 1.41.0https://wiki.uniformserver.com/index.php?title=MongoDB_Tutorial_2:_Buttons_1&diff=4328&oldid=prevRic: New page: {{Nav MongoDB Tutorial 2}} == Introduction == With a working window we need to add functionality to each button this page covers the lower two buttons '''''Open cmd Window''''' and '''''H...2010-08-01T13:13:43Z<p>New page: {{Nav MongoDB Tutorial 2}} == Introduction == With a working window we need to add functionality to each button this page covers the lower two buttons '''''Open cmd Window''''' and '''''H...</p>
<p><b>New page</b></p><div>{{Nav MongoDB Tutorial 2}}<br />
<br />
== Introduction ==<br />
With a working window we need to add functionality to each button this page covers the lower two buttons '''''Open cmd Window''''' and '''''Help and Information'''''<br />
<br />
== Handler function ==<br />
<br />
Handler function processes button clicks each button has a unique ID. You can use this directly however a constant is preferred since a name is more meaningful. <br />
<br />
Current handler function contains redundant code this needs to be removed.<br />
Replace the handler function with the following:<br />
{|<br />
|-<br />
|<br />
<pre><br />
//=== 4) Handler Function =====================================================<br />
function process_mongo($window, $id){<br />
global $win_mongo;<br />
global $statusbar_mongo;<br />
<br />
switch($id) {<br />
<br />
<br />
case IDCLOSE: // Constant IDCLOSE (8) predefined<br />
wb_destroy_window($window); // Destroy the window<br />
break;<br />
}<br />
}<br />
//================================================ END 4) Handler Function ===<br />
<br />
</pre><br />
|<br />
* Function processes a single button.<br />
* Clicking the window top right crosses produces an event.<br />
* This event sends the originator ID to the handler function for processing.<br />
* ID is 8 which has a predefined constant '''''IDCLOSE'''''<br />
* This matches a defined case statement<br />
* Function '''wb_destroy_window($window)''' sends appropriate message to kill the window.<br />
* There is nothing else to do hence break to exit case.<br />
<br />
|}<br />
'''''[[#top | Top]]'''''<br />
<br />
== Help and Information ==<br />
Help and Information can be implemented using another window however this really is overkill. Preferred solution is for the button to open a text file (read_me.txt) in notepad.<br />
<br />
I have assumed this file is contained in the '''''us_info''''' folder. To allow relocation a constant is defined in file mongo_db_inc.php hence add the following line:<br />
<pre><br />
define("INFO_TXT", "$mongo_base_f/UniServer/usr/local/mongo/us_info/read_me.txt"); // Information file<br />
</pre><br />
WinBinder has a neat function wb_exec() that can start a process and pass parameters to it. Function also detaches that process from the main application. The following runs notepad and opens file read_me.txt<br />
<pre><br />
wb_exec('Notepad',INFO_TXT);<br />
</pre><br />
We have defined a constant for the help button ID_HELP_BUTTON we use this to intercept the button click and run above function. Code snippet as follows<br />
{|<br />
|-valign="top"<br />
|<br />
'''''Code'':'''<br />
<br />
* We have defined a constant for the help button ID_HELP_BUTTON<br />
* We use this to intercept the button click and run above function.<br />
* Code snippet shown on right<br />
|<br />
<pre><br />
//=== Display help info =============================<br />
case ID_HELP_BUTTON: // Button <br />
<br />
wb_exec('Notepad',INFO_TXT);<br />
<br />
break; <br />
//========================== END Display help info ===<br />
<br />
</pre><br />
|}<br />
'''''[[#top | Top]]'''''<br />
<br />
== Open cmd Window ==<br />
{|<br />
|-<br />
|<br />
Code:<br />
<br />
* To run our function open_cmd_window() is equally as simple<br />
* Code snippet of right<br />
<br />
|<br />
<pre><br />
//=== Open command window ============================<br />
// Open a command window in folder bin<br />
case ID_OPEN_CMD_BUTTON: // Button <br />
open_cmd_window();<br />
break;<br />
//======================== END Open command window ===<br />
</pre><br />
|}<br />
'''''[[#top | Top]]'''''<br />
== Updated handler function ==<br />
Adding the above gives the following handler function:<br />
<pre><br />
//=== 4) Handler Function =====================================================<br />
function process_mongo($window, $id){<br />
global $win_mongo;<br />
global $statusbar_mongo;<br />
<br />
switch($id) {<br />
<br />
//=== Open command window ==================================================<br />
// Open a command window in folder bin<br />
case ID_OPEN_CMD_BUTTON: // Button <br />
open_cmd_window();<br />
break;<br />
//============================================== END Open command window ===<br />
<br />
<br />
//=== Display help info ====================================================<br />
case ID_HELP_BUTTON: // Button <br />
<br />
wb_exec('Notepad',INFO_TXT);<br />
<br />
break; <br />
//================================================ END Display help info ===<br />
<br />
case IDCLOSE: // Constant IDCLOSE (8) predefined<br />
wb_destroy_window($window); // Destroy the window<br />
break;<br />
}<br />
}<br />
//================================================ END 4) Handler Function ===<br />
</pre><br />
'''''[[#top | Top]]'''''<br />
<br />
== Summary ==<br />
Looking at the handler function you have to admit it’s elegant.<br />
<br />
WinBinder hides all complexity of a Windows application allowing implementing your application with ease.<br />
<br />
Adding functionality to top two buttons are covered on the [[MongoDB Tutorial 2: Buttons 2 | '''next page''']]. <br />
<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
----<br />
<br />
[[Category: Tutorials]]<br />
[[Category: How To]]<br />
[[Category: Uniform Server 6-Carbo]]</div>Ric