Imports System.Diagnostics
Public Class frmtest4
'benötigte APIs
Private Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As _
IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hWnd As _
Integer, _
ByVal flag As Integer) As IntPtr
Public Declare Function MoveWindow Lib "user32" (ByVal hWnd As IntPtr, _
ByVal x As Integer, ByVal y As Integer, _
ByVal nWidth As Integer, ByVal nHeight As Integer, _
ByVal bRepaint As Boolean) As Boolean
' Activate an application window.
Declare Auto Function SetForegroundWindow Lib "USER32.DLL" _
(ByVal hWnd As IntPtr) As Boolean
'ShowWindow-Konstanten
Private Const SW_NORMAL As Integer = 1
'ProzessID des eingebetteten fensters merken
Private intProgrammID As Integer
Dim tc As New TabControl With {.Parent = Me, .Width = 600, .Height = 650}
Private Sub frmtest4_Load(sender As System.Object, _
e As System.EventArgs) Handles MyBase.Load
Me.Width = 650 : Me.Height = 680
tc.TabPages.Add("Test")
Starten()
End Sub
Private Sub Starten()
Dim handle As IntPtr
StartProgramm("cmd.exe", tc.TabPages(0), intProgrammID, Handle)
If Not SetForegroundWindow(handle) Then Stop
SendKeys.Send("Color f0")
SendKeys.Send("{Enter}")
Dim direc As String = _
My.Computer.FileSystem.SpecialDirectories.MyPictures
SendKeys.Send("Cd " & direc)
SendKeys.Send("{Enter}")
End Sub
Public Sub StartProgramm(ByVal Programm As String, ByVal Seite As TabPage, _
ByRef ProgrammID As Integer, ByRef procHandle As IntPtr)
Dim psi As New ProcessStartInfo
With psi
.FileName = Programm
End With
Dim p As Process = Process.Start(psi)
Threading.Thread.Sleep(1000)
procHandle = p.MainWindowHandle
ProgrammID = p.Id
'DOS-Box in Tabpage einbetten
SetParent(procHandle, Seite.Handle)
'WindowState der DOS-Box auf "normal" setzen
ShowWindow(CInt(procHandle), SW_NORMAL)
'DOS-Box auf TabPage zentrieren
Dim mw As Boolean = _
MoveWindow(procHandle, 0, 0, Seite.Width, Seite.Height, True)
End Sub
End Class
Beitrag wurde zuletzt am 25.04.14 um 18:02:48 editiert. |