I'm trying to build a function that allows me to bind to a specific window (that is already open) and get the dimensions of the window, as well as send either mouse clicks or key strokes to the window. I'm trying to make a windows form that I can run another program "inside of". I want to be able to resize an application window that is already open into a form itself and when something is done in the form, it sends the commands to the other window. For example, one side would be an entry form and the other an antiquated desktop application that doesn't allow copy paste. When the submit button was pushed in the entry form, there would be some data integrity checks (to remove any bad chars from the entry form) and then it would do sendkeys or something of that nature to the window that was "bound" inside the form.
Can anyone point me to an example of this kind of binding process? I'd like to make the form also scale and have the other window resize based on the resize done to the parent form, so any function examples would be extremely helpful.
I'm using a snippet I found that allows me to bind and control the child window:
function Set-WindowStyle {
param(
[Parameter()]
[ValidateSet('FORCEMINIMIZE', 'HIDE', 'MAXIMIZE', 'MINIMIZE', 'RESTORE',
'SHOW', 'SHOWDEFAULT', 'SHOWMAXIMIZED', 'SHOWMINIMIZED',
'SHOWMINNOACTIVE', 'SHOWNA', 'SHOWNOACTIVATE', 'SHOWNORMAL')]
$Style = 'SHOW',
[Parameter()]
$MainWindowHandle = (Get-Process -Id $pid).MainWindowHandle
)
$WindowStates = @{
FORCEMINIMIZE = 11; HIDE = 0
MAXIMIZE = 3; MINIMIZE = 6
RESTORE = 9; SHOW = 5
SHOWDEFAULT = 10; SHOWMAXIMIZED = 3
SHOWMINIMIZED = 2; SHOWMINNOACTIVE = 7
SHOWNA = 8; SHOWNOACTIVATE = 4
SHOWNORMAL = 1
}
Write-Verbose ("Set Window Style {1} on handle {0}" -f $MainWindowHandle, $($WindowStates[$style]))
[Win32Functions.Win32ShowWindowAsync]::ShowWindowAsync($MainWindowHandle, $WindowStates[$Style]) | Out-Null
}
and that all seems to work but I'm failing to figure out how to bind/sendkeys/window resize. I've looked into the WASP module in the psgallery but it doesn't seem to work anymore.