Click here to Skip to main content
15,887,975 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have started a process:

dim myproc as new process
' Some setup code for calling a third-party application
myproc.start


Later in the program, I need to make the main window of myproc the topmost, active window.

Any suggestions? I cannot modify the third-party application.

Per one suggestion, I tried:
' Activate and bring to the top an existing window.
Dim winPtr As IntPtr

winPtr = myproc.MainWindowHandle
WinAPI.SendMessage(winPtr, WinAPI.WndMsg.WM_SETFOCUS, CType(1, IntPtr), CType(0, IntPtr))


but this did not work.
Posted
Updated 16-Mar-10 10:18am
v9

You need to get the handle to the other applications window, and send that window a WM_FOCUS message.

If you launched the app yourself, you could get the window handle by way of manipulating the Process object you used to launch the application.
 
Share this answer
 
v3
The process variable must be defined as follows:

Private Shared WithEvents myProcess As Process = Nothing


Then you can catch the Exited event. This works beautifully.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900