Hi Ansi,
erst dachte ich: geht nicht.
Aber dann - dann habe ich mich besinnt, dass wir in unserer VBEx32.DLL ja eine "Window-Kidnapping"-Funktion haben.
Alles, was Du brauchst ist unsere VBEX32.DLL und nachfolgenden Code.
Für das Beispiel einfach ein neues Projekt erstellen, eine Form mit einem CommandButton - et voilá:
Option Explicit
<font color=green>' zunächst die benötigten API-Deklarationen</font>
Private Declare Function GetWindowThreadProcessId Lib _
"user32" (ByVal hWnd As Long, lpdwProcessId As Long) _
As Long
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetParent Lib "user32" _
(ByVal hWnd As Long) As Long
Private Const GW_HWNDNEXT = 2
<font color=green>' benötigte VBEX-Funktion</font>
Private Declare Sub VBEX_MakeChild Lib "vbex32.dll" _
Alias "VBMAKECHILD" ( _
ByVal zhWnd As Long, _
ByVal ownerhWnd As Long, _
ByVal x As Long, ByVal y As Long) <font color=green>' Anwendung starten und Fenster-Handle zurückgeben</font>
Private Function Shell2hWnd(ByVal sFilename As String, _
Optional ByVal Mode As VbAppWinStyle)
Dim lngAppTaskID As Long
Dim lngProcTaskID As Long
Dim lnghWnd As Long
<font color=green>' TaskID der zu startenden Anwendung</font>
lngAppTaskID = Shell(sFilename, Mode)
<font color=green>' Anwendung konnte nicht gestartet werden</font>
If lngAppTaskID = 0 Then Exit Function
<font color=green>' Fenster durchlaufen und nach Process-ID suchen</font>
lnghWnd = FindWindow(vbNullString, vbNullString)
Do While lnghWnd <> 0
<font color=green>' Existiert kein Eltern-Fenster, dann ProcssID</font>
<font color=green>' ermitteln und mit TaskID vergleichen</font>
If GetParent(lnghWnd) = 0 Then
GetWindowThreadProcessId lnghWnd, lngProcTaskID
<font color=green>' Handelt es sich um die gesuchte TaskID?</font>
If lngProcTaskID = lngAppTaskID Then
<font color=green>' Fenster-Handle zurückgeben und Schleife
' verlassen!</font>
Shell2hWnd = lnghWnd
Exit Do
End If
End If
<font color=green>' Nächstes Fenster</font>
lnghWnd = GetWindow(lnghWnd, GW_HWNDNEXT)
Loop
End Function Private Sub Command1_Click()
Dim zhWnd As Long
<font color=green>' DOS-Box starten und kidnappen</font>
zhWnd = Shell2hWnd(Environ$("COMSPEC"), vbNormalFocus)
VBEX_MakeChild zhWnd, Me.hWnd, 0, 0
End Sub Cu
Dieter |