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 (Problems with U2lcom.dll)Next Topic (Share variables between application and ActiveX-control in VB6) New Topic New Poll Post Reply
AndreaVB Forum : ActiveX : Shell Control in a form
Poster Message
jorge1145
Level: Big Cheese


Registered: 28-07-2004
Posts: 25

icon Shell Control in a form

How can i have a shell controlled in a form? Like having the MS DOS screen/window within a form?

01-09-2004 at 10:19 PM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: Shell Control in a form

If you want to have MS-DOS prompt on your form, then it is a huge project to develop. You may search for the DOS emulators written in VB, there are some of them available, just see if they satisfy your needs.

____________________________
If you find the answer helpful, please mark this topic as solved.

01-09-2004 at 10:55 PM
View Profile Send Email to User Show All Posts | Quote Reply
jorge1145
Level: Big Cheese


Registered: 28-07-2004
Posts: 25
icon Re: Shell Control in a form

Thanks for your prompt response! Well, not MSDOS, but a program i use a work that is kinda old school like MSDOS.  It is used to look at customer accounts.  How hard is it to have any type of program embedded in a form?

01-09-2004 at 11:02 PM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: Shell Control in a form

Embedding some app in your application is not hard, but then you will hardly control the uotput from it. Here is the code from www.allapi.com for embedding some app in your app

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 LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () 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()
    'KPD-Team 1999
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim Pid As Long
    'Lock the window update
    LockWindowUpdate GetDesktopWindow
    'Execute notepad.Exe
    Pid = Shell("c:\windows\notepad.exe", vbNormalFocus)
    If Pid = 0 Then MsgBox "Error starting the app"
    '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
    'Unlock windowupdate
    LockWindowUpdate False
End Sub
Private Sub Form_Unload(Cancel As Integer)
    'Unload notepad
    DestroyWindow mWnd
    'End this program
    TerminateProcess GetCurrentProcess, 0
End Sub



____________________________
If you find the answer helpful, please mark this topic as solved.

02-09-2004 at 10:29 AM
View Profile Send Email to User Show All Posts | Quote Reply
jorge1145
Level: Big Cheese


Registered: 28-07-2004
Posts: 25
icon Re: Shell Control in a form

Sweet! Thanks!  Is there an explanation why an application like "TELNET" does not not stay "inside" the form like "NOTEPAD" does?  Is there a way to lock where the application is positioned on/in the form? I think i would be using this method for an application like TELNET

02-09-2004 at 09:27 PM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: Shell Control in a form

Never tried it with telnet, so I am not aware of the problems that can occur. You can set forms position, like with SetWindowPos API

[Edited by Goran on 02-09-2004 at 10:51 PM GMT]

____________________________
If you find the answer helpful, please mark this topic as solved.

02-09-2004 at 09:50 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : ActiveX : Shell Control in a form
Previous Topic (Problems with U2lcom.dll)Next Topic (Share variables between application and ActiveX-control in VB6) 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