MongoDB Tutorial 1: Buttons 1
MongoDB Tutorial 1 : Introduction | Alternative control | Basic Window App | Buttons 1 | Buttons 2 | Mongo-Start
|
|
MongoDB Standalone UniServer 6-Carbo. |
Introduction
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
Handler function
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.
Current handler function contains redundant code this needs to be removed. Replace the handler function with the following:
//=== 4) Handler Function ===================================================== function process_mongo($window, $id){ switch($id) { case IDCLOSE: // Constant IDCLOSE (8) predefined wb_destroy_window($window); // Destroy the window break; } } //================================================ END 4) Handler Function === |
|
Help and Information
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.
I have assumed this file is contained in the control folder. To allow relocation a constant is defined in file mongo_db_inc.php hence add the following line:
define("INFO_TXT", "$mongo_base_f/mongodb_1/control/read_me.txt"); // Information file
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
wb_exec('Notepad',INFO_TXT);
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
Code:
|
//=== Display help info ============================= case ID_HELP_BUTTON: // Button wb_exec('Notepad',INFO_TXT); break; //========================== END Display help info === |
Open cmd Window
Code:
|
//=== Open command window ============================ // Open a command window in folder bin case ID_OPEN_CMD_BUTTON: // Button open_cmd_window(); break; //======================== END Open command window === |
Updated handler function
Adding the above gives the following handler function:
//=== 4) Handler Function ===================================================== function process_mongo($window, $id){ switch($id) { //=== Open command window ================================================== // Open a command window in folder bin case ID_OPEN_CMD_BUTTON: // Button open_cmd_window(); break; //============================================== END Open command window === //=== Display help info ==================================================== case ID_HELP_BUTTON: // Button wb_exec('Notepad',INFO_TXT); break; //================================================ END Display help info === case IDCLOSE: // Constant IDCLOSE (8) predefined wb_destroy_window($window); // Destroy the window break; } } //================================================ END 4) Handler Function ===
Summary
Looking at the handler function you have to admit it’s elegant.
WinBinder hides all complexity of a Windows application allowing implementing your application with ease.
Adding functionality to top two buttons are covered on the next page.