Results 1 to 7 of 7

Thread: Embed or Host a 3rd party app in a panel?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    102

    Embed or Host a 3rd party app in a panel?

    So lets say you have a form with a panel inside it called pgcontents and you want a program such as notepad.exe to display in the panel in a borderless state. I know this is possible but I'm having difficulty getting it to work.

    I am hopeless at API calls and well, this one is confusing me like crazy but here is the code I grabbed from somewhere about a month ago and attempted to put into my form called "template".

    Code:
    Public Class template
        Public rolldownsize As Integer
    
        Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
        Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        Private Const WM_SYSCOMMAND As Integer = 274
        Private Const SC_MAXIMIZE As Integer = 61488
        Dim proc As Process
    
        Private Sub Template_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            proc = Process.Start("C:\Windows\notepad.exe")
            proc.WaitForInputIdle()
            SetParent(proc.MainWindowHandle, pgcontents.Handle)
            SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
    End Sub
    End Class
    I honestly barely understand the code there but it semi gets me the result I want. Here is a screenshot:
    Name:  mKv3Wva.jpg
Views: 1325
Size:  13.6 KB

    Notice you can still see and access the windows titlebar inside the panel? I don't want that, I want the 3rd party program to be borderless.

    Also it doesn't seem to work for all programs for example when you replace notepad.exe with write.exe then wordpad just opens in a separate window rather than in the panel. Fraps opens up in the panel but then opens up on a new window when you click something.

    The application also seems to be out of focus and I would like it to come back in focus when you click on the fake title bar panel pgtitlebar. Is that possible.

    Thanks in advance for help on this topic

    P.S any further reading I can do to understand what those numbers mean such as SC_MAXIMIZE As Integer = 61488? Or how I can get all programs to work/embed properly?

    No interactions between the window and embedded programs are necessary, the embedded program just needs to work normally and stay in the panel without borders.
    Last edited by 12padams; Jul 19th, 2014 at 09:49 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Embed or Host a 3rd party app in a panel?

    It shouldn't really be necessary to tell a .NET developer to go to the MSDN Library as a first option whenever they want to know something about Microsoft development.

    http://social.msdn.microsoft.com/Sea...mark=true&ac=4

    As for the issue, most applications were never meant to be used the way you're trying so it's a hack and hacks are certainly not guaranteed to work when any detail changes. A process may not have a main window or it may not be the window that you see. There's also the fact that, in some cases, you might be violating a license agreement by doing that, especially if you remove the window border. If it's even possible to get it working with all the applications you want it to work with, you would almost certainly have to write specific code for a number of them., There's no one simple code snippet that will work for all applications.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    102

    Re: Embed or Host a 3rd party app in a panel?

    Basically the user will be able to browse for a exe file already on their computer and display it in a window. So I'm not including any .exe files with my program, the user will choose them from their own computer.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Embed or Host a 3rd party app in a panel?

    Quote Originally Posted by 12padams View Post
    Basically the user will be able to browse for a exe file already on their computer and display it in a window. So I'm not including any .exe files with my program, the user will choose them from their own computer.
    So you have no idea whether you're violating a license or not and you won't be able to write application-specific code for an arbitrary application.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    102

    Re: Embed or Host a 3rd party app in a panel?

    So basically this simple task of displaying a random 3rd party application in a panel is illegal and impossible?

    What about the person who made this control which is unfortunately in C#: http://www.codeproject.com/Articles/...inForm-project

    Is that person violating a license by releasing that to the coding community?

    P.S That control does exactly what I want but unfortunately it's in C# so I can't use it.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Embed or Host a 3rd party app in a panel?

    Quote Originally Posted by 12padams View Post
    Is that person violating a license by releasing that to the coding community?
    If that application is used to host an application whose license forbids it then yes, they are violating a license.
    Quote Originally Posted by 12padams View Post
    That control does exactly what I want but unfortunately it's in C# so I can't use it.
    Pretty much the entire .NET Framework is written in C# and you use that. You simply compile the code into a DLL and reference it. Alternatively, write the equivalent VB code. As long as it doesn't make use of pointers, anything that can be done in C# can be done in VB.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    102

    Re: Embed or Host a 3rd party app in a panel?

    Ok, never mind I figured out how to remove the window borders and stuff but If I put a warning in my program saying "Do not use this application to host other applications if their license forbids it" will that be ok and cover me?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width