• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net

Your first windows application, written in PHP ONLY !!

krakjoe

stop staring
NLC
Oh yeah, here we go ....

I'll assume already that you know php, and are confident that you can follow instructions and function prototypes similar to those you see @ php.net, that's pretty much all you need.

Firstly, a little bit about how this is done, so it doesn't seem like voodoo or something to you.

As you know php is an extendible language, you can pretty much write any C code you want to ( c++ if you're good enough ) and have php execute it, and I'm sure youre aware of PHP-GTK, well for some time now there has existed a library going by the name of WinBinder, what winbinder does is fuses the power and glory of php with the accessibility of windows and it's own native API to allow even novice php programmers to build fully featured windows applications using thier existing knowledge and skills.

I won't go into how the Windows API works, I don't need to you don't need to know.

Here is some pseudo code with the structure of a WinBound application

PHP:
<?php
// first include the wb functions that are contained in some php scripts distributed with winbinders installation package
include('winbinder.php');
// next you need to create a window probably for the user to interact with
$mainwin = wb_create_window( [ function args ] );
// next you need to draw controls on the above window
wb_create_control( $mainwin, [ function args ] );
// next you need to set a handler for that window, this function will handle the button pushes and tab changes etc in your application, it's the "brains" of the operation so to speak
wb_set_handler( $mainwin, 'process_my_window' );
// next we need to define the function and all it's procedures, notice this function has at least two parameters, the window it's for, and the id of the control being clicked, id's are specified in wb_create_control and normally defined before that, passing them works and trying to be as simple as I can be.
function process_my_window( $window, $id )
{
    switch( $id )
    {
        // this ID is predefined by wb, it's for the exit button, and you MUST put one in
        case IDCLOSE:
            wb_destroy_window( $window );
        break;
       
        case IDC_BUTTON:
            // your other cases and buttons and what not here
        break;
    }

}
// the next step is to tell wb to start looping infinitely with
wb_main_loop( );
?>
Writing windows applications from php really is as simple as that, please take a look at winbinder and it's documentation, and any questions you might have regarding it's usage feel free to ask if you don't get a response from the forums @ winbinder.

Once your applications are written, you'll notice they are still .php(w) scripts, however there are remedies for that, one of them exists : phpCompile : and of course has my name on it, so is far superior to anything else you might find, and now your php is an actual windows .exe that you can distribute like the big boys do .....

phpCompile is also suitable for making console applications from php, no further knowledge needed there, you write php scripts to do whatever you need and can turn them into an .exe to do whatever you need anywhere there is windows

Obviously the code for an actual windows application will be more complicated, but I promise not by much, and if you have the ability to use http://winasm.net winasm studio, you'll save yourself even more time, once winbinder is installed look in the examples directory for a look at most of the features that wb has to offer, this is definately one library every php programmer should know by heart ......

Thanks for listening ....
 

krakjoe

stop staring
NLC
Just over a year ago, I wrote the code that drives

http://krakjoe.com/projects/myCpanelBackup

When I was finished, I wrote a form for it but it looked rubbish - and was almost useless as an application, I had heard of py2exe and started to look into writing a php2exe program, I started but didn't get very far due to the lack of support ( or so I thought ) for the windows api, so then I started to attempt to write my own php extension that gave the access I needed to put files inside and retrieve them from an exe .... I was searching a build error on google and it came up in the winbinder forum, honestly I thought it was a joke when I saw the applications that were built with it, I was certain somewhere I'd need at least some c - but no, you don't, I scrapped both my php2exe program and my winapi extension and immediately started to suck in all the information I could, I have now written two successful php2exe programs for both php4 and php5 and know winbinder pretty well .... I more or less scrapped using all code but php, I use c for hacking php for my phpCompile-Beta program but apart from that I never have to look at another dll error again, not even once ....

God I love php, I actually get butterflies in my stomach when I think about the possibilities .....
 

krakjoe

stop staring
NLC
Lots of people have read the thread and no one is saying anything, is it because you don't believe me or something ??

I don't get it ... talk damn it ...
 

webadpro

Active Member
Wow.. nice I came up and being able to get something out.. and geez, I've got to say... WOW... this is amazing... Now I just need to learn it more and create nice looking apps.

Thanks Joe!

Joe, once we use phpCompile to compile our files, do we need to include any other files else to get the exe to execute and work as wanted? Also, would you mind explaining how to use a DB with winBinder?

Regards
 
Last edited:

krakjoe

stop staring
NLC
You can use normal mysql, or one of the flat file database drivers available for php, any php code will work, just interact as you normally would, but take special care when creating permissions for your mysql users ...

I said I would make a working example, and this morning I have, in the following archive is the following application, it's actually very simple, my coding standards might have lapsed on this because I'm very tired and just trying to wear myself out so I can sleep properly ( if you find mistakes then post ), but demonstrates well how to use wb and other extensions ....



Like I said, entirely PHP .... heres the sources ...

http://krakjoe.com/temp/uTube.zip
 

krakjoe

stop staring
NLC
http://krakjoe.com/projects/phpCompile - yay, I wrote that one ( php4 only ) ...
http://krakjoe.com/projects/phpCompile-Beta - yay, I wrote that one too ( php5 only, most php4 scripts will work anyway, but you have a better OO interface in php5 ) ...
http://winbinder.org -- yay someone else wrote that one

WinBinder is a php extension that allows php to make native API calls on windows machines, no voodoo, using these calls u can amongst other things, create controls and ( finally ) present a native looking windows interface to your PHP scripts, you do not need any knowledge of the windows API to make use of winbinder, it's functions are geared toward php users and it's a fantastically written and documented extension.

phpCompile is written by me, to turn winbound ( or indeed, ANY php ) into windows executables, able to execute on any windows platform above windows 98 WITHOUT that machine having php installed. It uses the php embeeded sapi to create the executables, no voodoo, php is meant to do this ...

Yes, an exe out of php, good isn't it ...

archive above is source to an application, I don't think I included the exe, you should do that as part of the learning process .... the screenshot is the executing exe packed with phpCompile v1
 
Last edited:

iBrightDev

Jay Street
NLC
NLC
joe, how the heck do you use the phpcompile? every time i try to load the program, the command prompt flashes, and then disappears instantly. :S
 

themoose

Sup, Recoil here.
NLC
Joe, I'm trying to compile that uTube programme from the source files you gave me, but when I open the programme it flashes for a millisecond and closes. What's up?
 

krakjoe

stop staring
NLC
@MCT, just like any other console executable, if you need to force it to stay open call system("PAUSE"); at the end of execution, otherwise execute it properly from a console ( cmd ) ...

@Colin, on IM

NOTE TO ALL : If a application depends on an extension, you must add that extension to the project with phpcompile, this application requires both curl and winbinder ... furthermore curl requires libeay32.dll and ssleay32.dll - this is a restriction of cURL, NOT phpCompile, or winbinder

http://krakjoe.com/temp/uTube-exe.zip
 
Last edited:

iBrightDev

Jay Street
NLC
NLC
i think it wont work because of the way the system admin has the computers set up at work
i will see if i can get it to work at home instead

is your site down?
 
Last edited:

krakjoe

stop staring
NLC
what code are you trying to run ?? it should work on any system, it doesn't matter how it is setup because it has everything it needs to run inside the archive ( with the exception applications that use curl ) ....
 

iBrightDev

Jay Street
NLC
NLC
i cant even do a cd c: to start trying to open anything
the drive shows as h: :S
there is no h drive. so, i think i am being blocked form doing anything in cmd.
 

krakjoe

stop staring
NLC
then put system("PAUSE"); at the end of the code your running and it'll stop the execution and keep the window till you press enter .... but yeah that's wierd, prolly best to leave it till you get home ...
 

iBrightDev

Jay Street
NLC
NLC
that is it, i dont really know what you mean by what code am i running. i am trying to open you compile program because i wanted to compile the utube program, but, when i try to open the compile program, the windows closes immediately. so, how can i keep that window open? or, and i trying to compile it wrong?
 

krakjoe

stop staring
NLC
oh prolly then they have done something to stop you running software they do not know .... which is quite clever, leave it till your on a normal pc .....
 
Top