简体   繁体   English

PHP DOTNET():捕获System.Windows.Forms控件事件以创建可用的WIN gui

[英]PHP DOTNET(): Capturing System.Windows.Forms control events to create a usable WIN gui

I made a Windows GUI through PHP's DOTNET class and System.Windows.Forms . 我通过PHP的DOTNET类System.Windows.Forms制作了Windows GUI。 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. 我无法使com_event_sink()处理任何事件。 I know of no method to get PHP to fake or sink control event "delegates". 我知道没有任何方法可以使PHP伪造或接收控制事件“委托”。 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? 使用PHP,有没有人设法进入实际的System.Windows.Forms类事件以创建有效的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? 引用wezfurlong.org: 如果您同时希望发生事件,则所有.Net文档都建议您改为为对象创建自己的包装... :( 。任何人都发现了一种解决方法,不会强迫您学习新语言?

Here's my working test GUI... 这是我的工作测试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. 我也对替代方法-PHP-GTK感兴趣。 Has anyone gotten this working by overlaying the required libs with their normal PHP5.3 installation? 有没有人通过将所需的库与正常的PHP5.3安装覆盖在一起而使此工作正常进行的? I'm not interested in installing the prepackaged PHP version that comes with PHP-GTK as it's years out of date. 我对安装PHP-GTK随附的预打包PHP版本不感兴趣,因为它已经过时了几年。 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. 但是,如果有人能告诉我要从PHP-GTK软件包中选择哪个dll文件,然后选择放入我的普通PHP安装程序中以使其像任何普通扩展一样正常工作,我会不知所措。

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. 编辑:万一有人提到Winbinder-尽管我认为那些开发人员做得很好,但这实在是个漏洞百出,一个分散的爱好项目,并且目前还没有集中维护。

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. 更新:除非有人知道一个技巧或特定的启用COM的.Net程序集可以充当包装程序,否则我认为使用本机PHP方法无法解决此问题。 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. 我不得不求助于自己的VB.Net包装库,该库在很大程度上依赖于VB.Net Reflection类,将其注册为COM类,然后通过COM连接到-that-。 Disappointing, but it's starting to work. 令人失望,但它开始起作用。

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). Dotnet类似乎不能完全发挥作用,它依赖于可COM访问的类(大多数不是),并且某些常见的.Net类型不能转换为PHP值(请参阅PHP错误跟踪器)。 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. 因此,在VB.Net中构建一个非常基本的包装器/ API并将其设置为COM类是我找到使之正常工作的唯一方法。 Purely as an (open source) example, see: http://universalccw.sourceforge.net/ 纯粹作为(开放源代码)示例,请参见: http : //universalccw.sourceforge.net/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM