borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (vb6 HELP! Barcode scanner then msaccess)Next Topic (using DDE to display stock quote) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Shell
Poster Message
omrane
Level: Guest


icon Shell   Archived to Disk

Hi, I'm looking for help to attach any external program(applicetion .exe) to my VB application so it can be displayed in one VB form.I've tried   Shell function and OLE control but both of them can only run the application outside of my application (in independent window)?
Thank you for any suggestions

07-06-2002 at 11:31 AM
| Quote Reply
thelos
Level: Guest

icon Re: Shell   Archived to Disk

I think i know what to do but i would need to know exactly what external applications your hoping to include

09-06-2002 at 01:48 AM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: Shell   Archived to Disk

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long

Const GW_HWNDNEXT = 2
Dim mWnd As Long
Function InstanceToWnd(ByVal target_pid As Long) As Long
    Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
    'Find the first window
    test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
    Do While test_hwnd <> 0
        'Check if the window isn't a child
        If GetParent(test_hwnd) = 0 Then
            'Get the window's thread
            test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
            If test_pid = target_pid Then
                InstanceToWnd = test_hwnd
                Exit Do
            End If
        End If
        'retrieve the next window
        test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
    Loop
End Function
Private Sub Form_Load()
    Dim Pid As Long
    
    Pid = Shell("notepad.exe", vbNormalFocus)

    'retrieve the handle of the window
    mWnd = InstanceToWnd(Pid)
    'Set the notepad's parent
    SetParent mWnd, Me.hwnd
    'Put the focus on notepad
    Putfocus mWnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
    'Unload notepad
    DestroyWindow mWnd
End Sub



09-06-2002 at 03:15 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
omrane
Level: Guest

icon Re: Re: Shell   Archived to Disk

the aplication is a Psched.exe it's a pspice (electrical simulation package)application.

10-06-2002 at 04:52 AM
| Quote Reply
AndreaVB Forum : VB General : Shell
Previous Topic (vb6 HELP! Barcode scanner then msaccess)Next Topic (using DDE to display stock quote) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder