Creating a Windows GUI Application with PHP
This is a guest blog post by Tim. Tim is a PHP programmer who is interested in Web Design, CSS, and Pizza. He runs the site php.uni.cc where he posts tutorials to help you with PHP, Design, and more. You can also find him over at forums.tizag.com.
Update: This was originally posted towards the end of July 2007. I'm reposting this as I believe it didn't get the attention it deserved. -Jake
This tutorial will show you how to make a basic “Hello World” application using PHP, Winbinder, and the Bambalam Compiler.
First we need to setup our environment. Once you have downloaded Winbinder and Bambalam Compiler from the links above, you should copy the following files into a new folder with the following structure:
- project_folder/bam.exe #Bambamlam Compiler - rename the old .exe to bam.exe
- project_folder/helloworld.php #Our “Hello World” source
- project_folder/winbinder.php #Winbinder - from WinBinder-0.46.0/phpcode/include/
- project_folder/wb_resources.inc.php #Winbinder - from WinBinder-0.46.0/phpcode/include/
- project_folder/wb_generic.inc.php #Winbinder - from WinBinder-0.46.0/phpcode/include/
- project_folder/wb_windows.inc.php #Winbinder - from WinBinder-0.46.0/phpcode/include/
- project_folder/php_winbinder.dll #Winbinder - from WinBinder-0.46.0/binaries/php4/ext/
- project_folder/project.bcp #Our Bam. project file
- project_folder/build.bat #Command to build our project
Once you have the files in order, copy and paste the following lines into the corresponding files.
build.bat
bam project.bcp
pause
On running the file, it will build a .exe based on the parameters in project.bcp and will pause the output so we can see if there are any errors.
project.bcp
OUTFILE helloworld.exe
EMBED helloworld.php
EMBED wb_generic.inc.php
EMBED wb_resources.inc.php
EMBED wb_windows.inc.php
EMBED winbinder.php
MAINFILE helloworld.php
EXTENSION php_winbinder.dllWINDOWED
This simply tells bam.exe to:
- Output the .exe to helloworld.exe
- Embed all the .php files
- Set helloworld.php as the main file
- Include the Winbinder extension
- Not to show the command line
Now that our environment is setup, we can move onto the coding.
First, Open up helloworld.php with you favorite PHP editor.
As you would start off any PHP script, type in:
<?php
Now we need to include winbinder.php. This holds several functions that we need.
<?php
include(”winbinder.php”);
Next, we need to create the application window. We also need to set it in a function.
<?php
include(”winbinder.php”);
$window = wb_create_window(NULL, AppWindow, “Hello World”, WBC_CENTER, WBC_CENTER, 400, 300);
The function wb_create_window has several required parameters. I will explain them now.
- NULL = The parent window. Since we have no other window, this needs to be NULL.
- AppWindow = This is the window type. You can find more types in the WinBinder documentation.
- “Hello World” = The window title.
- WBC_CENTER = The X starting location. WBC_CENTER is a predefined constant
- WBC_CENTER = The Y starting location. WBC_CENTER is a predefined constant
- 400 = The window width
- 300 = The window height
We will now make the text “Hello World” appear in the window.
<?php
include(”winbinder.php”);
$window = wb_create_window(NULL, AppWindow, “Hello World”, WBC_CENTER, WBC_CENTER, 400, 300);
$hello_world = wb_create_control($window, Label, “Hello World”, 5, 5, 100, 50);
The function wb_create_control has several required parameters. I will explain them now.
- $window = The objective window. Put the variable of the window you wish to add the control to in that spot.
- Label = The control type. You can find more control types in the WinBinder documentation.
- “Hello World” = The default value
- 5 = The X starting location.
- 100 = The control width
- 50 = The control height
Almost done! Finally, we must add the following function that loops the window to keep it alive.
<?php
include(”winbinder.php”);
$window = wb_create_window(NULL, AppWindow, “Hello World”, WBC_CENTER, WBC_CENTER, 400, 300);
$hello_world = wb_create_control($window, Label, “Hello World”, 5, 5, 100, 50);
wb_main_loop();
And there you have it! Now, compile the application by running build.bat. It all went well, it should output helloworld.exe which you should see the window with “Hello World”.
If you wish to expand you’re application making skills, you should read the Bambalam Compile project page and also the WinBinder documentation.


My best friend has this kind of website. It’s so much better than this one. So you better go away from here
Thank you for a clear and useful solution to an important problem. I apologize for the comment above dated 4/11/08 on behalf of the community.