| 1 | param([string]$Title, [string]$Receipt) |
| 2 | $ErrorActionPreference = 'Stop' |
| 3 | Add-Type -AssemblyName System.Windows.Forms |
| 4 | $form = New-Object System.Windows.Forms.Form |
| 5 | $form.Text = $Title |
| 6 | $form.Width = 420 |
| 7 | $form.Height = 220 |
| 8 | $panel = New-Object System.Windows.Forms.Panel |
| 9 | $panel.Dock = 'Fill' |
| 10 | $edit = New-Object System.Windows.Forms.TextBox |
| 11 | $edit.Name = 'FixtureEntry' |
| 12 | $edit.Text = 'initial' |
| 13 | $edit.SetBounds(20, 20, 320, 30) |
| 14 | $button = New-Object System.Windows.Forms.Button |
| 15 | $button.Text = 'Apply fixture' |
| 16 | $button.SetBounds(20, 70, 160, 35) |
| 17 | $script:clicks = 0 |
| 18 | $button.Add_Click({ $script:clicks++ }) |
| 19 | $panel.Controls.Add($button) |
| 20 | $panel.Controls.Add($edit) |
| 21 | $form.Controls.Add($panel) |
| 22 | $timer = New-Object System.Windows.Forms.Timer |
| 23 | $timer.Interval = 100 |
| 24 | $timer.Add_Tick({ |
| 25 | $json = @{ title = $form.Text; visible = $form.Visible; text = $edit.Text; clicks = $script:clicks; hwnd = $form.Handle.ToInt64() } | ConvertTo-Json -Compress |
| 26 | [IO.File]::WriteAllText($Receipt + '.tmp', $json, (New-Object Text.UTF8Encoding($false))) |
| 27 | Move-Item -Force ($Receipt + '.tmp') $Receipt |
| 28 | }) |
| 29 | $timer.Start() |
| 30 | try { [System.Windows.Forms.Application]::Run($form) } finally { $timer.Dispose(); $form.Dispose() } |
| 31 |