vbMarkO
asked on
Modify this code to Constrain app within a fixed position within panel (it opens an app within an app)
I need to know how to modify the following code to do the following questions
1. Is there a way to constrain the app I am opening in a fixed position within the panel?
2. Also is it possible to make my app resize to accommodate the opened app?
Public Class Form1
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Private p As Process = Nothing
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (p Is Nothing) OrElse p.HasExited Then
p = Process.Start("calc")
p.WaitForInputIdle()
SetParent(p.MainWindowHand le, Panel1.Handle)
End If
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormC losingEven tArgs) Handles Me.FormClosing
If Not (p Is Nothing) Then
If Not p.HasExited Then
p.CloseMainWindow() ' or p.Kill() if it doesn't have a GUI
End If
End If
End Sub
End Class
1. Is there a way to constrain the app I am opening in a fixed position within the panel?
2. Also is it possible to make my app resize to accommodate the opened app?
Public Class Form1
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Private p As Process = Nothing
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (p Is Nothing) OrElse p.HasExited Then
p = Process.Start("calc")
p.WaitForInputIdle()
SetParent(p.MainWindowHand
End If
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormC
If Not (p Is Nothing) Then
If Not p.HasExited Then
p.CloseMainWindow() ' or p.Kill() if it doesn't have a GUI
End If
End If
End Sub
End Class
You might be able to modify the windows styles using GetWindowLong() and SetWindowLong() to make it nonsizeable...would have to play with it...
That way it can't be "moved".
In this PAQ I remove the "minimize" button from a NotePad window:
https://www.experts-exchange.com/questions/22139099/I-need-code-to-prevent-Notepad-exe-from-minimizing-using-a-windows-hook.html
Again...just talking out loud...haven't played with it yet...
That way it can't be "moved".
In this PAQ I remove the "minimize" button from a NotePad window:
https://www.experts-exchange.com/questions/22139099/I-need-code-to-prevent-Notepad-exe-from-minimizing-using-a-windows-hook.html
Again...just talking out loud...haven't played with it yet...
ASKER
graye,
Yeah, if it will accomplish what I need I would ... not as far as resizing no need for that ... I made my app of such that the other app will fit nicely just need to move it so it will center within panel1 or fill it either way which ever is easiest ...
So what are we talking about here code wise ..... alot?
Mark
Yeah, if it will accomplish what I need I would ... not as far as resizing no need for that ... I made my app of such that the other app will fit nicely just need to move it so it will center within panel1 or fill it either way which ever is easiest ...
So what are we talking about here code wise ..... alot?
Mark
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Idle_Mind,
You are da Man for sure .... that worked like a charm and is exactly what I was needing thanx a million ....
Mark
You are da Man for sure .... that worked like a charm and is exactly what I was needing thanx a million ....
Mark
Humph... I learned something
I didn't know you could set the parent handle to a control for a "foriegn" process. (So disregard my comments to the contrary!)
I didn't know you could set the parent handle to a control for a "foriegn" process. (So disregard my comments to the contrary!)
The alternative is to send windows API "events" to the running process to move/resize it relative to your control. Unfortunately that's all done "by hand".... you performing all of the calculations and issuing the required events in code.
Let us know if you really wanna go down that path, we can help with the "low-level plumbing" to make it all work