Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

running 2 application under a container

Posted on 1999-07-11
3
Medium Priority
?
137 Views
Last Modified: 2010-05-02
Hi,
   I would like to run 2 or more application under a form or other container.  I would like them to be mdi.  when I close the container I want them to close as well.  
I tried to use the runapp and shell but didn't get it right.
Thanks
Shai.
0
Comment
Question by:shaii
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Mirkwood earned 150 total points
ID: 1523517
You have to find the handle of the application you start from shell command using  the description of the window.  A application have always the same Description, but not the same handle.

You can use these 3 function to retrieve the handle by description.
Note: You window should be in top level list to be able to find it.

Private Function GetBaseName$(ByVal Source$)
' If source$ is a path, this function retrieves the
' basename, or filename sans path
' source$ MUST be a valid filename
'

On Error GoTo ErrorHandle

    Do While InStr(Source$, "\") <> 0
        Source$ = Mid$(Source$, InStr(Source$, "\") + 1)
    Loop
    If InStr(Source$, ":") <> 0 Then
        Source$ = Mid$(Source$, InStr(Source$, ":") + 1)
    End If
    GetBaseName$ = Source$

    Exit Function

ErrorHandle:
    MsgErr
    Resume Next

End Function
'******************************************************************


'******************************************************************
Private Function GetWindowDesc$(ByVal hwnd)
'   Builds a string descrbing the window in format
'   handle, source application, class
'   seperated by tabs
'

    Dim Desc$
    Dim tbuf$

   Dim inst As Long
   Dim dummy As Long
     
On Error GoTo ErrorHandle

    ' Include the windows handle first
    Desc$ = "&H" + Hex$(hwnd) + Chr$(9)

    ' Get name of source app
    tbuf$ = String$(256, 0) ' Predefine string length
    ' Get instance for window
    inst = GetWindowWord(hwnd, GWW_HINSTANCE)
     
    ' Get the module filename
    dummy = GetModuleFileName(inst, tbuf$, 255)
    tbuf$ = GetBaseName$(tbuf$)
     

    ' The following two lines are equivalent
    'tbuf$ = agGetStringFromLPSTR$(tbuf$)
    ' If InStr(tbuf$, Chr$(0)) Then tbuf$ = Left$(tbuf$, InStr(tbuf$, Chr$(0)) - 1)
     
    ' And add it to the description
    Desc$ = Desc$ + tbuf$ + Chr$(9)

    ' Finally, add the class name
    tbuf$ = String$(256, 0) ' Initialize space again
    dummy = GetClassName(hwnd, tbuf$, 255)
    'tbuf$ = agGetStringFromLPSTR(tbuf$)
    If InStr(tbuf$, Chr$(0)) Then tbuf$ = Left$(tbuf$, InStr(tbuf$, Chr$(0)) - 1)

    Desc$ = Desc$ + tbuf$

    ' And return the description
    GetWindowDesc$ = Desc$

    Exit Function

ErrorHandle:
    MsgErr
    Resume Next

End Function

'******************************************************************
Private Function GetWindowhWnd$(ByVal hwnd)
'   Builds a string descrbing the window in format
'   handle, source application, class
'   seperated by tabs
'
   Dim Desc$
   Dim tbuf$
   Dim inst As Long
   Dim dummy As Long

On Error GoTo ErrorHandle

    ' Include the windows handle first
    Desc$ = "&H" + Hex$(hwnd) + Chr$(9)

    ' Get name of source app
    tbuf$ = String$(256, 0) ' Predefine string length
    ' Get instance for window
    inst = GetWindowWord(hwnd, GWW_HINSTANCE)
     
    ' Get the module filename
    dummy = GetModuleFileName(inst, tbuf$, 255)
    tbuf$ = GetBaseName$(tbuf$)
     

    ' Finally, add the class name
    tbuf$ = String$(256, 0) ' Initialize space again
    dummy = GetClassName(hwnd, tbuf$, 255)
   
    ' And return the description
    GetWindowhWnd$ = Desc$

    Exit Function

ErrorHandle:
    MsgErr
    Resume Next

End Function
'******************************************************************


'******************************************************************
Private Function GetWindowName$(ByVal hwnd)
'   Builds a string descrbing the window in format
'   handle, source application, class
'   seperated by tabs
'
    Dim Desc$
    Dim tbuf$
     
    #If Win32 Then
        Dim inst As Long
        Dim dummy As Long
    #Else
        Dim inst As Integer
        Dim dummy As Integer
    #End If

On Error GoTo ErrorHandle


    ' Include the windows handle first
    Desc$ = "&H" + Hex$(hwnd) + Chr$(9)

    ' Get name of source app
    tbuf$ = String$(256, 0) ' Predefine string length
    ' Get instance for window
    inst = GetWindowWord(hwnd, GWW_HINSTANCE)
     
    ' Get the module filename
    dummy = GetModuleFileName(inst, tbuf$, 255)
    tbuf$ = GetBaseName$(tbuf$)
     

    ' The following two lines are equivalent
    'tbuf$ = agGetStringFromLPSTR(tbuf$)
    ' If InStr(tbuf$, Chr$(0)) Then tbuf$ = Left$(tbuf$, InStr(tbuf$, Chr$(0)) - 1)
     
    ' And add it to the description
    Desc$ = Desc$ + tbuf$ + Chr$(9)

    ' Finally, add the class name
    tbuf$ = String$(256, 0) ' Initialize space again
    dummy = GetClassName(hwnd, tbuf$, 255)
    'tbuf$ = agGetStringFromLPSTR(tbuf$)
    If InStr(tbuf$, Chr$(0)) Then tbuf$ = Left$(tbuf$, InStr(tbuf$, Chr$(0)) - 1)
     
    Desc$ = tbuf$

    ' And return the description
    GetWindowName$ = Desc$

    Exit Function

ErrorHandle:
    MsgErr
    Resume Next

End Function
'******************************************************************


After yo have just to change the attribute to your window to transform this window child of the window you want


Public Sub AddChild(strDescription As String, objParent As Object, Optional blnLike As Boolean = False)
'************************************************************************
'PURPOSE    This function loop in all top level window and search for   *
'           the windows description match with strDescription parameter *
'INPUT:     String to compare with window description                   *
'************************************************************************
'Note Chaine = TACTICIAN if you search for Tactician description
 
   Dim lngCurrHwnd As Long
   Dim lngParentHwnd As Long
   Dim lngChildHwnd As Long
   Dim lngDesktopHwnd As Long
   Dim lngTmpHwnd As Long
   
On Error GoTo ErrorHandle
         
     
    ' The desktop is the highest window
    lngDesktopHwnd = GetDesktopWindow()
     
    'Initialisation
    lngParentHwnd = objParent.hwnd
     
    ' It's first child is the 1st top level window
    lngCurrHwnd = GetWindow(lngDesktopHwnd, GW_CHILD)

    ' Now LOOP all top level windows
    Do
      'If description match with request string
      If blnLike Then
         If UCase(GetWindowName$(lngCurrHwnd)) Like UCase(strDescription) Then
         
            'Window search found
            lngChildHwnd = GetWindowhWnd$(lngCurrHwnd)
             
            'Make this window a child window
            lngTmpHwnd = GetWindowLong(lngChildHwnd, GWL_STYLE)
            lngTmpHwnd = SetWindowLong(lngChildHwnd, GWL_STYLE, lngTmpHwnd + WS_CHILD)
             
            'Set the parent of the window
            lngTmpHwnd = SetParent(lngChildHwnd, lngParentHwnd)
             
            'Don't notify parent if child close
            lngTmpHwnd = GetWindowLong(lngChildHwnd, GWL_EXSTYLE)
            lngTmpHwnd = SetWindowLong(lngChildHwnd, GWL_EXSTYLE, lngTmpHwnd + WS_EX_NOPARENTNOTIFY)
             
            'Hide child window
            lngTmpHwnd = ShowWindow(lngChildHwnd, SW_HIDE)
            lngTmpHwnd = ShowWindow(lngChildHwnd, SW_SHOW)
             
            Exit Do
           
         End If
      Else
         If UCase(GetWindowName$(lngCurrHwnd)) = UCase(strDescription) Then
         
            'Window search found
            lngChildHwnd = GetWindowhWnd$(lngCurrHwnd)
             
            'Make this window a child window
            lngTmpHwnd = GetWindowLong(lngChildHwnd, GWL_STYLE)
            lngTmpHwnd = SetWindowLong(lngChildHwnd, GWL_STYLE, lngTmpHwnd + WS_CHILD)
             
            'Set the parent of the window
            lngTmpHwnd = SetParent(lngChildHwnd, lngParentHwnd)
             
            'Don't notify parent if child close
            lngTmpHwnd = GetWindowLong(lngChildHwnd, GWL_EXSTYLE)
            lngTmpHwnd = SetWindowLong(lngChildHwnd, GWL_EXSTYLE, lngTmpHwnd + WS_EX_NOPARENTNOTIFY)
             
            'Hide child window
            lngTmpHwnd = ShowWindow(lngChildHwnd, SW_HIDE)
             
            Exit Do
           
         End If
      End If
       
      'get the net window
      lngCurrHwnd = GetWindow(lngCurrHwnd, GW_HWNDNEXT)

    Loop While lngCurrHwnd <> 0
     
     
    Exit Sub

ErrorHandle:
    MsgErr
    Resume Next

End Sub

0
 

Author Comment

by:shaii
ID: 1523518
I still don't understand how to do this!
0
 

Author Comment

by:shaii
ID: 1523519
I have an answer from vb-helper
For an example program that may work, go to
    http://www.vb-helper.com/HowToAdv.htmand click the "Start a program inside
another" link.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

730 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