I'm using VB Shell() to initiate the application, which returns a process
ID. I have unsuccessfully tried just about every combination of API calls
to obtain the hWnd using the process ID, so that I can use the
SendMessage() function to cause the application to take focus. There is no
way to know the window caption, so I can't use FindWindow() to get the
hWnd.
I've also tried OpenProcess() to start the applications, but it is of no
help. It would be nice if the STARTUPINFO structure returned the
information that the application starts up with. That way, I could get the
caption, then use FindWindow() and I'm done, but that would make too much
sense...
Any help or suggestions would be greatly appreciated.
Joe Foster
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function BringWindowToTop Lib "user32" _
(ByVal hwnd As Long) As Long
Private lProcessID As Long
Private Sub Command1_Click()
lProcessID = Shell("Notepad.exe", vbNormalFocus)
End Sub
Private Sub Command2_Click()
Dim lhRet As Long
lhRet = hWndFromProcID(lProcessID)
Call BringWindowToTop(lhRet)
End Sub
Public Function hWndFromProcID(ProcID As Long) As Long
Dim lhTmp As Long
Dim lRetVal As Long
Dim lCurrentProcID As Long
'----------------------------
On Error GoTo errhWndFromProcID
lhTmp = GetDesktopWindow()
lhTmp = GetWindow(lhTmp, GW_CHILD)
Do While lhTmp <> 0
lRetVal = GetWindowThreadProcessId(lhTmp, lCurrentProcID)
If lCurrentProcID = ProcID Then
hWndFromProcID = lhTmp
Exit Do
End If
lhTmp = GetWindow(lhTmp, GW_HWNDNEXT)
Loop
Exit Function
errhWndFromProcID:
hWndFromProcID = 0
End Function
__________snip_______________________________
--
***********************************************************
Joe LeVasseur lvas...@tiac.net
Microsoft Developer MVP- Visual Basic
Check out Yankee Clipper Plus- August 98 PCComputing
Mag "Amazing Free Stuff: Programs and Power Toys"
http://www.tiac.net/users/lvasseur/ycphome.html
"He preaches well that lives well, quoth Sancho; that's
all the divinity I understand." Miguel de Cervantes
**********************************************************
PS- Please reply to the newsgroup- except in the
case of flames, insults, etc. (Don't bother.)
Joseph W. Foster <Foste...@home.com> wrote in message
01bdc204$07abcfc0$3e70...@ci672803-a.nash1.tn.home.com...