views:

41

answers:

1

I made a Windows GUI through PHP's DOTNET class and System.Windows.Forms. But, I'm stuck on handling button clicks, field updates, form open/close events, etc.

I cannot get com_event_sink() working with any events whatsoever. I know of no method to get PHP to fake or sink control event "delegates". The best I can do is hackish - constantly monitor control properties for any hint of changes - such as check if a button is currently being dragged in lieu of an actual click event. But there's only one or two possible properties that even relate to user interaction that I can use here. Obviously, without hooking into form control events, this renders my application pretty powerless.

Using PHP, has anyone managed to hook into actual System.Windows.Forms class events to make an effective Windows GUI? If so, how? Or, is there a different assembly I should look at instead? Quoting wezfurlong.org: If you want events in the mean time, all the .Net docs suggest that you should instead make your own wrappers for the objects... :(. Anyone found a workaround that doesn't force you to learn a new language?

Here's my working test GUI...

<?php

$full_assembly_string = 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089';
$namespace = 'System.Windows.Forms';

// Main Form
$form = new DOTNET($full_assembly_string, $namespace.'.Form');
$form->Width = 450;
$form->Height = 550;
$form->Show();

// Textbox 1
$txt1 = new DOTNET($full_assembly_string, $namespace.'.TextBox');
$txt1->Name = "IP";
$txt1->Height = 400;
$txt1->Width = 400;
$txt1->Top = 40;
$txt1->Left = 5;
$txt1->Parent = $form;

// Textbox 2
$txt2 = new DOTNET($full_assembly_string, $namespace.'.TextBox');
$txt2->Height = 300;
$txt2->Width = 400;
$txt2->Top = 80;
$txt2->Left = 5;
$txt2->Multiline = True;
$txt2->ScrollBars = 3;
$txt2->Parent = $form;

// Button 1
$btn1 = new DOTNET($full_assembly_string, $namespace.'.Button');
$btn1->Height = 25;
$btn1->Width = 75;
$btn1->Text = "Backtrace";
$btn1->Top = 5;
$btn1->Left = 5;
$btn1->Parent = $form;

// Hack message/event capturing loop
while(true) {
    com_message_pump(1);
    // Check if 'Capture' property of Button 1 changed in lieu of actual click event
    if ((bool) $btn1->Capture) {
        $txt2->Text = "BACKTRACING ".$txt1->Name." ".$txt1->Text."!!";
        $btn1->Capture = false; // force release of the button
        }
    }

?>

I'm also interested in an alternative - PHP-GTK. Has anyone gotten this working by overlaying the required libs with their normal PHP5.3 installation? I'm not interested in installing the prepackaged PHP version that comes with PHP-GTK as it's years out of date. But I'm all ears if anyone can tell me which dll files out of PHP-GTK's bundle to pick and choose to drop into my normal PHP installation to get it working like any normal extension.

Edit: In case anyone mentions Winbinder - though I think those developers did a great job, it's just too buggy, a scattered hobby project, and not centrally maintained to be usable at the moment.

Update: Unless anyone knows of a trick or a specific COM-enabled .Net assembly that could act as a wrapper, I'd consider this problem unsolvable using native PHP methods. I had to resort to making my own VB.Net wrapper library relying heavily on VB.Net Reflection class as a go-between, register it as a COM class, and connect to -that- via COM instead. Disappointing, but it's starting to work.

A: 

Self-answer. Dotnet class doesn't appear to be fully functional and relies on classes to be COM accessible (which most are not), and some common .Net types cannot be converted to PHP values (see PHP bug tracker). So, building a very basic wrapper/API in VB.Net and making it a COM class was the only way I could find to get this working. Purely as an (open source) example, see: http://universalccw.sourceforge.net/

bob-the-destroyer