I've been playing with CreateProcess and can't get the StartupInfo data 'recognised'. A work around is to use SetWindowPos after the process has been created
Form Code:
Code:
Option Explicit
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" _
(ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As Long, _
lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Boolean
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Sub Command_Click()
Dim lngReturn As Long
Dim strCL As String
Dim udtStart As STARTUPINFO
Dim udtPI As PROCESS_INFORMATION
udtStart.cb = Len(udtStart)
strCL = """C:\program files\microsoft Visual Studio\VB98\project1.exe"""
lngReturn = CreateProcess(vbNullString, strCL, ByVal 0&, ByVal 0&, ByVal 0&, ByVal 0&, ByVal 0&, vbNullString, udtStart, udtPI)
WaitForSingleObject udtPI.hProcess, 100&
lngPID = udtPI.dwProcessId
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
lngReturn = CloseHandle(udtPI.hProcess)
lngReturn = CloseHandle(udtPI.hThread)
End Sub
and in a Module:
Code:
Option Explicit
Private Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, _
lpdwProcessId As Long) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Const SWP_NOZORDER As Long = 4
Public lngPID As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim lngRet As Long
Dim lngPID1 As Long
lngRet = GetWindowThreadProcessId(hwnd, lngPID1)
If lngPID1 = lngPID Then
lngRet = SetWindowPos(hwnd, 0&, 400&, 400&, 10&, 10&, SWP_NOZORDER)
End If
EnumWindowsProc = True
End Function