function showCapture($owner) { $form = New-Object System.Windows.Forms.Form $form.Owner = $owner $form.icon = $icon $form.Text = "Capturar" $form.Width = 445 $form.Height = 220 $form.AutoSize = $true $form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterParent $form.Font = "Microsoft Sans Serif, 9.35" $form.FormBorderStyle = 'FixedDialog' $label_url = New-Object System.Windows.Forms.Label $label_url.Text = "URL:" $label_url.AutoSize = $true $label_url.Location = New-Object System.Drawing.Point(20, 23) $text_url = New-Object System.Windows.Forms.TextBox $text_url.Width = 333 $text_url.Location = New-Object System.Drawing.Point(75, 20) $text_url.add_DoubleClick({ $text_url.SelectAll(); }) $form.Controls.Add($label_url) $form.Controls.Add($text_url) $label_dest = New-Object System.Windows.Forms.Label $label_dest.Text = "Destino:" $label_dest.AutoSize = $true $label_dest.Location = New-Object System.Drawing.Point(20, 58) $text_dest = New-Object System.Windows.Forms.TextBox $text_dest.Text = $def_dest_dir $text_dest.Width = 255 $text_dest.Location = New-Object System.Drawing.Point(75, 55) $text_dest.add_DoubleClick({ $text_dest.SelectAll(); }) $btn_dest = New-Object System.Windows.Forms.Button $btn_dest.Text = "Examinar" $btn_dest.AutoSize = $true $btn_dest.Location = New-Object System.Drawing.Point(335, 53) $btn_dest.Add_Click({ $dest = selectFolder -path $def_dest_dir if ($dest) { $text_dest.Text = $dest } }) $form.Controls.Add($label_dest) $form.Controls.Add($text_dest) $form.Controls.Add($btn_dest) $label_name = New-Object System.Windows.Forms.Label $label_name.Text = "Nombre:" $label_name.AutoSize = $true $label_name.Location = New-Object System.Drawing.Point(20, 93) $text_name = New-Object System.Windows.Forms.TextBox $text_name.Text = "Captura - $(Get-Date -Format "yyyy-MM-dd HH.mm")" $text_name.Width = 333 $text_name.Location = New-Object System.Drawing.Point(75, 90) $text_name.add_TextChanged({ removeInvalidChars -textbox $text_name }) $text_name.add_DoubleClick({ $text_name.SelectAll(); }) $text_name.Add_KeyDown({ if ($_.KeyCode -eq "Enter") { $btn_rec.PerformClick() } }) $form.Controls.Add($label_name) $form.Controls.Add($text_name) function finish { $buttonTimer.Dispose() if ($null -ne $curr_process) { taskkill -pid $curr_process.Id $global:curr_process = $null } $btn_stop.Width = 0 $btn_stop.Height = 0 $btn_rec.Width = 150 $btn_rec.Height = 30 printLog } # El evento process.exited no funciona, por eso uso un timer para cambiar el boton # https://github.com/PowerShell/PowerShell/issues/8000#issuecomment-542412046 $buttonTimer = [System.Windows.Forms.Timer]::new() $buttonTimer.Interval = 1000 $buttonTimer.Add_Tick({ if ($null -ne $curr_process -and $curr_process.HasExited) { finish } }) $btn_rec = New-Object System.Windows.Forms.Button $btn_rec.Text = "Capturar" $btn_rec.Location = New-Object System.Drawing.Point(140, 135) $btn_rec.Width = 150 $btn_rec.Height = 30 $btn_rec.Add_Click({ try { $prevCode = startAlwaysOn capture -url $text_url.Text -out "$($text_dest.Text)\$($text_name.Text)" } finally { endAlwaysOn -code $prevCode } if ($null -ne $curr_process) { $btn_stop.Width = 150 $btn_stop.Height = 30 $btn_rec.Width = 0 $btn_rec.Height = 0 $buttonTimer.Start() } }) $btn_stop = New-Object System.Windows.Forms.Button $btn_stop.Text = "Detener" $btn_stop.Location = New-Object System.Drawing.Point(140, 135) $btn_stop.Width = 0 $btn_stop.Height = 0 $btn_stop.Add_Click({ finish }) $form.Controls.Add($btn_rec) $form.Controls.Add($btn_stop) $text_url.Select() $form.Add_Closing({ finish $owner.Location = getRelativeLocation -parent $owner -child $form $form.Hide() $owner.Show() }) [PSAppID]::SetAppIdForWindow($form.handle, "$($metadata.package).$app_name") $form.Add_LocationChanged({ $global:win_loc = $form.Location }) $form.Add_Resize({ $global:win_size = $form.Size }) $form.MaximizeBox = $false $form.ShowDialog() }