Results 1 to 4 of 4

Thread: How to run an app within an app?

  1. #1

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Question

    Can anyone tell me the code on how to run a program from a program and how to retrieve PC's info?And how to check if a file is exist or not?

    Many regards

    I am using VB5 Enterprise

  2. #2
    Guest
    Q1:

    Code:
    Shell "C:\file.exe", vbNormalFocus
    
    'or
    
    Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    
    Public Const SW_SHOWNORMAL = 1
    
    ShellExecute Me.hwnd, vbNullString, "C:\file.txt", vbNullString, "c:\", SW_SHOWNORMAL
    Q3:

    Code:
    ffile = Dir("C:\file.exe")
    If Not ffile = "" Then
    Msgbox "file exists"
    else
    Msgbox "file doesn't exist"
    End If

  3. #3
    Addicted Member
    Join Date
    May 2000
    Posts
    240

    This might work

    I found this code here in vb world.net for Starting a program in a program.

    Option Explicit

    Private Const GW_HWNDNEXT = 2

    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

    Private old_parent As Long
    Private child_hwnd As Long

    ' Return the window handle for an instance handle.
    Private Function InstanceToWnd(ByVal target_pid As Long) As Long
    Dim test_hwnd As Long
    Dim test_pid As Long
    Dim test_thread_id As Long

    ' Get the first window handle.
    test_hwnd = FindWindow(ByVal 0&, ByVal 0&)

    ' Loop until we find the target or we run out
    ' of windows.
    Do While test_hwnd <> 0
    ' See if this window has a parent. If not,
    ' it is a top-level window.
    If GetParent(test_hwnd) = 0 Then
    ' This is a top-level window. See if
    ' it has the target instance handle.
    test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)

    If test_pid = target_pid Then
    ' This is the target.
    InstanceToWnd = test_hwnd
    Exit Do
    End If
    End If

    ' Examine the next window.
    test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
    Loop
    End Function

    Private Sub cmdFree_Click()
    SetParent child_hwnd, old_parent

    cmdRun.Enabled = True
    cmdFree.Enabled = False
    End Sub

    Private Sub cmdRun_Click()
    Dim pid As Long
    Dim buf As String
    Dim buf_len As Long

    ' Start the program.
    pid = Shell(txtProgram.Text, vbNormalFocus)
    If pid = 0 Then
    MsgBox "Error starting program"
    Exit Sub
    End If

    ' Get the window handle.
    child_hwnd = InstanceToWnd(pid)

    ' Reparent the program so it lies inside
    ' the PictureBox.
    old_parent = SetParent(child_hwnd, picChild.hwnd)

    cmdRun.Enabled = False
    cmdFree.Enabled = True
    End Sub

    Private Sub Form_Resize()
    Dim hgt As Single

    hgt = ScaleHeight - picChild.Top
    If hgt < 120 Then hgt = 120

    picChild.Move 0, picChild.Top, ScaleWidth, hgt
    End Sub

    Go to http://www.allapi.net for api's that get pc's info....
    since i dont know what info you want secific i cant help.



  4. #4
    Guest
    You could put the window inside your program as well. By using the SetParent function and the FindWindow function.

    Code:
    Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal
    hWndNewParent As Long) As Long
    
    'This will put a form inside a form.
    SetParent Form1.hwnd, Me.hwnd
    You could also use the FindWindow function like this:

    Code:
    Declare Function findwindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal
    hWndNewParent As Long) As Long
    
    'Open up the calculator and try this:
    'This will put the calculator in your form
    
    Dim x
    x = FindWindow(vbNullString, "Calculator")
    If x = 0 Then
    MsgBox "Window was not found!", 16
    Else
    SetParent x, Me.hWnd
    End If

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