MongoDB Tutorial 2: Buttons 1

From The Uniform Server Wiki
Revision as of 13:13, 1 August 2010 by Ric (talk | contribs) (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...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

 

MongoDB Plugin
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){
  global $win_mongo;
  global $statusbar_mongo;

   switch($id) {


   case IDCLOSE:                             // Constant IDCLOSE (8) predefined
      wb_destroy_window($window);            // Destroy the window
      break;
   }
}
//================================================ END 4) Handler Function ===

  • Function processes a single button.
  • Clicking the window top right crosses produces an event.
  • This event sends the originator ID to the handler function for processing.
  • ID is 8 which has a predefined constant IDCLOSE
  • This matches a defined case statement
  • Function wb_destroy_window($window) sends appropriate message to kill the window.
  • There is nothing else to do hence break to exit case.

Top

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 us_info 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/UniServer/usr/local/mongo/us_info/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:

  • 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 shown on right
   //=== Display help info =============================
   case ID_HELP_BUTTON:          // Button 

    wb_exec('Notepad',INFO_TXT);

   break; 
   //========================== END Display help info ===

Top

Open cmd Window

Code:

  • To run our function open_cmd_window() is equally as simple
  • Code snippet of right
   //=== Open command window ============================
   // Open a command window in folder bin
   case ID_OPEN_CMD_BUTTON:          // Button 
    open_cmd_window();
   break;
   //======================== END Open command window ===

Top

Updated handler function

Adding the above gives the following handler function:

//=== 4) Handler Function =====================================================
function process_mongo($window, $id){
  global $win_mongo;
  global $statusbar_mongo;

   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 ===

Top

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.


Top