title: PHP DOTNET(): Capturing System.Windows.Forms control events to create a usable WIN gui
body: <p>I made a Windows GUI through PHP's <a href="http://php.net/manual/en/class.dotnet.php" rel="nofollow noreferrer">DOTNET class</a> and <a href="http://msdn.microsoft.com/en-us/library/k50ex0x9.aspx" rel="nofollow noreferrer">System.Windows.Forms</a>.  But, I'm stuck on handling button clicks, field updates, form open/close events, etc.</p>
  
  <p>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.</p>
  
  <p>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:  <a href="http://wezfurlong.org/blog/2004/oct/net-annoyances" rel="nofollow noreferrer">If you want events in the mean time, all the .Net docs suggest that you should instead make your own wrappers for the objects... :(</a>.  Anyone found a workaround that doesn't force you to learn a new language?</p>
  
  <p>Here's my working test GUI...</p>
  
  <pre><code>&lt;?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-&gt;Width = 450;
  $form-&gt;Height = 550;
  $form-&gt;Show();
  
  // Textbox 1
  $txt1 = new DOTNET($full_assembly_string, $namespace.'.TextBox');
  $txt1-&gt;Name = "IP";
  $txt1-&gt;Height = 400;
  $txt1-&gt;Width = 400;
  $txt1-&gt;Top = 40;
  $txt1-&gt;Left = 5;
  $txt1-&gt;Parent = $form;
  
  // Textbox 2
  $txt2 = new DOTNET($full_assembly_string, $namespace.'.TextBox');
  $txt2-&gt;Height = 300;
  $txt2-&gt;Width = 400;
  $txt2-&gt;Top = 80;
  $txt2-&gt;Left = 5;
  $txt2-&gt;Multiline = True;
  $txt2-&gt;ScrollBars = 3;
  $txt2-&gt;Parent = $form;
  
  // Button 1
  $btn1 = new DOTNET($full_assembly_string, $namespace.'.Button');
  $btn1-&gt;Height = 25;
  $btn1-&gt;Width = 75;
  $btn1-&gt;Text = "Backtrace";
  $btn1-&gt;Top = 5;
  $btn1-&gt;Left = 5;
  $btn1-&gt;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-&gt;Capture) {
          $txt2-&gt;Text = "BACKTRACING ".$txt1-&gt;Name." ".$txt1-&gt;Text."!!";
          $btn1-&gt;Capture = false; // force release of the button
          }
      }
  
  ?&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p><b>Update:</b> 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.</p>