PHP WinBinder 4: Introduction

From The Uniform Server Wiki
Jump to navigation Jump to search

 

UniServer 5-Nano
PHP WinBinder 4 - Tray Menu.

WinBinder Part 4

Introduction

Tray Menu

Unitray has stood the test of time however one real drawback is its lack of Unicode support. Translating menu-items into different languages is possible using entities. Not an ideal solution since there is several languages such as Chinese that are not translatable using entities

One solution would be to recode the above application with Unicode support. An alternative is to rewrite the application using a different scripting language. Interestingly WinBinder has recently introduced an update that fully supports Unicode, hence the PHP scripting language is an ideal choice.

Advantage of using WinBinder and PHP is the unification of Uniform Server. The control architecture is already written in PHP hence it is logical a new tray menu should be written in the same language.

Tutorial

This tutorial covers design and implementation of a new tray menu. Although specifically targeted at Uniform Server the menu architecture is general purpose allowing it to be tailored for other applications.

Objective

Objective is to produce a tray menu with format and features similar to Unitray. This ideally would be a replacement for Unitray. Secondary objective is to explore the capabilities of WinBinder.

 

Top

Specification

This specification is a bullet list intended only to maintain focus on what is required.

  • Unicode support
  • Menu configured using an ini file
  • Single level of sub-menu
  • Auto-resize to content
  • Run target applications using single mouse click
  • Open sub-menu on mouse over

You will notice from the above specification there are no bells and whistles. It covers absolute minimum requirement for a point and click menu.

Top

Configuration file

Never reinvent the wheel!

In keeping with this philosophy PHP’s ini file format is more than suitable for this application.

Top

Unpredictable

Content of a configuration file is unpredictable I am referring to number of menu items and sub-menus a user can configure.

One element written in stone is the name of the main configuration block. It serves as a reference point allowing information to be extracted and used as required.

However data in the configuration file is not directly usable. Solution; extract to a master array, rearrange and add additional data as required.

Top

Master array

The concept of a mater array is important and will be covered in detail later.

In principal all data we are going to use is stored in this array.

Data from the configuration file has a hierarchy and is flattened when written to our master array making it more accessible.

Top

WinBinder functions used

The following functions were lifted directly from the example scripts.

Rollover

  • $font_text_black = wb_create_font("Tahoma", 8, BLACK, 0);
  • $font_text_white = wb_create_font("Tahoma", 8, WHITE, 0);
  • wb_destroy_font(); // Destroy all fonts
  • $frame = wb_create_control($mainwin, Frame, "", 0, 0, $win_width, $win_height2, 101, WBC_IMAGE);
  • wb_create_image($win_width, $win_height2) -- Create an image
  • wb_set_image($frame, $bmp); // Swith image to label
  • wb_destroy_image($bmp); // Delete image

Icons

  • $img_1 = wb_create_image(16, 16); // Size of small icon
  • $img_2 = wb_create_image(16, 16); // Size of small icon
  • $img = wb_load_image('menu_icons.bmp');
  • wb_draw_image($img_1, $img, 0, 0, 16, 16, NOCOLOR, 16-1, 0); // Draw single images
  • wb_draw_image($img_2, $img, 0, 0, 16, 16, NOCOLOR, 64-1, 0); // Draw single images
  • wb_draw_image($bmp, $img_1, 20, 100); // Draw left icon 1
  • wb_draw_image($bmp, $img_2, 120, 100); // Draw left icon 2
  • wb_destroy_image($img_1); // Kill images created
  • wb_destroy_image($img_2); // Kill images created

Size and position

  • $max_width_array = wb_get_size($text_str); // Get string dimensions in pix
    • $max_width = $max_width_array[0] +3;
  • $dim = explode(" ", wb_get_system_info("workarea")); // Working screen area
    • $screen_width = $dim [2]; // Extract width
    • $screen_height = $dim [3]; // Extract height


Top

Download and Install

Depending on the file format choose one of the following installation methods:

exe:

  • Download file WinBinder_tray_menu_tutorial.exe from Sourceforge
  • Create a new folder us_temp and copy WinBinder_tray_menu_tutorial.exe to it.
  • To extract double click on file WinBinder_tray_menu_tutorial.exe
  • A new folder is created containing two folder:
WinBinder_tray_menu_tutorial  - Main folder
  Read_me.txt
  tutorial                    - Support material folder
  tray_menu_2                 - Tray menu demo folder

zip:

  • Download file WinBinder_tray_menu_tutorial.zip from Sourceforge
  • Create a new folder us_temp and copy WinBinder_tray_menu_tutorial.zip to it.
  • Extract all files to this current folder.
  • New folders are created:
WinBinder_tray_menu_tutorial
  WinBinder_tray_menu_tutorial  - Main folder
  Read_me.txt
  tutorial                      - Support material folder
  tray_menu_2                   - Tray menu demo folder

Top

Acknowledgements

I would like to express my thanks to the following:

Alec Gorge

 

WinBinder forum name "alecgorge," for allowing inclusion of his binaries.

Alec Gorge

 

WinBinder Wiki name "alecgorge" for allowing publication of his php5ts.dll (1.01 MB) taken from his new packer phpack v0.7.5

Ahmed Alsamawi

 

WinBinder Wiki name ermac2014 made a significant contribution to the WinBinder project.

He is the originator and contributor of code giving WinBinder full Unicode support.

Its this code that has made it worthwhile looking at an alternative tray-menu for Uniform Server.

Check out WinBinder forum for latest releases.

Top

Summary

I have provided a general outline of what is required and introduced the concept of a master array. Before looking at working menu code there are certain areas that are problematic.

This tutorial is written in the same order as I solved small chunks of the overall menu design. Its also ordered in terms of complexity most complex first.

One feature of UniTray I like is its rollover effect. From past experience I know this is a problem area. Hence on the next page you will find several small examples to see if a similar rollover effect is achievable using WinBinder.

Top