This is for finding a programs hwnd immediately after shelling, for use if you need to hide it or something
VB Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As Long
Private Declare Function GetParent Lib "user32" ( _
ByVal hwnd 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.dll" ( _
ByVal hwnd As Long, _
ByVal wCmd As Long _
) As Long
Private Const GW_HWNDNEXT As Long = 2
Private Sub Form_Load()
MsgBox ShellAndFind("C:\Documents and Settings\Jason\Desktop\project1.exe")
End Sub
Private Function ShellAndFind(Path As String) As Long
Dim testHWND As Long
Dim testPID As Long
Dim testID As Long
Path = Shell(Path)
testHWND = FindWindow(vbNullString, vbNullString)
Do While testHWND <> 0
If GetParent(testHWND) = 0 Then
testID = GetWindowThreadProcessId(testHWND, testPID)
If testPID = Path Then
ShellAndFind = testHWND
Exit Do
End If
End If
testHWND = GetWindow(testHWND, GW_HWNDNEXT)
Loop
End Function
'NOTE:I modified code from another site to suit my needs, it isnt exact, or close to it for that matter.
I got some code from another site..tell me if you like it