Solved

Modify this code to  Constrain app within a fixed position within panel  (it opens an app within an app)

Posted on 2007-04-02
6
214 Views
Last Modified: 2010-04-23
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.MainWindowHandle, Panel1.Handle)
        End If
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) 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
0
Comment
Question by:vbMarkO
  • 2
  • 2
  • 2
6 Comments
 
LVL 41

Expert Comment

by:graye
ID: 18837547
No, there is no clean way to have a separate process's window "dock" into another process's window (or control)

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
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18837583
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:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22139099.html

Again...just talking out loud...haven't played with it yet...

0
 

Author Comment

by:vbMarkO
ID: 18838269
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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18838335
"just need to move it so it will center within panel1 or fill it either way which ever is easiest ..."

You can make the app Maximize to fill the Panel like this:

Public Class Form1

    Private Const SW_MAXIMIZE As Integer = 3

    Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
    Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal handle As IntPtr, ByVal nCmdShow As Integer) 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("NotePad")
            p.WaitForInputIdle()
            SetParent(p.MainWindowHandle, Panel1.Handle)
            ShowWindow(p.MainWindowHandle, SW_MAXIMIZE)
        End If
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) 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
0
 

Author Comment

by:vbMarkO
ID: 18838830
Idle_Mind,

You are da Man for sure .... that worked like a charm and is exactly what I was needing thanx a million ....

Mark
0
 
LVL 41

Expert Comment

by:graye
ID: 18839312
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!)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now