PHP WinBinder: Template: Difference between revisions
Jump to navigation
Jump to search
no edit summary
(Proofreading and grammatical changes; some minor reformatting) |
Upazixorys (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
=[http://acisabukody.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]= | |||
{{Nav PHP WinBinder}} | {{Nav PHP WinBinder}} | ||
'''''Windows application template''''' | '''''Windows application template''''' | ||
Line 18: | Line 19: | ||
|- | |- | ||
| | | | ||
<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 36: | Line 37: | ||
} | } | ||
} | } | ||
? | ?> | ||
</pre> | |||
| | | | ||
| &nbsp; | ||
| | | | ||
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 60: | Line 61: | ||
|- | |- | ||
| | | | ||
<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 125: | Line 126: | ||
|- | |- | ||
| | | | ||
<pre> | |||
Line 133: | Line 134: | ||
</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 154: | Line 155: | ||
|- | |- | ||
| | | | ||
<pre> | |||
Line 160: | Line 161: | ||
</pre> | |||
| | | | ||
* Replace script and paths as appropriate. | * Replace script and paths as appropriate. | ||
Line 176: | Line 177: | ||
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 203: | Line 204: | ||
} | } | ||
} | } | ||
? | ?> | ||
</pre> | |||
| | | | ||
| &nbsp; | ||
| | | | ||
<br /> | |||
'''''Window produced by script''''' | '''''Window produced by script''''' | ||
[[Image:WinBinder_1.gif]] | &nbsp;[[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 |