PHP WinBinder: Template: Difference between revisions
m
Reverted edits by Upazixorys (Talk); changed back to last version by BobS
Upazixorys (talk | contribs) No edit summary |
m (Reverted edits by Upazixorys (Talk); changed back to last version by BobS) |
||
Line 1: | Line 1: | ||
{{Nav PHP WinBinder}} | {{Nav PHP WinBinder}} | ||
'''''Windows application template''''' | '''''Windows application template''''' | ||
Line 19: | Line 18: | ||
|- | |- | ||
| | | | ||
<pre> | |||
<?php | |||
Include | Include "../php/include/winbinder.php"; // Location Of Winbinder Library | ||
$mainwin = wb_create_window(NULL, AppWindow, | $mainwin = wb_create_window(NULL, AppWindow, "XXX", 320, 240); // Create main window | ||
wb_set_handler($mainwin, | wb_set_handler($mainwin, "process_main"); // Assign handler to main window. | ||
wb_main_loop(); // Enter application loop | wb_main_loop(); // Enter application loop | ||
Line 37: | Line 36: | ||
} | } | ||
} | } | ||
? | ?> | ||
</pre> | |||
| | | | ||
& | | ||
| | | | ||
This really is an elegant script because it masks all the complexity associated with creating a Windows application. | This really is an elegant script because it masks all the complexity associated with creating a Windows application. | ||
Line 61: | Line 60: | ||
|- | |- | ||
| | | | ||
<pre> | |||
Include | Include "../php/include/winbinder.php"; | ||
</pre> | |||
| | | | ||
Every Windows script you create must contain this line. It pulls in all the WinBinder functions. If your script is located in another folder, change the path accordingly. | Every Windows script you create must contain this line. It pulls in all the WinBinder functions. If your script is located in another folder, change the path accordingly. | ||
|- | |- | ||
| | | | ||
<pre> | |||
$mainwin=wb_create_window(NULL,AppWindow, | $mainwin=wb_create_window(NULL,AppWindow,"XXX",320,240); | ||
</pre> | |||
| | | | ||
This function creates an application window with title XXX (change this to something meaningful). The window will have a width of 320 pixels and height of 240; again, these are changeable. | This function creates an application window with title XXX (change this to something meaningful). The window will have a width of 320 pixels and height of 240; again, these are changeable. | ||
|- | |- | ||
| | | | ||
<pre> | |||
wb_set_handler($mainwin, | wb_set_handler($mainwin,"process_main"); | ||
</pre> | |||
| | | | ||
Generally every window action (mouse movement, button click) requires processing. This is performed by a single function assigned to the main window. The function receives the ID of an event that requires processing. The function | Generally every window action (mouse movement, button click) requires processing. This is performed by a single function assigned to the main window. The function receives the ID of an event that requires processing. The function "process_main" is referred to as a handler. Hence Assign handler to main window. Note that if this function cannot handle the request it is passed onto a system default handler. | ||
|- | |- | ||
| | | | ||
<pre> | |||
wb_main_loop(); | wb_main_loop(); | ||
</pre> | |||
| | | | ||
This function effectively keeps the window alive. The call to wb_main_loop() must be the last executable statement of the PHP script. All statements after it will be ignored (this does not apply to any functions after it). | This function effectively keeps the window alive. The call to wb_main_loop() must be the last executable statement of the PHP script. All statements after it will be ignored (this does not apply to any functions after it). | ||
|- | |- | ||
| | | | ||
<pre> | |||
function process_main($window, $id) | function process_main($window, $id) | ||
</pre> | |||
| | | | ||
The handler function processes all events occurring in our window $window. Each event produces an ID. Any event not handled is passed on to a default system handler. | The handler function processes all events occurring in our window $window. Each event produces an ID. Any event not handled is passed on to a default system handler. | ||
|- | |- | ||
| | | | ||
<pre> | |||
switch($id) | switch($id) | ||
</pre> | |||
| | | | ||
The handler consists of a switch statement with each case corresponding to a specific ID. In this example a single case is shown: '''IDCLOSE'''. This constant is set to 8. Closing a window (clicking the | The handler consists of a switch statement with each case corresponding to a specific ID. In this example a single case is shown: '''IDCLOSE'''. This constant is set to 8. Closing a window (clicking the "X" in the top right corner) sends ID 8 to the handler. | ||
|- | |- | ||
| | | | ||
<pre> | |||
wb_destroy_window($window); | wb_destroy_window($window); | ||
</pre> | |||
| | | | ||
Every program must include this function. It terminates the window and performs a clean-up operation | Every program must include this function. It terminates the window and performs a clean-up operation | ||
Line 126: | Line 125: | ||
|- | |- | ||
| | | | ||
<pre> | |||
Line 134: | Line 133: | ||
</pre> | |||
| | | | ||
* '''..\php\php.exe''' - Move up one folder level and down into folder php | * '''..\php\php.exe''' - Move up one folder level and down into folder php<br /> run PHP CLI interface program '''php.exe''' | ||
* '''-c ..\php\php-wb.ini''' - Force PHP to use configuration file '''php-wb.ini''' | * '''-c ..\php\php-wb.ini''' - Force PHP to use configuration file '''php-wb.ini''' | ||
* '''test_1.phpw''' - PHP script to run (note extension '''phpw''' you can use '''php''') | * '''test_1.phpw''' - PHP script to run (note extension '''phpw''' you can use '''php''') | ||
Line 155: | Line 154: | ||
|- | |- | ||
| | | | ||
<pre> | |||
Line 161: | Line 160: | ||
</pre> | |||
| | | | ||
* Replace script and paths as appropriate. | * Replace script and paths as appropriate. | ||
Line 177: | Line 176: | ||
The file is divided into sections. These are required for all windows applications. | The file is divided into sections. These are required for all windows applications. | ||
{| | {| | ||
|-valign= | |-valign="top" | ||
| | | | ||
<pre> | |||
<?php | |||
Include | Include "../php/include/winbinder.php"; // Location Of Winbinder Library | ||
//=== 1) Create main window --------------------------------------------------- | //=== 1) Create main window --------------------------------------------------- | ||
$mainwin = wb_create_window(NULL, AppWindow, | $mainwin = wb_create_window(NULL, AppWindow, "Test 1", 320, 240); | ||
//=== 2) Create controls for the main window ---------------------------------- | //=== 2) Create controls for the main window ---------------------------------- | ||
//=== 3) Assign handler function to the main window -------------------------- | //=== 3) Assign handler function to the main window -------------------------- | ||
wb_set_handler($mainwin, | wb_set_handler($mainwin, "process_main"); | ||
//=== 5) Enter application loop ----------------------------------------------- | //=== 5) Enter application loop ----------------------------------------------- | ||
Line 204: | Line 203: | ||
} | } | ||
} | } | ||
? | ?> | ||
</pre> | |||
| | | | ||
& | | ||
| | | | ||
<br /> | |||
'''''Window produced by script''''' | '''''Window produced by script''''' | ||
& | [[Image:WinBinder_1.gif]] | ||
* The above window is a blank application. | * The above window is a blank application. | ||
* It has two active controls | * It has two active controls |