Option Explicit
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
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
Public Sub OpenTextFile(strFile As String)
'==========================================
Dim Ret As Long
Dim lngHWnd As Long
Dim strBuffer As String
'you may need to maximize your form and adjust frame's size as well
'Me.WindowState = vbMaximized
'Frame1.Move 0, 0, ...
LockWindowUpdate GetDesktopWindow
strBuffer = Space(260)
Ret = FindExecutable(strFile, vbNullString, strBuffer)
If Ret > 32 Then
lngHWnd = Shell(Left$(strBuffer, InStr(strBuffer, Chr$(0)) - 1) & " " & strFile, vbNormalFocus)
mWnd = InstanceToWnd(lngHWnd)
SetParent mWnd, Frame1.hwnd
End If
LockWindowUpdate False
End Sub
Private Sub Command1_Click()
OpenTextFile "C:\Temp\test1.txt"
End Sub